Symfony 4 LAMP (Linux, Apache, PHP, MySQL) Setup

This tutorial covers installing the LAMP stack for a Symfony 4 website.

The LAMP stack is:

  • Linux (Ubuntu)
  • Apache
  • MySQL
  • PHP

We're going with PHP 7.2, as it is the most current PHP version at the time of recording.

PHP 7.1.3 is the bare minimum PHP version required to run a Symfony 4 application.

This tutorial is almost identical to the LAMP tutorial for Symfony 3.

However, as mentioned, our PHP version will be different.

The Apache Vhost configuration is slightly different, to reflect the Symfony 4 directory structure.

We will also need to do a little extra setup regarding environment variables. This will be done in a few videos time.

I'm going to provide abbreviated steps here, but if you'd like the full steps, please watch this video, and adapt the PHP and Apache sections accordingly.

Spinning Up A Server

To begin with we are going to create a new Digital Ocean Droplet using the $10 plan, installing a fresh copy of Ubuntu 16.04.3 x64 as our virtual server / droplet Operating System.

You can follow this process on a different VPS provider such as Linode, or Amazon AWS.

If you do not yet have a Digital Ocean account, please create one now. By using this link you will get $10 initial credit, which is going to be more than enough to complete all the examples in this course. Full disclosure: this is an affiliate link.

Be sure to upload your SSH key(s) as available. If you do not have an SSH key, then please follow this guide.

Creating your new Droplet should take about 30 seconds.

Once done, you should be able to SSH into the box by running:

ssh root@

Change the IP address to match your own Droplet accordingly.

I'm going to assume you have created a local entry in /etc/hosts or similar, and have a added an entry such as:

# from your local machine
# in the /etc/hosts file
# (or windows equivalent)

This step is important to ensure you can browse to your made up domain name without having to actually register a real new domain. This will only be usable on your own local PC.

Apache Server Setup

Switch back to your server's terminal session now.

apt-get update
apt-get install apache2 -y
cd /etc/apache2/sites-available/
a2dissite 000-default
service apache2 reload
a2enmod rewrite
service apache2 restart

Ok, so we have achieved quite a lot there. There's nothing new, again, if unsure please watch the previous video where all of this and more was covered in greater depth.

The Vhost config we need is as follows:

<VirtualHost *:80>

    DocumentRoot /var/www/
    <Directory /var/www/>
        AllowOverride None
        Require all granted
        Allow from All

        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ index.php [QSA,L]

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeeScript assets
    # <Directory /var/www/>
    #     Options FollowSymlinks
    # </Directory>

    # optionally disable the RewriteEngine for the asset directories
    # which will allow apache to simply reply with a 404 when files are
    # not found instead of passing the request into the full symfony stack
    <Directory /var/www/>
        <IfModule mod_rewrite.c>
            RewriteEngine Off
    ErrorLog /var/log/apache2/crvfakeexample.com_error.log
    CustomLog /var/log/apache2/crvfakeexample.com_access.log combined

    # optionally set the value of the environment variables used in the application
    #SetEnv APP_ENV prod
    #SetEnv APP_SECRET <app-secret-id>
    #SetEnv DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"

This is largely copied from the Symfony Apache example, with the Apache 2.4 change made (Require all granted).

We will need to tweak this file again during the setup of our environment variables.

After saving and exiting, be sure to enable the site and reload Apache:

service apache2 reload

Installing PHP 7.2 For Symfony 4

Symfony 4 expects at least Symfony 7.1.3.

In order to install PHP 7.1 or greater, a standard installation of Ubuntu needs a little help.

PHP 7.0 is the release of PHP available in the currently supplied Ubuntu package list. At the time of recording, in order to install PHP 7.1, or PHP 7.2, we can use a third party package list.

apt-get install python-software-properties -y
add-apt-repository ppa:ondrej/php
apt-get update

apt-get install php7.2 \
  libapache2-mod-php7.2 \
  php7.2-cli \
  php7.2-common \
  php7.2-mysql \
  php7.2-gd \
  php7.2-intl \
  php7.2-xml \
  php7.2-mbstring \

This installs PHP 7.2, the latest and greatest at the time of recording:

php -v
PHP (cli) (built: Dec  7 2017 20:14:31) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache, Copyright (c) 1999-2017, by Zend Technologies

We shall also need to install MySQL.

apt-get install mysql-server

Follow the prompts.

You will be asked to provide a root password.

To make your life as easy as possible, use the password of pass.

It shouldn't need saying, but of course don't use this password in production. This is a demo / example.

This is our basic LAMP server setup for Symfony 4.

Code For This Video

Get the code for this video.


# Title Duration
1 Symfony LAMP (Linux, Apache, PHP, MySQL) Setup 06:58
2 Symfony LEMP (Linux, nginx, PHP, MySQL) Setup 07:15
3 Apache or nginx - You Gotta Get Your Permissions Sorted 02:46
4 Symfony 3.x Demo Deploy Project 02:45
5 Part 1/3 - Deploying with rsync 08:09
6 Part 2/3 - Deploying with rsync - Using builds 07:38
7 Part 3/3 - Deploying with rsync - Shared var 05:02
8 Part 1/3 - Deploying with git 09:42
9 Part 2/3 - Deploying with git - Sharing folders 05:24
10 Part 3/3 - Deploying with git - Adding builds 05:45
11 Symfony 4 LAMP (Linux, Apache, PHP, MySQL) Setup 07:40
12 Symfony 4 LEMP (Linux, nginx, PHP, MySQL) Setup 08:53
13 Getting Comfortable with Symfony 4 Environment Variables 13:56
14 Part 1/2 - Deploying Symfony 4 with rsync 08:23
15 Part 2/2 - Deploying Symfony 4 with rsync 08:24