Symfony 4 LAMP,This educational covers installing the LAMP stack for a Symfony four internet site.
The LAMP stack is:
- Linux (Ubuntu)
- Apache
- MySQL
- PHP
We’re going with PHP 7.2, as it’s far the most contemporary PHP model on the time of recording.
PHP 7.1.Three is the bare minimum PHP version required to run a Symfony four software.
This tutorial is nearly identical to the LAMP tutorial for Symfony 3.
However, as referred to, our PHP model might be distinctive.
The Apache Vhost configuration is slightly specific, to reflect the Symfony 4 listing shape.
We may also need to do a little greater setup regarding surroundings variables. This might be performed in some films time.
I’m going to provide abbreviated steps here, but if you’d just like the full steps, please watch this video, and adapt the PHP and Apache sections as a consequence.
Symfony 4 LAMP,Spinning Up A Server
To begin with we are going to create a new Digital Ocean Droplet the usage of the $10 plan, putting in a clean replica of Ubuntu 16.04.Three x64 as our virtual server / droplet Operating System.
You can follow this system on a exclusive VPS company inclusive of Linode, or Amazon AWS.
If you do not yet have a Digital Ocean account, please create one now. By using this hyperlink you may get $10 preliminary credit score, which goes to be greater than enough to finish all the examples on this direction. Full disclosure: that is an affiliate link.
Be certain 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 must take about 30 seconds.
Once achieved, you have to be capable of SSH into the box by using strolling:
ssh [email protected]
Change the IP address to match your own Droplet for this reason.
I’m going to anticipate you have created a neighborhood access in /and many others/hosts or similar, and feature a added an access inclusive of:
# from your local machine
# in the /etc/hosts file
# (or windows equivalent)
165.227.110.26 crvfakeexample.com
This step is essential to ensure you may browse for your made up domain call while not having to virtually check in a actual new domain. This will most effective be usable for your very own local PC.
Apache Server Setup
Switch back in your server’s terminal consultation 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
touch crvfakeexample.com.conf
vim crvfakeexample.com.conf
Ok, so we’ve done pretty lots there. There’s nothing new, again, if uncertain please watch the preceding video in which all of this and greater become covered in greater depth.
The Vhost config we need is as follows:
<VirtualHost *:80>
ServerName crvfakeexample.com
ServerAlias www.crvfakeexample.com
DocumentRoot /var/www/crvfakeexample.com/public
<Directory /var/www/crvfakeexample.com/public>
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]
</IfModule>
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/crvfakeexample.com>
# 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/crvfakeexample.com/public/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
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"
</VirtualHost>
This is essentially copied from the Symfony Apache example, with the Apache 2.Four exchange made (Require all granted).
We will want to tweak this document again for the duration of the setup of our environment variables.
After saving and exiting, be sure to enable the website and reload Apache:
a2ensite crvfakeexample.com.conf
service apache2 reload
Installing PHP 7.2 For Symfony 4
Symfony four expects as a minimum Symfony 7.1.3.
In order to install PHP 7.1 or extra, a trendy installation of Ubuntu wishes a touch assist.
PHP 7.Zero is the release of PHP available in the presently supplied Ubuntu package list. At the time of recording, with a view to installation PHP 7.1, or PHP 7.2, we can use a 3rd birthday celebration package listing.
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 \
php7.2-zip
This installs PHP 7.2, the contemporary and greatest on the time of recording:
php -v
PHP 7.2.0-2+ubuntu16.04.1+deb.sury.org+2 (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 v7.2.0-2+ubuntu16.04.1+deb.sury.org+2, Copyright (c) 1999-2017, by Zend Technologies
We shall also need to install MySQL.
apt-get install mysql-server
Follow the activates.
You may be requested to provide a root password.
To make your lifestyles as clean as viable, use the password of pass.
It should not need saying, however of route don’t use this password in manufacturing. This is a demo / example.
This is our primary LAMP server setup for Symfony four.