Back to the list of posts

Setting up a server on Ubuntu to deploy a project on PHP-FPM Laravel Nginx

In order to successfully deploy a project on PHP-FPM Laravel Nginx, you need to properly configure the server on Ubuntu. In this article, we'll walk through the necessary steps and provide code examples to help you with the setup.

Step 1: Install required packages

Before installing PHP-FPM, Laravel and Nginx on the server, make sure that all required packages are installed. To do this, run the following command:

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install -y nginx php-fpm php-mysql php-mbstring git unzip

Step 2: Installing Laravel

After installing all the necessary packages, you need to install Laravel. To do this, run the following commands:

cd /var/www
sudo git clone https://github.com/laravel/laravel.git
cd /var/www/laravel
sudo composer install
sudo chown -R www-data:www-data /var/www/laravel/storage
sudo chmod -R 777 /var/www/laravel/storage
php artisan storage:link

Step 3: Setting up Nginx

Once Laravel is installed, the next step is to set up Nginx. To do this, edit the Nginx configuration file:

sudo nano /etc/nginx/sites-available/default

Replace the contents of the file with the following:

server {
     listen 80 default_server;
     listen [::]:80 default_server;

     root /var/www/laravel/public;
     index index.php index.html index.htm;

     server_name_;

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

     location ~ \\.php$ {
         try_files $uri /index.php =404;
         fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
     }
}

Don't forget to save the file and restart Nginx:

sudo systemctl restart nginx

Step 4: Check

After finishing the server setup, you can check if Laravel is running on the server. To do this, go to the address of your server in the browser. If you see a standard Laravel page, then everything is set up correctly.

Conclusion

In this article, we've covered the basic steps for setting up a server on Ubuntu to deploy a PHP-FPM Laravel Nginx project. You can use the above code to set up your server. Happy project deployment!

#DevOps #Laravel

Back to the list of posts Next post

menuclose

start a project

Заявка отправлена

Спасибо! Заявка отправлена. Свяжемся с вами в течении часа!