Linux – Can’t setup Nginx with PHP on Arch linux

arch linuxnginxPHP

I have tried to set up a LEMP server (Nginx, PHP, MySQL) on Arch Linux for a while, and have tried a few different online tutorials.
Most recently I tried: http://www.adminempire.com/how-to-insta … mysql-php/.

This tut asks me to create a seperate php.conf file in /etc/nginx/ and add:

location ~ \.(php|html|htm)$ {
  try_files      $uri = 404;
  fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
  fastcgi_index  index.php;
  include        fastcgi.conf;
}

then add to /etc/nginx/nginx.conf, iside the server class : include php.copf;

first I goto http://localhost, to test to make sure Nginx is running, and then I test http://localhost/phpinfo.php and I get a 404 error, I have restrted nginx (with no errors), and restarted php-fpm ( I even restarted my system). still getting the 404.

The tutorial said to put a phpinfo.php file /srv/http/phpinfo.php, but upon looking at nginx.conf I see:

location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
}

So I tried in /usr/share/nginx/html/phpinfo.php, and still get a 404

Best Answer

In your /srv/http directory, create a phpinfo.php file which contains

<? phpinfo(); ?>

Then modify your /etc/nginx/nginx.conf file

server {
    listen       80;
    server_name  localhost;
    root         /srv/http;

    location / {
        index  index.html index.htm index.php;
    }

    location ~ \.php$ {
        fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi.conf;
    }
}

Finally, restart nginx and php-fpm and try the following url http://localhost/phpinfo.php And it should work!

Related Question