In this tutorial, we will show you how to install Symfony 5 with Nginx on Debian 10.
Prerequisites
- A server running Debian 10.
- A root password is configured on your server.
Getting Started
Before starting, it is recommended to update your server with the latest version using the following command:
apt-get update -y
apt-get upgrade -y
Once your server is updated, restart it to implement the changes.
Install Nginx, MariaDB, and PHP
First, you will need to install Nginx, MariaDB, PHP and other required libraries on your server. You can install all of them with the following command:
apt-get install nginx mariadb-server php php-fpm php-common php-mysql php-gmp php-curl php-intl php-mbstring php-xmlrpc php-gd php-bcmath php-soap php-ldap php-imap php-xml php-cli php-zip git unzip wget -y
Once all the packages are installed, start Nginx and MariaDB service and enable them to start on system reboot with the following command:
systemctl start nginx
systemctl start mariadb
systemctl enable nginx
systemctl enable mariadb
Once you are done, you can proceed to the next step.
Install Symfony 5
First, you will need to install the Composer on your server. You can download the Composer installation script with the following command:
wget https://getcomposer.org/installer
Next, run the installer as shown below:
php installer
Once the Composer has been downloaded, you should see the following output:
All settings correct for using Composer Downloading... Composer (version 1.9.1) successfully installed to: /root/composer.phar Use it: php composer.phar
Next, move the Composer to /usr/local/bin directory and make it executable:
mv composer.phar /usr/local/bin/composer
chmod x /usr/local/bin/composer
Now, change the directory to the /var/www/html and install Symfony4 with the following command:
cd /var/www/html
composer create-project symfony/skeleton symfony5
Next, give proper permissions to the symfony4 directory as shown below:
chown -R www-data:www-data /var/www/html/symfony5
chmod -R 755 /var/www/html/symfony5
Configure Nginx for Symfony 5
Next, you will need to create an Nginx virtual host configuration file for Symfony4. You can create it with the following command:
nano /etc/nginx/sites-available/symfony.conf
Add the following lines:
server { server_name your-server-ip; root /var/www/html/symfony5/public; location / { try_files $uri /index.php$is_args$args; } location ~ ^/index.php(/|$) { fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; fastcgi_split_path_info ^(. .php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; internal; } location ~ .php$ { return 404; } error_log /var/log/nginx/symfony_error.log; access_log /var/log/nginx/symfony_access.log; }
Save and close the file when you are finished. Then, enable the Nginx virtual host with the following command:
ln -s /etc/nginx/sites-available/symfony.conf /etc/nginx/sites-enabled/
Next, check the Nginx for any syntax error with the following command:
nginx -t
You should see the following output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Finally, restart the Nginx service to implement the changes:
systemctl restart nginx
Access Symfony5
Symfony4 is now installed, you can access it by visiting the URL http://your-server-ip on your web browser. You should see the Symfony 5 welcome page:
Congratulations! you have successfully installed Symfony5 on Debian 10 server. You can now host any PHP application using Symfony 5.
About Hitesh Jethva
Over 8 years of experience as a Linux system administrator. My skills include a depth knowledge of Redhat/Centos, Ubuntu Nginx and Apache, Mysql, Subversion, Linux, Ubuntu, web hosting, web server, Squid proxy, NFS, FTP, DNS, Samba, LDAP, OpenVPN, Haproxy, Amazon web services, WHMCS, OpenStack Cloud, Postfix Mail Server, Security etc.