1

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

2 Answers 2

4

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!

1
  • Thanks, so much simpler than the tutorials I went through. Worked perfectly. Dec 12, 2013 at 16:05
1

Regarding testing the installation with phpinfo(), I recommend you use <?php for the opening bracket, because <? might not always work depending on how your php comes configured by default.

Make sure that the 'root' specifier is directly under 'server', as it is under the first 'location' in the default config.

I also had to modify /php/php.ini value for the specifier open_basedir to include the path to the root of the website.

This is on Arch Linux with php 5.5.13-1, php-fpm 5.5.13-1, and nginx 1.6.0-4.

My nginx config:

server {
    listen       80;

    server_name  sitename.domain;

    error_log    /var/log/nginx/error.log info;

    root   /srv/www/sitename;

    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        fastcgi.conf;
    }
}

My /etc/php/php.ini:

...
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/srv/www/
...

And when testing with a web browser, make sure to not reload from the browser cache each time you attempt to reload the URL to the php file, or the browser will keep thinking your php file is a plain stored resource and will keep trying to save it like a regular file download. This can happen by default on Chrome/Chromium 34 unless you have the DevTools open, and with the setting "Disable cache (while DevTools is open)" enabled. In my experience Firefox 24.5 worked better for testing getting the php enabled.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .