From 982aa92e804d384d2c4d15ce73f721e5cc13f22d Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Fri, 26 Apr 2019 08:58:12 +0100 Subject: [PATCH] Start implementing docker --- bin/php-swap | 65 ++++------------ bin/php-swap.old | 53 +++++++++++++ .../apache/sites-enabled/httpd-vhosts.conf | 75 +++++++++++++++++++ docker/web/docker-compose.yml | 20 +++++ docker/web/php/Dockerfile | 5 ++ docker/web/php/Dockerfile.sample | 5 ++ 6 files changed, 174 insertions(+), 49 deletions(-) create mode 100755 bin/php-swap.old create mode 100644 docker/web/apache/sites-enabled/httpd-vhosts.conf create mode 100644 docker/web/docker-compose.yml create mode 100644 docker/web/php/Dockerfile create mode 100644 docker/web/php/Dockerfile.sample diff --git a/bin/php-swap b/bin/php-swap index 98413385..37ee1935 100755 --- a/bin/php-swap +++ b/bin/php-swap @@ -1,53 +1,20 @@ -#!/usr/bin/bash -line=$(php --version | grep "PHP" -m 1) -libphp="/opt/lampp/modules/libphp7.1.so" -case "$1" in - 5) - file="/opt/lampp/etc/extra/httpd-xampp-php5.conf" - phpexe=$(ls /opt/lampp/bin/php-5.*) - phpcgi=$(ls /opt/lampp/bin/php-cgi-5.*) - phpconfig=$(ls /opt/lampp/bin/php-config-5.*) - phpize=$(ls /opt/lampp/bin/phpize-5.*) - ;; - 7 | 7.1) - file="/opt/lampp/etc/extra/httpd-xampp-php7.conf" - phpexe=$(ls /opt/lampp/bin/php-7.1.*) - phpcgi=$(ls /opt/lampp/bin/php-cgi-7.1.*) - phpconfig=$(ls /opt/lampp/bin/php-config-7.1.*) - phpize=$(ls /opt/lampp/bin/phpize-7.1.*) - ;; - 7.0) - file="/opt/lampp/etc/extra/httpd-xampp-php7.conf" - phpexe=$(ls /opt/lampp/bin/php-7.0.*) - phpcgi=$(ls /opt/lampp/bin/php-cgi-7.0.*) - phpconfig=$(ls /opt/lampp/bin/php-config-7.0.*) - phpize=$(ls /opt/lampp/bin/phpize-7.0.*) - libphp="/opt/lampp/modules/libphp7.0.so" - ;; - *) - echo "Please specify the version you want" - exit 1 - ;; -esac - -lampp='/opt/lampp/lampp' -echo $phpexe -if [ "$(id -u)" != "0" ]; then - echo "Sorry, you are not root." - exit 1 -fi +#!/bin/bash +DOCKER_CONFIG_DIRECTORY="/home/jonathan/.dotfiles/docker/web/" -$lampp stopapache -ln -s -f $file /opt/lampp/etc/extra/httpd-xampp.conf -ln -s -f $phpexe /opt/lampp/bin/php -ln -s -f $phpcgi /opt/lampp/bin/php-cgi -ln -s -f $phpconfig /opt/lampp/bin/php-config -ln -s -f $phpize /opt/lampp/bin/phpize -ln -s -f $libphp /opt/lampp/modules/libphp7.so +if [ ! -z "$1" ]; then + version="$1" -$lampp startapache -echo -echo "Now on PHP ${phpexe##*-}" -exit 0 + if [ "$(whoami)" == "root" ]; then + cd "$DOCKER_CONFIG_DIRECTORY" + docker-compose down + sed "s/%version%/$version/" php/Dockerfile.sample > php/Dockerfile + docker-compose up --build -d + else + gksudo $0 "$version" + fi +else + version="$(echo -e "5.6\n7.0\n7.1\n7.2\n7.3" | rofi -dmenu -p "PHP Version")" + $0 "$version" +fi diff --git a/bin/php-swap.old b/bin/php-swap.old new file mode 100755 index 00000000..98413385 --- /dev/null +++ b/bin/php-swap.old @@ -0,0 +1,53 @@ +#!/usr/bin/bash +line=$(php --version | grep "PHP" -m 1) +libphp="/opt/lampp/modules/libphp7.1.so" +case "$1" in + 5) + file="/opt/lampp/etc/extra/httpd-xampp-php5.conf" + phpexe=$(ls /opt/lampp/bin/php-5.*) + phpcgi=$(ls /opt/lampp/bin/php-cgi-5.*) + phpconfig=$(ls /opt/lampp/bin/php-config-5.*) + phpize=$(ls /opt/lampp/bin/phpize-5.*) + ;; + 7 | 7.1) + file="/opt/lampp/etc/extra/httpd-xampp-php7.conf" + phpexe=$(ls /opt/lampp/bin/php-7.1.*) + phpcgi=$(ls /opt/lampp/bin/php-cgi-7.1.*) + phpconfig=$(ls /opt/lampp/bin/php-config-7.1.*) + phpize=$(ls /opt/lampp/bin/phpize-7.1.*) + ;; + 7.0) + file="/opt/lampp/etc/extra/httpd-xampp-php7.conf" + phpexe=$(ls /opt/lampp/bin/php-7.0.*) + phpcgi=$(ls /opt/lampp/bin/php-cgi-7.0.*) + phpconfig=$(ls /opt/lampp/bin/php-config-7.0.*) + phpize=$(ls /opt/lampp/bin/phpize-7.0.*) + libphp="/opt/lampp/modules/libphp7.0.so" + ;; + *) + echo "Please specify the version you want" + exit 1 + ;; +esac + +lampp='/opt/lampp/lampp' +echo $phpexe +if [ "$(id -u)" != "0" ]; then + echo "Sorry, you are not root." + exit 1 +fi + + +$lampp stopapache +ln -s -f $file /opt/lampp/etc/extra/httpd-xampp.conf +ln -s -f $phpexe /opt/lampp/bin/php +ln -s -f $phpcgi /opt/lampp/bin/php-cgi +ln -s -f $phpconfig /opt/lampp/bin/php-config +ln -s -f $phpize /opt/lampp/bin/phpize +ln -s -f $libphp /opt/lampp/modules/libphp7.so + + +$lampp startapache +echo +echo "Now on PHP ${phpexe##*-}" +exit 0 diff --git a/docker/web/apache/sites-enabled/httpd-vhosts.conf b/docker/web/apache/sites-enabled/httpd-vhosts.conf new file mode 100644 index 00000000..61c79549 --- /dev/null +++ b/docker/web/apache/sites-enabled/httpd-vhosts.conf @@ -0,0 +1,75 @@ +# Virtual Hosts +# +# Required modules: mod_log_config + +# If you want to maintain multiple domains/hostnames on your +# machine you can setup VirtualHost containers for them. Most configurations +# use only name-based virtual hosts so the server doesn't need to worry about +# IP addresses. This is indicated by the asterisks in the directives below. +# +# Please see the documentation at +# +# for further details before you try to setup virtual hosts. +# +# You may use the command line option '-S' to verify your virtual host +# configuration. + +# +# VirtualHost example: +# Almost any Apache directive may go into a VirtualHost container. +# The first VirtualHost section is used for all requests that do not +# match a ServerName or ServerAlias in any block. +# + + ServerName test.local + ServerAlias *.local + VirtualDocumentRoot /var/www/html/%-2/public_html + CustomLog /var/www/html/access.log vhost_combined + ErrorLog /var/www/html/error.log + Options +FollowSymLinks + php_flag session.auto_start off + php_value max_execution_time 18000 + php_flag suhosin.session.cryptua off + + +# +# ServerName test.local +# ServerAlias *.local +# VirtualDocumentRoot /var/www/html/%-2/public_html +# CustomLog /var/www/html/access.log vhost_combined +# ErrorLog /var/www/html/error.log +# Options +FollowSymLinks +# php_flag session.auto_start off +# php_value max_execution_time 18000 +# php_flag suhosin.session.cryptua off +# SSLEngine On +# #SSLCertificateFile /var/www/html/root-ca/certs/local.cert.pem +# #SSLCertificateKeyFile /var/www/html/root-ca/private/local.key.pem +# + + + ServerName test.local.jh + ServerAlias *.local.jh + VirtualDocumentRoot /var/www/html/%-3/public_html + CustomLog /var/www/html/access.log vhost_combined + ErrorLog /var/www/html/error.log + Options +FollowSymLinks + php_flag session.auto_start off + php_value max_execution_time 18000 + php_flag suhosin.session.cryptua off + + + + ServerName test.local.jh + ServerAlias *.local.jh + VirtualDocumentRoot /var/www/html/%-3/public_html + CustomLog /var/www/html/access.log vhost_combined + ErrorLog /var/www/html/error.log + Options +FollowSymLinks + php_flag session.auto_start off + php_value max_execution_time 18000 + php_flag suhosin.session.cryptua off + SSLEngine On + SSLCertificateFile /var/www/html/root-ca/certs/local.cert.pem + SSLCertificateKeyFile /var/www/html/root-ca/private/local.key.pem + diff --git a/docker/web/docker-compose.yml b/docker/web/docker-compose.yml new file mode 100644 index 00000000..33ec81c6 --- /dev/null +++ b/docker/web/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3' +services: + php: + container_name: php + build: ./php/ + volumes: + - /home/jonathan/Sites/:/var/www/html/ + - /home/jonathan/.dotfiles/docker/web/apache/sites-enabled/:/etc/apache2/sites-enabled + ports: + - 80:80 + - 443:443 + restart: always + mysql: + container_name: mysql + image: mysql:5.6 + ports: + - 3306:3306 + environment: + MYSQL_ROOT_PASSWORD: root + restart: always diff --git a/docker/web/php/Dockerfile b/docker/web/php/Dockerfile new file mode 100644 index 00000000..f2dd4717 --- /dev/null +++ b/docker/web/php/Dockerfile @@ -0,0 +1,5 @@ +FROM php:7.3-apache + +RUN a2enmod rewrite vhost_alias ssl + +RUN docker-php-ext-install mysqli pdo pdo_mysql diff --git a/docker/web/php/Dockerfile.sample b/docker/web/php/Dockerfile.sample new file mode 100644 index 00000000..ac3f00cc --- /dev/null +++ b/docker/web/php/Dockerfile.sample @@ -0,0 +1,5 @@ +FROM php:%version%-apache + +RUN a2enmod rewrite vhost_alias ssl + +RUN docker-php-ext-install mysqli pdo pdo_mysql