Running laravel on laradock apache2

In the official laradock documentation, there is a lot of sample code to run nginx, but laradock also provides a mechanism to use apache.

Getting Started

First of all, if there is a service that is running, let’s bring it down, to prevent troublesome troubles.

docker-compose down

Create the following localhost.conf file in the laradock/apache2/sites folder on the host OS side.


<VirtualHost *:80>
  ServerName localhost
  DocumentRoot /var/www/public/
  Options Indexes FollowSymLinks

  <Directory "/var/www/public/">
    AllowOverride All
    <IfVersion < 2.4>
      Allow from all
    <IfVersion >= 2.4>
      Require all granted

This is what the image looks like.

Then record the localhost.conf file to your Docker image with the following command:

docker-compose build apache2

Now you are ready to go.

Start the container in the same way as for nginx, but specify the apache2 service instead of the nginx service

docker-compose up -d apache2 mysql

More details

There is a difference in the default settings of nginx and apache2 in laradock.

default nginx settings of laradock.

The default setting of nginx of laradock is to make the /var/www/public folder of the OS in the container as Document Root when accessed from http://localhost.

default apache2 settings of laradock .

On the other hand, in apache2 of laradock, when accessing with http://localhost, the /var/www folder of the OS in the container is set to be published.

If you modify this to expose the /var/www/public folder like nginx, you can develop laravel with the same usability as when using nginx.

/ laradock / apache2 / sites folder

A file called sample.conf.example is provided in the laradock/apache2/sites/ folder.

I copied this file, pasted as a new file called localhost.conf, and rewrote the following three directories.

  • ServerName
  • DocumentRoot
  • Directory

Note that it works even if the file name is not localhost.conf, but the end of the file name must end with .conf.

In laradock, if you save the * .conf file in the laradock/apache2/sites/ folder on the host OS side, it seems that it is set to be recognized by apache.