2

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):

  1. For each app, add 127.0.0.1 myapp to my local /etc/hosts file so that it redirects to the docker container.

  2. In my /etc/apache2/apache2.conf file, set the document root to /var/www/html

  3. 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):

  1. In /etc/apache2/apache2.conf and /etc/apache2/sites-available only define the web root: /var/www/html

  2. Mount the apps as sub directories of the web root: /var/www/html/myapp_1

  3. Use .htaccess inside the respective myapp folder to configure the apps. They should be accessible at http://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?

Barret Wallace
  • 155
  • 3
  • 13
  • I haven't read the whole thing but got the gist of it, I use https://github.com/jwilder/nginx-proxy without a problem (13 applications currently, no SSL), each of my applications have its own webserver (NGINX) and php-fpm service. Everything is orchestrated with gitlab-ci (locally hosted). – Kyslik Jun 11 '18 at 10:11
  • Thanks, but I don't see how this solves my problem. I could use the nginx-proxy to dynamically forward `myapp_1.localhost` , `myapp_2.localhost` etc. to distinct docker containers. However, my problem lies _within_ these containers: How do I configure their `apache2.conf` files? – Barret Wallace Jun 11 '18 at 12:29
  • Your question has no answer mate, its too broad, I invested time to let you know how I do it. – Kyslik Jun 11 '18 at 12:30
  • Could perhaps Apache's [mod_vhost_alias](https://httpd.apache.org/docs/2.4/mod/mod_vhost_alias.html) be a solution? It is intended for dynamically configured mass virtual hosting. – Barret Wallace Jun 11 '18 at 16:48
  • If you have one app per container than you do not need to have vhost at all, just default configuration to handle port 80. Let the nginx-proxy do the routing job. – Kyslik Jun 11 '18 at 16:49
  • OK, I give up. Probably, it's the best way to have only one app per container, indeed. If you convert your comment into an answer, I'll accept it. – Barret Wallace Jun 13 '18 at 18:21
  • The real question that you should be asking is: should I have one container that includes webserver (Apache / NGINX), database (MySQL) and application server (PHP) or one container per service - ending up with probably `4xNUM OF APPS` containers. I use the latter and use docker-compose on other hand [fideloper](https://github.com/fideloper) uses one container that bundles in everything (as far as I remember). Bundling multiple applications is just *stupid* (defeating the purpose od docker) just use VPS for that. – Kyslik Jun 13 '18 at 18:25

0 Answers0