I'm looking for a good practice for deploying my php web apps to a local docker container based on Ubuntu 18.04 and Apache 2.4.
Depending on the kind of app, its base file is myapp/public/index.php
(Laravel) or just myapp/index.php
(plain vanilla php). I can, of course, mount the apps into /var/www/html/myapp
or any other location.
Option 1 (fixed /etc/hosts, apache2.conf and vhosts):
For each app, add
127.0.0.1 myapp
to my local/etc/hosts
file so that it redirects to the docker container.In my
/etc/apache2/apache2.conf
file, set the document root to/var/www/html
For each web app, define a vhost in
/etc/apache2/sites-available
Advantages:
I can access my apps locally by using urls like
http://myapp_1
,http://myapp_2
etc.I can point
http://myapp_1
to/var/www/myapp_1/public
.I can later use this configuration in my production environment (no docker) more or less without modifications.
Disadvantages:
The apache configuration is hard-coded into the docker image. Whenever I add, remove or rename an app, I have to adjust and re-build the docker image.
Teamwork is very cumbersome as everyone may work on a different subset of apps, which has to be in his/her docker image.
Option 2 (use .htaccess):
In
/etc/apache2/apache2.conf
and/etc/apache2/sites-available
only define the web root:/var/www/html
Mount the apps as sub directories of the web root:
/var/www/html/myapp_1
Use
.htaccess
inside the respectivemyapp
folder to configure the apps. They should be accessible athttp://localhost/myapp_1
etc.
Advantages:
No need to adjust the docker image for new apps.
No changes to local
/etc/hosts
files.
Disadvantages:
I don't know if (and how)
.htaccess
can be configured so that it can be used like a<VirtualHost>
configuration with all paths working correctly (e.g. css).The apache configuration significantly differs from the production environment.
My question
What is a good practice to combine the advantages of both approaches? Which option would you choose? Is there another alternative, that I have not mentioned?