From baafdbaeec94a65740afc9c1de6b3d168808c307 Mon Sep 17 00:00:00 2001 From: Professor <81946811+alinuxist@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:29:16 +0330 Subject: [PATCH] HowToCreateLaravelOnNginx --- LaravelOnNginx/LaravelOnNginx | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 LaravelOnNginx/LaravelOnNginx diff --git a/LaravelOnNginx/LaravelOnNginx b/LaravelOnNginx/LaravelOnNginx new file mode 100644 index 0000000..7fdb347 --- /dev/null +++ b/LaravelOnNginx/LaravelOnNginx @@ -0,0 +1,83 @@ +Sure! Here's a step-by-step guide on how to deploy Laravel on Nginx: + +1. Install Nginx: + - Update the package list: `sudo apt update` + - Install Nginx: `sudo apt install nginx` + +2. Configure Nginx: + - Open the default Nginx configuration file: `sudo nano /etc/nginx/sites-available/default` + - Replace the existing content with the following configuration: + + ``` + server { + listen 80; + server_name your_domain.com; + root /var/www/html/your_laravel_project/public; + + index index.php index.html index.htm; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ \.php$ { + include snippets/fastcgi-php.conf; + fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # Adjust version if needed + } + + location ~ /\.ht { + deny all; + } + } + ``` + +3. Save and close the file. + +4. Test the Nginx configuration for syntax errors: `sudo nginx -t` + +5. If there are no errors, restart Nginx to apply the changes: `sudo systemctl restart nginx` + +6. Install PHP and required extensions: + - Add the Ondřej Surý PPA repository: `sudo add-apt-repository ppa:ondrej/php` + - Update the package list again: `sudo apt update` + - Install PHP and required extensions (adjust version if needed): + ``` + sudo apt install php7.4-fpm php7.4-mbstring php7.4-xml php7.4-zip php7.4-mysql php7.4-curl php7.4-gd + ``` + +7. Install Composer: + - Download and install Composer globally: + ``` + curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer + ``` + +8. Clone or upload your Laravel project to `/var/www/html/your_laravel_project` directory. + +9. Set appropriate permissions for Laravel directories: + ``` + cd /var/www/html/your_laravel_project + sudo chown -R www-data:www-data storage bootstrap/cache + sudo chmod -R 775 storage bootstrap/cache + ``` + +10. Install project dependencies using Composer: + ``` + cd /var/www/html/your_laravel_project + composer install --no-dev --optimize-autoloader + ``` + +11. Generate an application key for Laravel: + ``` + cd /var/www/html/your_laravel_project + php artisan key:generate + ``` + +12. Restart PHP-FPM service to apply changes: `sudo systemctl restart php7.x-fpm` (replace x with your PHP version) + +That's it! Your Laravel application should now be deployed on Nginx successfully. + +Note: Make sure to replace "your_domain.com" with your actual domain name or IP address in step 2, and adjust any other configurations as per your specific requirements. + + +Daily quota: 2/3 +ENG | ES | عربي | 中文 | فارسی