├── .dockerignore ├── .gitignore ├── Dockerfile ├── README.md ├── docker-compose.yml ├── docker-entrypoint.sh └── maria-wait.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | * 2 | !docker-entrypoint.sh 3 | !maria-wait.sh 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.4-apache 2 | # MAINTAINER Austin St. Aubin 3 | 4 | # Build Environment Variables 5 | ENV VERSION 3.5.2 6 | ENV URL https://github.com/phpservermon/phpservermon/archive/v${VERSION}.tar.gz 7 | 8 | # Install Base 9 | RUN apt-get update 10 | 11 | # Install & Setup Dependencies 12 | RUN set -ex; \ 13 | apt-get install -y curl iputils-ping; \ 14 | apt-get install -y zip unzip git; \ 15 | #docker-php-ext-configure gd --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-webp-dir=/usr --with-png-dir=/usr --with-xpm-dir=/usr; \ 16 | docker-php-ext-install pdo pdo_mysql mysqli sockets; \ 17 | apt-get clean -y; \ 18 | rm -rf /var/lib/apt/lists/*; \ 19 | curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 20 | 21 | # Expose Ports 22 | EXPOSE 80 23 | 24 | # Apache Document Root 25 | ENV APACHE_DOCUMENT_ROOT /var/www/html 26 | RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf 27 | RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf 28 | 29 | # User Environment Variables 30 | ENV PSM_REFRESH_RATE_SECONDS 90 31 | ENV PSM_AUTO_CONFIGURE true 32 | ENV PSM_PHP_DEBUG false 33 | ENV MYSQL_HOST database 34 | ENV MYSQL_USER phpservermonitor 35 | ENV MYSQL_PASSWORD YOUR_PASSWORD 36 | ENV MYSQL_DATABASE phpservermonitor 37 | ENV MYSQL_DATABASE_PREFIX psm_ 38 | 39 | # Time Zone 40 | ENV PHP_TIME_ZONE 'Europe/Amsterdam' 41 | RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" 42 | RUN sed -i 's/;date.timezone =/date.timezone = "${PHP_TIME_ZONE}"/g' "$PHP_INI_DIR/php.ini" 43 | # RUN php -i | grep -i error 44 | 45 | # Webserver Run User 46 | ENV APACHE_RUN_USER www-data 47 | 48 | # Persistent Sessions 49 | RUN mkdir '/sessions'; \ 50 | chown ${APACHE_RUN_USER}:www-data '/sessions'; \ 51 | sed -i 's/;session.save_path\s*=.*/session.save_path = "\/sessions"/g' "$PHP_INI_DIR/php.ini"; \ 52 | cat "$PHP_INI_DIR/php.ini" | grep 'session.save_path' 53 | VOLUME /sessions 54 | 55 | # Extract Repo HTML Files 56 | RUN set -ex; \ 57 | cd /tmp; \ 58 | rm -rf ${APACHE_DOCUMENT_ROOT}/*; \ 59 | curl --output phpservermonitor.tar.gz --location $URL; \ 60 | tar -xvf phpservermonitor.tar.gz --strip-components=1 -C ${APACHE_DOCUMENT_ROOT}/; \ 61 | cd ${APACHE_DOCUMENT_ROOT} 62 | # chown -R ${APACHE_RUN_USER}:www-data /var/www 63 | # find /var/www -type d -exec chmod 750 {} \; ; \ 64 | # find /var/www -type f -exec chmod 640 {} \; 65 | 66 | # Configuration 67 | # VOLUME ${APACHE_DOCUMENT_ROOT}/config.php 68 | RUN touch ${APACHE_DOCUMENT_ROOT}/config.php; \ 69 | chmod 0777 ${APACHE_DOCUMENT_ROOT}/config.php 70 | 71 | # Composer install dependencies 72 | RUN composer install --no-dev -o 73 | 74 | # Add Entrypoint & Start Commands 75 | COPY docker-entrypoint.sh /usr/local/bin/ 76 | COPY maria-wait.sh /usr/local/bin/ 77 | 78 | RUN chmod u+rwx /usr/local/bin/docker-entrypoint.sh 79 | ENTRYPOINT ["docker-entrypoint.sh"] 80 | CMD ["apache2-foreground"] 81 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # PHPServerMonitor in Docker (Last version 3.5.2) 3 | 4 | ### Last update : 2020/09/09 . Created repository with version 3.5.2 5 | #### Please open issues on [github](https://github.com/Quentinvarquet/docker-phpservermonitor/issues) 6 | 7 | ### PHPServerMonitor 8 | 9 | [PHPServerMonitor](http://www.phpservermonitor.org/) is a script that checks whether your websites and servers are up and running. It comes with a web based user interface where you can manage your services and websites, and you can manage users for each server with a mobile number and email address. 10 | 11 | ### Docker 12 | 13 | [Docker](https://www.docker.com/) allows you to package an application with all of its dependencies into a standardized unit for software development. 14 | 15 | More information : 16 | 17 | * [What is docker](https://www.docker.com/what-docker) 18 | * [How to Create a Docker Business Case](https://www.brianchristner.io/how-to-create-a-docker-business-case/) 19 | 20 | ### Information & Build 21 | 22 | This is the official repository for PHPServerMonitor 23 | It will be updated every time there is a new version of PHPServerMonitor available, or you can build yourself with. 24 | 25 | ``` 26 | ## Build and Deploy PHPServerMonitor with Docker 27 | 28 | # Working Dir 29 | mkdir -p "/tmp/php-server-monitor" 30 | cd "/tmp/php-server-monitor" 31 | 32 | # Clone Git Repo 33 | git clone https://github.com/phpservermon/docker-phpservermonitor.git phpservermonitor 34 | cd phpservermonitor/ 35 | 36 | # Build Docker Image 37 | docker build --no-cache \ 38 | --tag "phpservermonitor:3.5.2" \ 39 | --tag "phpservermonitor:latest" \ 40 | --file Dockerfile . 41 | ``` 42 | 43 | 44 | ## Option 1 (recommended): Deploy Container Stack w/ Docker-Compose & Random Passwords 45 | 46 | ``` 47 | # Generate Random Passwords 48 | export "MYSQL_ROOT_PASSWORD=$(cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)" "MYSQL_PASSWORD=$(cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)" 49 | 50 | # Deploy with Docker-Compose 51 | docker-compose up -d 52 | ``` 53 | 54 | ## Option 2: Deploy Seperated Container w/ Docker-Compose & Random Passwords 55 | 56 | ``` 57 | # Start Containers w/ Random Passwords 58 | export "MYSQL_ROOT_PASSWORD=$(cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)" "MYSQL_PASSWORD=$(cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)" 59 | 60 | # Create a network 61 | docker network create -d psm 62 | 63 | # phpservermonitor 64 | docker run -d --name phpservermonitor \ 65 | --network psm \ 66 | --restart always \ 67 | -v /sessions \ 68 | --dns=192.168.3.8 \ 69 | -p 8080:80 \ 70 | -e TIME_ZONE='Europe/Amsterdam' \ 71 | -e PSM_REFRESH_RATE_SECONDS=15 \ 72 | -e PSM_AUTO_CONFIGURE=true \ 73 | -e MYSQL_HOST=db \ 74 | -e MYSQL_USER=phpservermonitor \ 75 | -e MYSQL_PASSWORD=${MYSQL_PASSWORD} \ 76 | -e MYSQL_DATABASE=phpservermonitor \ 77 | -e MYSQL_DATABASE_PREFIX=psm_ \ 78 | phpservermonitor:latest 79 | 80 | # phpservermonitor_mariadb 81 | docker run -d --name phpservermonitor_mariadb \ 82 | --network psm --network-alias db \ 83 | --restart always \ 84 | -e MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} \ 85 | -e MYSQL_USER=phpservermonitor \ 86 | -e MYSQL_PASSWORD=${MYSQL_PASSWORD} \ 87 | -e MYSQL_DATABASE=phpservermonitor \ 88 | mariadb 89 | ``` 90 | 91 | #### Database Configuration 92 | 93 | Configuration should be automatic if the envirmental varable is set `PSM_AUTO_CONFIGURE=true`. Otherwise the configuration window should be prepopulated to the following. 94 | 95 | * **Database Host:** db 96 | * **Database Name:** phpservermonitor 97 | * **Database User:** phpservermonitor 98 | * **Data Password:** YOUR_PASSWORD 99 | * **Table Previx:** psm_ 100 | 101 | ----- 102 | 103 | ## PING check 104 | On Windows machines the PING will be checked using socket. 105 | For all other machines this will be checked using exec() and the terminal PING command. 106 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | services: 3 | 4 | phpservermonitor: 5 | build: . 6 | image: phpservermonitor:latest 7 | container_name: phpservermonitor 8 | restart: always 9 | environment: 10 | - TIME_ZONE='Europe/Amsterdam' 11 | - PSM_REFRESH_RATE_SECONDS=15 12 | - PSM_AUTO_CONFIGURE=true 13 | - MYSQL_HOST=db 14 | - MYSQL_USER=phpservermonitor 15 | - MYSQL_PASSWORD=${MYSQL_PASSWORD} 16 | - MYSQL_DATABASE=phpservermonitor 17 | - MYSQL_DATABASE_PREFIX=psm_ 18 | ports: 19 | - 8080:80 20 | volumes: 21 | - /sessions 22 | depends_on: 23 | - db 24 | 25 | db: 26 | image: mariadb 27 | container_name: phpservermonitor_mariadb 28 | restart: always 29 | environment: 30 | - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} 31 | - MYSQL_USER=phpservermonitor 32 | - MYSQL_PASSWORD=${MYSQL_PASSWORD} 33 | - MYSQL_DATABASE=phpservermonitor 34 | volumes: 35 | - ./mariadb:/var/lib/mysql/phpservermonitor 36 | 37 | # phpmyadmin: 38 | # image: phpmyadmin/phpmyadmin 39 | # container_name: phpservermonitor_phpmyadmin 40 | # restart: always 41 | # environment: 42 | # - PMA_HOST=db 43 | # ports: 44 | # - 8081:80 45 | # volumes: 46 | # - /sessions 47 | -------------------------------------------------------------------------------- /docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | # Setup Database Connection 5 | if [ ${PSM_AUTO_CONFIGURE} = true ]; then 6 | 7 | # Setup / Create 8 | echo "Auto Configure / Create config.php" 9 | touch ${APACHE_DOCUMENT_ROOT}/config.php; \ 10 | chmod 0777 ${APACHE_DOCUMENT_ROOT}/config.php 11 | 12 | cat > ${APACHE_DOCUMENT_ROOT}/config.php << EOF 13 | 21 | EOF 22 | 23 | else 24 | # Setup Database Connection Defaults 25 | echo "Setting Database Connection Defaults" 26 | sed -ri -e "/db_host/s/'[^']*'/'${MYSQL_HOST}'/2" "${APACHE_DOCUMENT_ROOT}/src/psm/Module/Install/Controller/InstallController.php" 27 | sed -ri -e "/db_port/s/'[^']*'/''/2" "${APACHE_DOCUMENT_ROOT}/src/psm/Module/Install/Controller/InstallController.php" 28 | sed -ri -e "/db_name/s/'[^']*'/'${MYSQL_DATABASE}'/2" "${APACHE_DOCUMENT_ROOT}/src/psm/Module/Install/Controller/InstallController.php" 29 | sed -ri -e "/db_user/s/'[^']*'/'${MYSQL_USER}'/2" "${APACHE_DOCUMENT_ROOT}/src/psm/Module/Install/Controller/InstallController.php" 30 | sed -ri -e "/db_pass/s/'[^']*'/'${MYSQL_PASSWORD}'/2" "${APACHE_DOCUMENT_ROOT}/src/psm/Module/Install/Controller/InstallController.php" 31 | sed -ri -e "/db_prefix/s/'[^']*'/'${MYSQL_DATABASE_PREFIX}'/2" "${APACHE_DOCUMENT_ROOT}/src/psm/Module/Install/Controller/InstallController.php" 32 | 33 | fi 34 | 35 | # Setup Database Connection 36 | if [ ${PSM_PHP_DEBUG} = true ]; then 37 | 38 | # PHP Debugging 39 | cat > ${APACHE_DOCUMENT_ROOT}/phpinfo.php << EOF 40 | 41 | 48 | EOF 49 | 50 | fi 51 | 52 | # wait until mariadb is ready 53 | echo "Waiting until database is ready..." 54 | /usr/local/bin/maria-wait.sh 55 | 56 | # first arg is `-f` or `--some-option` 57 | if [ "${1#-}" != "$1" ]; then 58 | set -- apache2-foreground "$@" 59 | fi 60 | 61 | # Start CMD Commands 62 | exec "$@" & (while true; do sleep "${PSM_REFRESH_RATE_SECONDS}"; /usr/local/bin/php ${APACHE_DOCUMENT_ROOT}/cron/status.cron.php; done) 63 | #exec "$@" & (while true; do sleep ${PSM_REFRESH_RATE_SECONDS}; su -l www-data -s /usr/local/bin/php ${APACHE_DOCUMENT_ROOT}/cron/status.cron.php; done) 64 | -------------------------------------------------------------------------------- /maria-wait.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ueo pipefail 4 | 5 | echo -n "Waiting until MariaDB has started" 6 | until (timeout 1 bash -c "< /dev/tcp/db/3306") &> /dev/null; do 7 | echo -n . 8 | sleep 1 9 | done 10 | echo 11 | --------------------------------------------------------------------------------