Setting up environment for Laravel, Symfony and WP using only one docker

masoud sharifi
3 min readJul 14, 2019

--

Photo by Fred Rivett on Unsplash

This is the easiest way to dockerize Symfony, Laravel and WP together with one docker environment using Laradock.

Laradock is a full PHP development environment for Docker. It includes pre-packaged Docker Images, all pre-configured to provide a wonderful PHP development environment.

Install requirements

GIT

Docker >= 17.12

Step 1: Fork Laradock repo

Fork Laradock repo from main Laradock repository:

After Fork this repo you have copy of Laradock in your github account.

Step 2: Clone Laradock to local machine

Clone forked Laradock repository to your local machine whit following commands:

$ mkdir ~/laradock_projects$ cd ~/laradock_projects/$ git clone https://github.com/YOUR-USERNAME/laradock.git

Create branch from stable version of Laradock and switch to that branch:

$ cd ~/laradock_projects/laradock$ git checkout tags/v7.15 -b v7.15

Step 3: Configure Laradock

Make .env file from env-example:

$ cp env-example .env

Note: Laradock using the last version of MySQL (version 8). I used MySQL 5.7 in my project because i couldn’t setup laravel with version 8. To change version of MYSQL edit .env and find MYSQL_VERSION=latest and change it to MYSQL_VERSION=5.7

Set WORKSPACE_INSTALL_SYMFONY to true in .env file to install Symfony Local Web Server:

WORKSPACE_INSTALL_SYMFONY=true

Step 4: Make projects directory

Create 3 directory in Laradock parent directory so you should create symfony, laravel and wordpress. List directory structure

$ cd ~/laradock_projects/
$ ls

After ls you folder structure should look like this:

+laradock
+laravel
+symfony
+wordpress

Step 5: Configure NGINX

Go to laradock nginx folder and copy default.conf for all projects:

$ cd ~/laradock_projects/laradock/nginx/sites$ cp default.conf symfony.conf$ cp default.conf laravel.conf$ cp default.conf wordpress.conf

Edit symfony.conf , laravel.conf and wordpress.conf and set server_name and change root path for each of theme.For example for wordpress edit wordpress.conf like this:

Edit laravel.conf like this:

And for symfony:

Step 6: Create projects domain

Edit hosts file:

$ sudo vi /etc/hosts

And add the following lines to hosts:

127.0.0.1 symfony.test
127.0.0.1 laravel.test
127.0.0.1 wordpress.test

Step 7:Builds, creates, starts services

Run following commands in laradock directory to builds, creates and starts docker services:

$ cd ~/laradock_projects/laradock/$ docker-compose up -d nginx mysql

After run all project you can check if all docker services is run with docker-compose ps.

Step 8: Install symfony

Go to laradock folder and go to enter workspace container:

$ cd ~/laradock_projects/laradock/$ sudo docker-compose exec workspace bash

Install symfony framework:

$ cd symfony$ symfony new ./ 3.4

Enter symfony.test in your browser.

Step 9: Instll laravel

Go to laradock folder and go to enter workspace container:

$ cd ~/laradock_projects/laradock/$ sudo docker-compose exec workspace bash

Install laravel framework:

$ cd laravel$ composer create-project --prefer-dist laravel/laravel

Move laravel folder content to parent directory:

$ shopt -s dotglob$ mv -v ./* ../

Enter laravel.test in your browser.

Step 10: Install wordpress

Exit workspace and go to wordpress folder:

$ cd ~/laradock_projects/wordpress/

Get wordpress file and extract it:

$ wget https://wordpress.org/latest.tar.gz$ unzip latest.tar.gz

Move wordpress directory content to parent directory.

$ shopt -s dotglob$ mv -v ./* ../

Enter wordpress.test in browser.

Feel free to contact me if you have any questions on Twitter

--

--