DATA path, vhost automatically enable
This commit is contained in:
parent
d0d15c612c
commit
71688f4384
18
README.md
18
README.md
@ -30,6 +30,11 @@ Windows: ```C:\<user>\worspace```
|
||||
|
||||
Always go in `<workspace>/devcontainer` to execute docker-compose command.
|
||||
|
||||
Create a `.env` file and add configuration vars:
|
||||
- DATA : where you store database, vhost, ...
|
||||
- WORKSPACE : your workspace files
|
||||
|
||||
|
||||
## Launch services (first time build)
|
||||
```bash
|
||||
docker-compose up -d
|
||||
@ -71,6 +76,8 @@ docker-compose exec <container_name>
|
||||
```
|
||||
|
||||
## PHP-FPM & Apache vhosts
|
||||
Create a VHOST file in `<DATA>/httpd/`. Add this to your vhost to connect php.
|
||||
|
||||
```
|
||||
# Redirect to local php-fpm if mod_php is not available
|
||||
<IfModule !mod_php7.c>
|
||||
@ -81,7 +88,7 @@ docker-compose exec <container_name>
|
||||
</IfModule>
|
||||
|
||||
<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
|
||||
SetHandler "proxy:fcgi://fpm70/:9000
|
||||
SetHandler "proxy:fcgi://fpm70:9000
|
||||
</FilesMatch>
|
||||
<FilesMatch ".+\.phps$">
|
||||
# Deny access to raw php sources by default
|
||||
@ -96,16 +103,15 @@ docker-compose exec <container_name>
|
||||
</IfModule>
|
||||
</IfModule>
|
||||
```
|
||||
Don't forget to create the directory in your workspace.
|
||||
To enable the new vhosts, simply stop an start the `httpd` container (`docker-compose stop && docker-compose start`).
|
||||
|
||||
## Database
|
||||
Database files are store in `<workspace>/database`.
|
||||
Even if you delete your container date are preserved.
|
||||
Database files are store in `<DATA>/`.
|
||||
Even if you delete your container, all data are preserved.
|
||||
|
||||
Read the doc official MariaDB: `https://hub.docker.com/_/mariadb/`
|
||||
|
||||
## HTTPd
|
||||
|
||||
|
||||
|
||||
# Additional
|
||||
## Ip Address
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: '2.3'
|
||||
version: '3'
|
||||
services:
|
||||
# PHP 5.6 FPM
|
||||
fpm56:
|
||||
@ -30,7 +30,7 @@ services:
|
||||
image: mailcatcher:0.6.5
|
||||
container_name: mailcatcher
|
||||
ports:
|
||||
- '1080:1080'
|
||||
- '1080:1080'
|
||||
logging:
|
||||
driver: 'json-file'
|
||||
options:
|
||||
@ -44,14 +44,15 @@ services:
|
||||
ports:
|
||||
- '3306:3306'
|
||||
volumes:
|
||||
- ${WORKSPACE}/container-data/db:/var/lib/mysql
|
||||
- ${DATA}/db:/var/lib/mysql
|
||||
logging:
|
||||
driver: 'json-file'
|
||||
options:
|
||||
max-size: '500m'
|
||||
max-file: '9'
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: 'password'
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
|
||||
MYSQL_ADMIN_PASSWORD: 'password'
|
||||
# Apache HTTPd
|
||||
httpd:
|
||||
build: ./dockerfiles/httpd/2.4/debian-9
|
||||
@ -60,19 +61,10 @@ services:
|
||||
ports:
|
||||
- '80:80'
|
||||
volumes:
|
||||
- ${WORKSPACE}/container-data/httpd:/etc/apache2/sites-available
|
||||
- ${DATA}/httpd:/sites-available
|
||||
- ${WORKSPACE}:/home/vhosts
|
||||
logging:
|
||||
driver: 'json-file'
|
||||
options:
|
||||
max-size: '1g'
|
||||
max-file: '10'
|
||||
|
||||
networks:
|
||||
default:
|
||||
driver: bridge
|
||||
ipam:
|
||||
driver: default
|
||||
config:
|
||||
- subnet: 172.18.0.0/16
|
||||
gateway: 172.18.0.1
|
||||
|
@ -1 +1,2 @@
|
||||
WORKSPACE=/home/ubuntu/workspace
|
||||
DATA=/home/ubuntu/cdata
|
||||
|
@ -6,22 +6,29 @@ ENV DEBIAN_FRONTEND noninteractive
|
||||
ENV TZ=Europe/Paris
|
||||
|
||||
# Installation
|
||||
RUN apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade && \
|
||||
apt-get -y install nano apache2 libapache2-mod-xsendfile && \
|
||||
echo "ServerName 127.0.0.1" > /etc/apache2/conf-available/httpd.conf && \
|
||||
mkdir /var/run/apache2 && mkdir /var/lock/apache2 && \
|
||||
rm -f /var/log/apache2/error.log && ln -s /dev/stderr /var/log/apache2/error.log && \
|
||||
rm -f /var/log/apache2/access.log && ln -s /dev/stdout /var/log/apache2/access.log
|
||||
RUN apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade \
|
||||
&& apt-get -y install nano apache2 libapache2-mod-xsendfile \
|
||||
&& echo "ServerName 127.0.0.1" > /etc/apache2/conf-available/httpd.conf \
|
||||
&& mkdir /var/run/apache2 && mkdir /var/lock/apache2 \
|
||||
&& rm -f /var/log/apache2/error.log && ln -s /dev/stderr /var/log/apache2/error.log \
|
||||
&& rm -f /var/log/apache2/access.log && ln -s /dev/stdout /var/log/apache2/access.log \
|
||||
&& echo "Europe/Paris" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists/* && mkdir /docker-entrypoint.d && mkdir /sites-available
|
||||
|
||||
RUN perl /usr/sbin/a2enconf httpd
|
||||
RUN perl /usr/sbin/a2enmod autoindex deflate expires headers rewrite actions proxy proxy_fcgi
|
||||
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ADD vhosts/test.conf /etc/apache2/sites-available/
|
||||
|
||||
ADD run.sh /run.sh
|
||||
RUN chmod +x /run.sh
|
||||
|
||||
# Entrypoint
|
||||
ADD vhost.sh /docker-entrypoint.d/
|
||||
RUN chmod 775 /docker-entrypoint.d/vhost.sh
|
||||
|
||||
# Add VOLUMEs
|
||||
VOLUME ["/home/vhosts"]
|
||||
VOLUME ["/home/vhosts", "/sites-available"]
|
||||
|
||||
# Expose and Run
|
||||
EXPOSE 80
|
||||
|
@ -4,5 +4,9 @@ set -e
|
||||
# Apache gets grumpy about PID files pre-existing
|
||||
rm -f /usr/local/apache2/logs/httpd.pid
|
||||
|
||||
if [ -f /docker-entrypoint.d/vhost.sh ]; then
|
||||
/docker-entrypoint.d/vhost.sh
|
||||
fi
|
||||
|
||||
source /etc/apache2/envvars
|
||||
exec apache2 -D FOREGROUND
|
||||
|
43
dockerfiles/httpd/2.4/debian-9/vhost.sh
Normal file
43
dockerfiles/httpd/2.4/debian-9/vhost.sh
Normal file
@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# --- Disable all website
|
||||
cd /etc/apache2/sites-available/
|
||||
for f in *.conf; do
|
||||
if [ $f = "000-default.conf" ]; then
|
||||
continue
|
||||
fi
|
||||
if [ $f = "default-ssl.conf" ]; then
|
||||
continue
|
||||
fi
|
||||
if [ $f = "test.conf" ]; then
|
||||
continue
|
||||
fi
|
||||
a2dissite $f;
|
||||
rm -vf /etc/apache2/sites-available/$f;
|
||||
done;
|
||||
|
||||
if [ ! -d /home/vhosts/test ]; then
|
||||
mkdir /home/vhosts/test
|
||||
fi
|
||||
|
||||
# --- Copy Vhosts files
|
||||
VHOSTS='000-default.conf test.conf'
|
||||
cd /etc/apache2/sites-available/
|
||||
for f in *.conf; do
|
||||
if [ $f = "000-default.conf" ]; then
|
||||
continue
|
||||
fi
|
||||
if [ $f = "default-ssl.conf" ]; then
|
||||
continue
|
||||
fi
|
||||
if [ $f = "test.conf" ]; then
|
||||
continue
|
||||
fi
|
||||
if [ -f $f ]; then
|
||||
cp -vf /sites-available/$f /etc/apache2/sites-available/
|
||||
VHOSTS+=" $f"
|
||||
fi
|
||||
done;
|
||||
|
||||
a2ensite $VHOSTS
|
40
dockerfiles/httpd/2.4/debian-9/vhosts/test.conf
Normal file
40
dockerfiles/httpd/2.4/debian-9/vhosts/test.conf
Normal file
@ -0,0 +1,40 @@
|
||||
<VirtualHost *:80>
|
||||
ServerName test.local
|
||||
ServerAdmin webmaster@localhost
|
||||
DocumentRoot /home/vhosts/test
|
||||
|
||||
# Redirect to local php-fpm if mod_php is not available
|
||||
<IfModule !mod_php7.c>
|
||||
<IfModule proxy_fcgi_module>
|
||||
# Enable http authorization headers
|
||||
<IfModule mod_setenvif.c>
|
||||
<IfModule mod_proxy_fcgi.c>
|
||||
SetEnvIfNoCase Authorization "(.+)" HTTP_AUTHORIZATION=$1
|
||||
</IfModule>
|
||||
</IfModule>
|
||||
|
||||
<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
|
||||
SetHandler "proxy:fcgi://fpm70:9000
|
||||
</FilesMatch>
|
||||
<FilesMatch ".+\.phps$">
|
||||
# Deny access to raw php sources by default
|
||||
# To re-enable it's recommended to enable access to the files
|
||||
# only in specific virtual host or directory
|
||||
Require all denied
|
||||
</FilesMatch>
|
||||
# Deny access to files without filename (e.g. '.php')
|
||||
<FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
|
||||
Require all denied
|
||||
</FilesMatch>
|
||||
</IfModule>
|
||||
</IfModule>
|
||||
|
||||
<Directory /home/vhosts/test/>
|
||||
Options FollowSymLinks Indexes
|
||||
AllowOverride all
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
||||
</VirtualHost>
|
@ -1,10 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
PASS=${MYSQL_ROOT_PASSWORD:-$(pwgen -s 12 1)}
|
||||
_word=$( [ ${MYSQL_ROOT_PASSWORD} ] && echo "preset" || echo "random" )
|
||||
PASS=${MYSQL_ADMIN_PASSWORD:-$(pwgen -s 12 1)}
|
||||
_word=$( [ ${MYSQL_ADMIN_PASSWORD} ] && echo "preset" || echo "random" )
|
||||
echo "=> Creating MariaDB admin user with ${_word} password"
|
||||
|
||||
mysql -uroot -e "CREATE USER 'admin'@'%' IDENTIFIED BY '$PASS'"
|
||||
mysql -uroot -e "CREATE USER IF NOT EXISTS 'admin'@'%' IDENTIFIED BY '$PASS'"
|
||||
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION"
|
||||
|
||||
echo "=> Done!"
|
||||
|
Loading…
Reference in New Issue
Block a user