PHP‐Apache Setup Guide - ajgillis04/GillisDockerDepot GitHub Wiki
This guide outlines the steps to set up a Docker container running an Apache server with PHP. This combination is widely used for web development and hosting PHP-based applications.
- Docker installed
- PHP-Apache container running in your Docker stack
docker run --rm -v /share/Docker/GillisDockerDepot/appdata/php-apache/apache2:/apache2 httpd:2.4 bash -c 'cp -r /usr/local/apache2/conf/* /apache2/'
docker run --rm -v /share/Docker/GillisDockerDepot/appdata/php-apache/apache2:/apache2 php:apache bash -c 'cp /etc/apache2/apache2.conf /apache2/'
copy your html files into /share/Docker/GillisDockerDepot/appdata/php-apache/var/www/html
docker exec -it php-apache-<name> bash -c "cat > /etc/apache2/sites-available/000-default.conf <<- 'EOF'
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOF"
docker exec -it php-apache-<name> ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/
docker exec -it php-apache-<name> bash -c "echo 'LoadModule mime_module /usr/lib/apache2/modules/mod_mime.so' >> /etc/apache2/apache2.conf"
docker exec -it php-apache-<name> bash -c "cat > /var/www/html/.htaccess <<- 'EOF'
AddType text/html .html
AddType text/css .css
AddType application/javascript .js
DirectoryIndex index.html
EOF"
docker exec -it php-apache-<name> bash -c "cat >> /etc/apache2/sites-available/000-default.conf <<- 'EOF'
AddType text/html .html
AddType text/css .css
AddType application/javascript .js
DirectoryIndex index.html
ErrorDocument 404 /404.html
EOF"
docker exec -it php-apache-<name> apachectl restart
docker exec -it php-apache-<name> apachectl configtest
find /pathtodata/GillisDockerDepot/appdata/php-apache-<name>/var/www/html/assets/img/portfolio -type f -exec chmod 644 {} \;
find /pathtodata/GillisDockerDepot/appdata/php-apache-<name>/var/www/html/assets/img/portfolio -type d -exec chmod 755 {} \;