In this post I will try to provide the simple steps to install the another PHP framework Symfony with Nginx. Presently we have Symfony 6 with PHP 8.* versions. But when we have PHP 7.4 these steps will be useful to install the Symfony 5.

Install Symfony 5 with PHP 7.4 on Ubuntu with Nginx

Install Symfony 5 with PHP 7.4 on Ubuntu with Nginx

Step 1: Install the Symfony CLI

1
2
curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.deb.sh' | sudo -E bash
sudo apt install symfony-cli

Step 2: Install the composer

1
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer

We can install the application either from CLI or from the composer

Step 3: In the previous post I have provided how to install PHP and Nginx, Now go to document root

1
CD /var/www/html/

Step 4: Run the below command to install the Symfony app

1
sudo composer create-project symfony/skeleton symfony5app

When we run this command we will get the question
Continue as root/super user [yes]? then type yes and enter

final output of above command

1
2
3
4
5
6
7
8
9
10
11
Some files have been created and/or updated to configure your new packages.
Please review, edit and commit them: these files are yours.

 symfony/framework-bundle  instructions:

  * Run your application:
    1. Go to the project directory
    2. Create your code repository with the git init command
    3. Download the Symfony CLI at https://symfony.com/download to install a development web server

  * Read the documentation at https://symfony.com/doc

Step 5: Run the below commands to give the permissions to the folder

1
2
sudo chown -R www-data:www-data /var/www/html/symfony5app/
sudo chmod -R 755 /var/www/html/symfony5app/

Step 6: In the browser open the link

1
http://localhost/symfony5app/public/

Step 7: In the previous post, we have learn about virtual host in Nginx, add the below statement in the configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
server {
        listen 80;
        root /var/www/html/symfony5app/public;
        index index.php index.nginx-debian.html;
        server_name _;
       
        location ~* \.(?:manifest|appcache|html?|xml|json)$ {
                expires -1;
                # access_log logs/static.log; # I don't usually include a static log
       }

        location ~* \.(?:css|js)$ {
                try_files $uri =404;
                expires 1y;
                access_log off;
                add_header Cache-Control "public";
        }

    location ~ \.php$ {
           include snippets/fastcgi-php.conf;
           fastcgi_pass unix:/run/php/php7.4-fpm.sock;
         }

        location / {
           try_files $uri $uri/ /index.php?$args;
        }
}

Step 8: Restart the Nginx, then application will open when we open the below link

1
http://localhost/

Hope it will useful.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *