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.
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
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
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
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.
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!
menuclose
Спасибо! Заявка отправлена. Свяжемся с вами в течении часа!