Symfony is a free, open-source, popular PHP framework with MVC architecture used to build web services, APIs, microservices, and high-performance, complex web applications. Symfony is compatible with other database systems and gives you full control over configuration. It comes with a set of reusable components and a user-friendly web interface, and its flexibility and high performance make it a top choice for developing an enterprise application.
In this tutorial, we will learn how to install the Symfony framework on CentOS 8 server.
- A fresh CentOS 8 VPS on the Atlantic.net Cloud Platform.
- A valid domain name pointed to your IP address. In this tutorial, we will use symfony.example.com.
- A root password configured on your server.
Note: You can refer to the Atlantic DNS Guide to manage the DNS records.
Step 1 – Create Atlantic.Net Cloud Server
First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing CentOS 8 as the operating system with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.
Once you are logged into your CentOS 8 server, run the following command to update your base system with the latest available packages.
dnf update -y
Step 2 – Install LAMP Server
First, you will need to install the Apache, MariaDB, PHP and other required PHP extensions in your server. You can install all of them with the following command:
dnf install httpd mariadb-server php php-cli php-common php-spl php-hash php-ctype php-json php-mbstring php-zip php-gd php-curl php-mysqli php-xml php-gmp php-intl php-xmlrpc php-bcmath php-soap php-ldap unzip -y
Once all the packages are installed, start the Apache and MariaDB service and enable them to start after system reboot with the following command:
systemctl start httpd
systemctl enable httpd
systemctl start mariadb
systemctl enable mariadb
Once you are done, you can proceed to the next step.
Step 3 – Secure MariaDB Database
By default, MariaDB is not secured, but you can secure the MariaDB and set a MariaDB root password using the following command:
Answer all the questions as shown below:
Enter current password for root (enter for none): Just Press Enter
Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
Once you are finished, you can proceed to the next step.
Step 4 – Install Symfony
Before installing Symfony, you will need to install Composer in your system. Composer is a dependency manager for PHP that can be used to install PHP dependencies while building the project.
You can install Composer with the following command:
wget https://getcomposer.org/installer -O composer-installer.php
php composer-installer.php --filename=composer --install-dir=/usr/local/bin
Once installed, you should get the following output:
All settings correct for using Composer
Composer (version 1.9.3) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer
Next, change the directory to the /var/www/html and create a new Symfony project with the following command:
composer create-project symfony/website-skeleton symfony5
Next, give proper permissions to the symfony5 directory using the following command:
chown -R apache:apache /var/www/html/symfony5
chmod -R 755 /var/www/html/symfony5
Step 5 – Start Symfony in Development Mode
You can now start Symfony in development mode using the following command:
php -S 0.0.0.0:8000 -t public
You should see the following output:
PHP 7.2.11 Development Server started at Thu Feb 6 08:56:29 2020
Listening on http://0.0.0.0:8000
Document root is /var/www/html/symfony5/public
Press Ctrl-C to quit.
Symfony web server is now started and listening on port 8000. You can access it using the URL http://your-server-ip:8000. You should see the following screen:
You can stop the Symfony web server by pressing CTRL+C on your terminal interface.
Step 6 – Configure Apache for Symfony
Next, you will need to create a new Apache virtual host configuration file for Symfony. You can create it with the following command:
Add the following lines:
ServerAdmin [email protected]
Allow from All
CustomLog "/var/log/httpd/example.com-access_log" combined
Save and close the file when you are finished. Then, restart the Apache service to apply the changes:
systemctl restart httpd
Step 7 – Configure Firewall
If the firewalld service is enabled in your system, you will need to allow HTTP/HTTPS port through firewalld.
First, check the firewalld service using the following command:
systemctl status firewalld
You should see that firewalld service is not running:
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
You can start the firewalld service and enable it to start after system reboot with the following command:
systemctl start firewalld
systemctl enable firewalld
Next, allow HTTP and HTTPS port through firewalld with the following command:
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
Next, reload the firewalld to apply the changes:
Step 8 – Access Symfony
Now, open your web browser and type the URL http://symfony.example.com. You will be redirected to the Symfony default dashboard as shown in the following screen:
Congratulations! you have successfully installed Symfony 5 on CentOS 8 server. You can now start building brilliant applications with Symfony. Get started on Symfony today on a VPS Hosting account from Atlantic.Net!