0

I want to deploy simple laravel app on nginx ubuntu 16.04 server .

I have put my app inside /var/www/html folder

on my server , i have already setup php and mysql .

i have added below code in my /etc/nginx/sites-enabled/myapp.com

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

root /var/www/html/MyApp/public;
index index.php index.html index.htm index.nginx-debian.html;
charset utf-8;

server_name myapp.com;
error_log  /var/log/nginx/myapp.com.log error;

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

 location ~ \.php$ {
     try_files $uri =404;
     fastcgi_split_path_info ^(.+\.php)(/.+)$;
     fastcgi_pass unix:/run/php/php7.0-fpm.sock;
     fastcgi_index index.php;
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     include fastcgi_params;
}

  location ~ /\.ht {
    deny  all;
  }

}

but instead of running app , it is downloading file , so i have searched and found stackoverflow link :

Nginx serves .php files as downloads, instead of executing them

But this in Not working in my case .

I have not much idea about nginx , please help me .

Saurabh Mistry
  • 12,833
  • 5
  • 50
  • 71

1 Answers1

0

nginx will show error 502 (bad gateway) when php-fpm is not running or it can't find the socket.

In your case, I think the problem is on this line:

fastcgi_pass unix:/run/php/php7.0.22-fpm.sock;

try changing it to

fastcgi_pass unix:/run/php/php7.0-fpm.sock;

save and reload or restart nginx.