Laravel nginx: Difference between revisions

From AWVVO
Jump to navigationJump to search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Create config file ==
== install PHP fpm ==
<syntaxhighlight lang="bash" copy line highlight="0">
sudo apt install php8.3-fpm
</syntaxhighlight>
 
== Create nginx config file ==
<syntaxhighlight lang="nginx" copy line highlight="0">
<syntaxhighlight lang="nginx" copy line highlight="0">
server {
server {
Line 15: Line 20:
     location ~ \.php$ {
     location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/run/php/php8.2-fpm.sock; # Adjust version if needed
         fastcgi_pass unix:/run/php/php8.3-fpm.sock; # Adjust version if needed
         fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
         fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
         include fastcgi_params;
         include fastcgi_params;
Line 28: Line 33:
}
}


</syntaxhighlight>
== Enable nginx config ==
<syntaxhighlight lang="bash" copy line highlight="0">
sudo chown -R www-data:www-data /home/ubuntu/dev/awvvo-server
sudo chmod -R 755 /home/ubuntu/dev/awvvo-server
sudo chmod o+x /home
sudo chmod o+x /home/ubuntu
sudo chmod o+x /home/ubuntu/dev
sudo ln -s /etc/nginx/sites-available/your-app /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 12:44, 29 March 2025

install PHP fpm

sudo apt install php8.3-fpm

Create nginx config file

server {
    listen 80;
    server_name your-domain.com;

    root /var/www/your-laravel-app/public;

    index index.php index.html;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock; # Adjust version if needed
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    access_log /var/log/nginx/your-app.access.log;
    error_log /var/log/nginx/your-app.error.log;
}

Enable nginx config

sudo chown -R www-data:www-data /home/ubuntu/dev/awvvo-server
sudo chmod -R 755 /home/ubuntu/dev/awvvo-server

sudo chmod o+x /home
sudo chmod o+x /home/ubuntu
sudo chmod o+x /home/ubuntu/dev

sudo ln -s /etc/nginx/sites-available/your-app /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx