Setting up an Apache + PHP on Ubuntu

Introduction

If you absolutely need to seperate the reverse-proxy from serving html & php content directly, you may but apache/php inside a container.

This can be done either on an Ubuntu Server host, or inside a container without using a Dockerfile: commit and you’ve got the image.

Requirements

This image/container will be based on ubuntu:latest or custom/ubuntu.

You probably want to link apache/php to an MySQL/MariaDB container.

Prepare the Apache/PHP image/container

Run the container,

app=apachephpprod
docker ps -a | grep $app
docker run --name $app -h $app \
    -p 80XX:80 -p 84XX:443 \
    -v /data/$app.html:/var/www/html \
    -v /data/$app.sitesenabled:/etc/apache2/sites-enabled \
    [custom/ubuntu](ubuntu) \
    #ubuntu:latest
docker ps -a | grep $app
docker exec -ti $app bash

Install apache2 & eventually ssl,

apt -y install apache2...
a2enmod ...

If needed, check that you can access the mariadb services,

apt -y install net-tools netcat curl inetutils-ping mariadb-client

cat /etc/hosts
ping -c1 mariadb
nc -z -v mariadb 3306
mysql -uroot -pPASSWORD_HERE -h mariadb --protocol=TCP
show databases;
use DBNAME;
show tables;
^D

Setup reverse-proxy & ready to go

Setup your reverse-proxy against port 80XX or 84XX.

You can now check the result,

https://dockerhost.example.com/

Resources

Apache and PHP on Docker https://medium.com/dev-tricks/apache-and-php-on-docker-44faef716150


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun