diff --git a/Dockerfile b/Dockerfile index 2b7cfef..9007f48 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,184 @@ -FROM ubuntu:16.04 -MAINTAINER "https://github.com/shincoder" +FROM ubuntu:18.04 +# Maintainer +LABEL maintainer="Jaouad E. " + +# Environment ENV DEBIAN_FRONTEND noninteractive +ENV PHP_VERSION 7.2 -# Install packages -ADD provision.sh /provision.sh -ADD serve.sh /serve.sh +# Update package list and upgrade available packages +RUN apt update && apt upgrade -y -ADD supervisor.conf /etc/supervisor/conf.d/supervisor.conf +# Ensure common dependencies are installed +RUN apt install -y \ + software-properties-common \ + ca-certificates \ + curl + +# Add PPAs and repositories +RUN apt-add-repository ppa:nginx/stable -y +RUN apt-add-repository ppa:ondrej/php -y +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ + echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list +RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - + +# Update package lists & install some basic packages +RUN apt update && apt install --fix-missing -y \ + apt-utils \ + bash-completion \ + beanstalkd \ + build-essential \ + cifs-utils \ + curl \ + git \ + libmcrypt4 \ + libpcre3-dev \ + libpng-dev \ + libsqlite3-dev \ + mcrypt \ + memcached \ + nginx \ + nodejs \ + openssh-server \ + pwgen \ + redis-server \ + software-properties-common \ + sqlite3 \ + supervisor \ + vim \ + yarn + +# Configure locale and timezone +RUN echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale +RUN ln -sf /usr/share/zoneinfo/UTC /etc/localtime + +# PHP and PHP dependencies installation +RUN apt install \ + --allow-downgrades \ + --allow-remove-essential \ + --allow-change-held-packages -y \ + php-pear \ + php${PHP_VERSION}-apcu \ + php${PHP_VERSION}-bcmath \ + php${PHP_VERSION}-cli \ + php${PHP_VERSION}-curl \ + php${PHP_VERSION}-dev \ + php${PHP_VERSION}-fpm \ + php${PHP_VERSION}-gd \ + php${PHP_VERSION}-gmp \ + php${PHP_VERSION}-imap \ + php${PHP_VERSION}-intl \ + php${PHP_VERSION}-json \ + php${PHP_VERSION}-ldap \ + php${PHP_VERSION}-mailparse \ + php${PHP_VERSION}-mbstring \ + php${PHP_VERSION}-mcrypt \ + php${PHP_VERSION}-memcached \ + php${PHP_VERSION}-mysql \ + php${PHP_VERSION}-pgsql \ + php${PHP_VERSION}-readline \ + php${PHP_VERSION}-redis \ + php${PHP_VERSION}-soap \ + php${PHP_VERSION}-sqlite3 \ + php${PHP_VERSION}-xdebug \ + php${PHP_VERSION}-xml \ + php${PHP_VERSION}-zip + +# Update package alternatives +RUN update-alternatives --set php /usr/bin/php${PHP_VERSION} && \ + update-alternatives --set php-config /usr/bin/php-config${PHP_VERSION} && \ + update-alternatives --set phpize /usr/bin/phpize${PHP_VERSION} + +# Install Composer package manager +RUN curl -sS https://getcomposer.org/installer | php && \ + mv composer.phar /usr/local/bin/composer + +# PHP CLI configuration +RUN sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/${PHP_VERSION}/cli/php.ini && \ + sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/${PHP_VERSION}/cli/php.ini && \ + sed -i "s/display_errors = .*/display_errors = On/" /etc/php/${PHP_VERSION}/cli/php.ini && \ + sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/${PHP_VERSION}/cli/php.ini + +# PHP FPM configuration +RUN sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/${PHP_VERSION}/fpm/php.ini && \ + sed -i "s/display_errors = .*/display_errors = On/" /etc/php/${PHP_VERSION}/fpm/php.ini && \ + sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/${PHP_VERSION}/fpm/php.ini && \ + sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/${PHP_VERSION}/fpm/php.ini && \ + sed -i "s/upload_max_filesize = .*/upload_max_filesize = 100M/" /etc/php/${PHP_VERSION}/fpm/php.ini && \ + sed -i "s/post_max_size = .*/post_max_size = 100M/" /etc/php/${PHP_VERSION}/fpm/php.ini && \ + sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/${PHP_VERSION}/fpm/php.ini + +RUN echo "xdebug.remote_enable = 1" >> /etc/php/${PHP_VERSION}/mods-available/xdebug.ini && \ + echo "xdebug.remote_connect_back = 1" >> /etc/php/${PHP_VERSION}/mods-available/xdebug.ini && \ + echo "xdebug.remote_port = 9000" >> /etc/php/${PHP_VERSION}/mods-available/xdebug.ini && \ + echo "xdebug.max_nesting_level = 512" >> /etc/php/${PHP_VERSION}/mods-available/xdebug.ini && \ + echo "opcache.revalidate_freq = 0" >> /etc/php/${PHP_VERSION}/mods-available/opcache.ini + +# Remove Nginx default configuration file +RUN rm /etc/nginx/sites-enabled/default && \ + rm /etc/nginx/sites-available/default + +# Set the Nginx and PHP-FPM user +RUN sed -i "s/user www-data;/user homestead;/" /etc/nginx/nginx.conf && \ + sed -i "s/# server_names_hash_bucket_size.*/server_names_hash_bucket_size 64;/" /etc/nginx/nginx.conf && \ + sed -i "s/user = www-data/user = homestead/" /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf && \ + sed -i "s/group = www-data/group = homestead/" /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf && \ + sed -i "s/;listen\.owner.*/listen.owner = homestead/" /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf && \ + sed -i "s/;listen\.group.*/listen.group = homestead/" /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf && \ + sed -i "s/;listen\.mode.*/listen.mode = 0666/" /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf +# Add OpenSSL certificate authority configuration to PHP FPM +RUN printf "[openssl]\n" | tee -a /etc/php/${PHP_VERSION}/fpm/php.ini && \ + printf "openssl.cainfo = /etc/ssl/certs/ca-certificates.crt\n" | tee -a /etc/php/${PHP_VERSION}/fpm/php.ini + +# Add cURL certificate authority configuration to PHP FPM +RUN printf "[curl]\n" | tee -a /etc/php/${PHP_VERSION}/fpm/php.ini && \ + printf "curl.cainfo = /etc/ssl/certs/ca-certificates.crt\n" | tee -a /etc/php/${PHP_VERSION}/fpm/php.ini + +# Disable x-debug on the CLI +RUN phpdismod -s cli xdebug + +# Install WordPress CLI +RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \ + chmod +x wp-cli.phar && \ + mv wp-cli.phar /usr/local/bin/wp + +# Configure SSH service +RUN mkdir -p /var/run/sshd && \ + sed -i "s/UsePrivilegeSeparation.*/UsePrivilegeSeparation no/g" /etc/ssh/sshd_config && \ + sed -i "s/UsePAM.*/UsePAM no/g" /etc/ssh/sshd_config && \ + sed -i "s/PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config + +# Create homestead user +RUN adduser homestead && \ + usermod -p $(echo secret | openssl passwd -1 -stdin) homestead + +# Add homestead to the sudo and www-data groups +RUN usermod -aG sudo homestead && \ + usermod -aG www-data homestead + +# Instal some commonly used Node packages +RUN npm install -g grunt-cli && \ + npm install -g gulp && \ + npm install -g bower + +# Configure beanstalkd and redis +RUN sed -i "s/#START=yes/START=yes/" /etc/default/beanstalkd && \ + sed -i "s/daemonize yes/daemonize no/" /etc/redis/redis.conf + +# Copy nginx virtualhost configuration +COPY example.nginx.conf /etc/nginx/sites-available/default +RUN ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/ + +# Add serve.sh script +ADD serve.sh /serve.sh RUN chmod +x /*.sh -RUN ./provision.sh +# Add supervisor configuration +ADD supervisor.conf /etc/supervisor/conf.d/supervisor.conf +# Expose HTTP, SSH adn debugging ports EXPOSE 80 22 35729 9876 + CMD ["/usr/bin/supervisord"] diff --git a/docker-compose.dist.yml b/docker-compose.dist.yml index 6d53762..a64d74f 100644 --- a/docker-compose.dist.yml +++ b/docker-compose.dist.yml @@ -1,24 +1,46 @@ -web: - image: shincoder/homestead:php7.1 - restart: unless-stopped +# Docker composer file reference version +version: '3.7' + +services: + # Web service + web: + image: shincoder/homestead:php7.2 + restart: always ports: - - "8000:80" # web - - "2222:22" # ssh + # Web + - "8000:80" + # SSH + - "2222:22" + # Live reload + - "35729:35729" + # Karma server + - "9876:9876" volumes: - - ~/.composer:/home/homestead/.composer # composer caching - - ~/.gitconfig:/home/homestead/.gitconfig # Git configuration ( access alias && config ) - - ~/.ssh:/home/homestead/.ssh # Ssh keys for easy deployment inside the container - - ~/apps:/apps # all apps - - ~/apps/volumes/nginx/sites-available:/etc/nginx/sites-available # nginx sites ( in case you recreate the container ) - - ~/apps/volumes/nginx/sites-enabled:/etc/nginx/sites-enabled # nginx sites ( in case you recreate the container ) - - ~/volumes/nginx/ssl:/etc/nginx/ssl + # Composer caching + - ~/.composer:/home/homestead/.composer + # Git configuration (access alias && config) + - ~/.gitconfig:/home/homestead/.gitconfig + # SSH keys for easy deployment inside the container + - ~/.ssh:/home/homestead/.ssh + # All apps + - ~/apps:/apps + # Nginx sites (in case you recreate the container) + - ~/apps/volumes/nginx/sites-available:/etc/nginx/sites-available + - ~/apps/volumes/nginx/sites-enabled:/etc/nginx/sites-enabled links: - - mysql - -mysql: - image: mysql:5.7 - restart: unless-stopped + - mariadb + + # Database service + mariadb: + image: mariadb:10 + restart: always + ports: + - "33060:3306" environment: - MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' + MYSQL_USER: admin + MYSQL_PASSWORD: root + MYSQL_ROOT_PASSWORD: root volumes: - - ~/volumes/mysql:/var/lib/mysql + # A bind-mount volume for persistent database files + - ~/apps/volumes/mysql:/var/lib/mysql + \ No newline at end of file diff --git a/example.nginx.conf b/example.nginx.conf new file mode 100644 index 0000000..842de9e --- /dev/null +++ b/example.nginx.conf @@ -0,0 +1,36 @@ +server { + listen 80 default_server; + listen [::]:80 default_server ipv6only=on; + + root /var/www/html; + server_name localhost; + + index index.html index.htm index.php; + + charset utf-8; + + location / { + try_files \$uri \$uri/ /index.php?\$query_string; + } + + location = /favicon.ico { access_log off; log_not_found off; } + location = /robots.txt { access_log off; log_not_found off; } + + access_log off; + error_log /var/log/nginx/error.log; + + error_page 404 /index.php; + + sendfile off; + + location ~ \.php$ { + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass unix:/var/run/php7.2-fpm.sock; + fastcgi_index index.php; + include fastcgi.conf; + } + + location ~ /\.ht { + deny all; + } +} \ No newline at end of file diff --git a/provision.sh b/provision.sh deleted file mode 100644 index 39e6fa4..0000000 --- a/provision.sh +++ /dev/null @@ -1,170 +0,0 @@ -#!/usr/bin/env bash - -# Laravel homestead original provisioning script -# https://github.com/laravel/settler - -# Update Package List -apt-get update -apt-get upgrade -y - -# Force Locale -apt-get install -y locales -echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale -locale-gen en_US.UTF-8 -export LANG=en_US.UTF-8 - -# Install ssh server -apt-get -y install openssh-server pwgen -mkdir -p /var/run/sshd -sed -i "s/UsePrivilegeSeparation.*/UsePrivilegeSeparation no/g" /etc/ssh/sshd_config -sed -i "s/UsePAM.*/UsePAM no/g" /etc/ssh/sshd_config -sed -i "s/PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config - -# Basic packages -apt-get install -y sudo software-properties-common nano curl \ -build-essential dos2unix gcc git git-flow libpcre3-dev apt-utils \ -make python2.7-dev python-pip re2c supervisor unattended-upgrades whois vim zip unzip - -# PPA -apt-add-repository ppa:ondrej/php -y - -# Update Package Lists -apt-get update - -# Create homestead user -adduser homestead -usermod -p $(echo secret | openssl passwd -1 -stdin) homestead -# Add homestead to the sudo group and www-data -usermod -aG sudo homestead -usermod -aG www-data homestead - -# Timezone -ln -sf /usr/share/zoneinfo/UTC /etc/localtime - -# PHP -apt-get install -y php7.2-cli php7.2-dev \ -php7.2-mysql php7.2-pgsql php7.2-sqlite3 php7.2-soap \ -php7.2-json php7.2-curl php7.2-gd \ -php7.2-gmp php7.2-imap php-xdebug \ -php7.2-mbstring php7.2-zip \ -php-pear php-apcu php-memcached php-redis \ -php7.2-dom php7.2-bcmath - -# Nginx & PHP-FPM -apt-get install -y nginx php7.2-fpm - -# Install Composer -curl -sS https://getcomposer.org/installer | php -mv composer.phar /usr/local/bin/composer - -# Add Composer Global Bin To Path -printf "\nPATH=\"/home/homestead/.composer/vendor/bin:\$PATH\"\n" | tee -a /home/homestead/.profile - -# Laravel Envoy -su homestead <<'EOF' -/usr/local/bin/composer global require "laravel/envoy=~1.5.0" -EOF - -# Set Some PHP CLI Settings -sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/7.2/cli/php.ini -sed -i "s/display_errors = .*/display_errors = On/" /etc/php/7.2/cli/php.ini -sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.2/cli/php.ini -sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.2/cli/php.ini - -sed -i "s/.*daemonize.*/daemonize = no/" /etc/php/7.2/fpm/php-fpm.conf -sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/7.2/fpm/php.ini -sed -i "s/display_errors = .*/display_errors = On/" /etc/php/7.2/fpm/php.ini -sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/7.2/fpm/php.ini -sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.2/fpm/php.ini -sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.2/fpm/php.ini - -# Enable Remote xdebug -echo "xdebug.remote_enable = 1" >> /etc/php/7.2/fpm/conf.d/20-xdebug.ini -echo "xdebug.remote_connect_back = 1" >> /etc/php/7.2/fpm/conf.d/20-xdebug.ini -echo "xdebug.remote_port = 9000" >> /etc/php/7.2/fpm/conf.d/20-xdebug.ini -echo "xdebug.var_display_max_depth = -1" >> /etc/php/7.2/fpm/conf.d/20-xdebug.ini -echo "xdebug.var_display_max_children = -1" >> /etc/php/7.2/fpm/conf.d/20-xdebug.ini -echo "xdebug.var_display_max_data = -1" >> /etc/php/7.2/fpm/conf.d/20-xdebug.ini -echo "xdebug.max_nesting_level = 500" >> /etc/php/7.2/fpm/conf.d/20-xdebug.ini - -# Not xdebug when on cli -phpdismod -s cli xdebug - -# Set The Nginx & PHP-FPM User -sed -i '1 idaemon off;' /etc/nginx/nginx.conf -sed -i "s/user www-data;/user homestead;/" /etc/nginx/nginx.conf -sed -i "s/# server_names_hash_bucket_size.*/server_names_hash_bucket_size 64;/" /etc/nginx/nginx.conf - -mkdir -p /run/php -touch /run/php/php7.2-fpm.sock -sed -i "s/user = www-data/user = homestead/" /etc/php/7.2/fpm/pool.d/www.conf -sed -i "s/group = www-data/group = homestead/" /etc/php/7.2/fpm/pool.d/www.conf -sed -i "s/;listen\.owner.*/listen.owner = homestead/" /etc/php/7.2/fpm/pool.d/www.conf -sed -i "s/;listen\.group.*/listen.group = homestead/" /etc/php/7.2/fpm/pool.d/www.conf -sed -i "s/;listen\.mode.*/listen.mode = 0666/" /etc/php/7.2/fpm/pool.d/www.conf - -# Install Node -curl --silent --location https://deb.nodesource.com/setup_8.x | bash - -apt-get install -y nodejs -npm install -g grunt-cli -npm install -g gulp -npm install -g bower - -# Install SQLite -apt-get install -y sqlite3 libsqlite3-dev - -# Memcached -apt-get install -y memcached - -# Beanstalkd -apt-get install -y beanstalkd -sed -i "s/#START=yes/START=yes/" /etc/default/beanstalkd - -# Redis -apt-get install -y redis-server -sed -i "s/daemonize yes/daemonize no/" /etc/redis/redis.conf - -# Configure default nginx site -block="server { - listen 80 default_server; - listen [::]:80 default_server ipv6only=on; - - root /var/www/html; - server_name localhost; - - index index.html index.htm index.php; - - charset utf-8; - - location / { - try_files \$uri \$uri/ /index.php?\$query_string; - } - - location = /favicon.ico { access_log off; log_not_found off; } - location = /robots.txt { access_log off; log_not_found off; } - - access_log off; - error_log /var/log/nginx/app-error.log error; - - error_page 404 /index.php; - - sendfile off; - - location ~ \.php$ { - fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass unix:/run/php/php7.2-fpm.sock; - fastcgi_index index.php; - include fastcgi.conf; - } - - location ~ /\.ht { - deny all; - } -} -" - -rm /etc/nginx/sites-enabled/default -rm /etc/nginx/sites-available/default - -cat > /etc/nginx/sites-enabled/default -echo "$block" > "/etc/nginx/sites-enabled/default" diff --git a/supervisor.conf b/supervisor.conf index 8dd66be..4f2da44 100644 --- a/supervisor.conf +++ b/supervisor.conf @@ -6,8 +6,8 @@ command=/usr/sbin/sshd -D autostart=true autorestart=true -[program:php-fpm7.1] -command=/usr/sbin/php-fpm7.2 +[program:php7.2-fpm] +command=/usr/sbin/php7.2-fpm autostart=true autorestart=true