Installing Laravel 5.1 with Nginx

February 11, 2016 2.5k views
Nginx PHP Deployment PHP Frameworks Ubuntu

Hi Guys, I've been trying to install laravel 5.1 with Nginx, I've installed the php-fpm, is currently running on /var/run/php5-fpm.sock.

I've created my nginx config as follow:

server {
        listen   80;

        root /var/www/;
        index index.php index.html index.htm;
        location / {
             try_files $uri $uri/ /index.php$is_args$args;

        # pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
        location ~ \.php$ {
                try_files $uri /index.php =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

However... when I try access my site I'm getting this error:

2016/02/11 16:25:04 [crit] 6465#0: *48 connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream, client: XXX.XXX.XXX.XXX, server:, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: ""

Seems like is a problem with user permissions, can anyone help?


1 Answer

Run 2 the following command:
chown -R www-data:www-data /path/to/laravel/public/forder

chmod +x /var/run/php5-fpm.sock

If you see 502 Bad GateWay error, open /etc/nginx/nginx.conf, at the top of file edit user to www-data, if don't exist add this line to top of file
user www-data;
Save and reload Nginx: nginx -s reload
Your Laravel Framework should be run

  • Thanks man, this help. However I also needed to change the owner and group of the php socket.

    $ sudo chown www-data:www-data /var/run/php5-fpm.sock

    After this, my app worked!


Have another answer? Share your knowledge.