Search code examples
phpnginxtor

Enabling php in Nginx


I want to open a white hat forum on a .onion site. I followed this for helping me with the setup. And it worked, however when I create a .php it cannot read the file, and offers to download the .php instead of reading it. So php is not enabled and I cant find any working articles on google, and its almost driven me crazy, so i hope you can help me

Here is my setup:

I'm running a raspberry pi, with a ethernet cable.

I'm using raspbian, very similar to debian.

Its running at port 9070 instead of 9000.

I can provide ssh for a trusted member if you can help me.

If you want to see what happens, you can do to (removed) and in the "test" folder there is a index.php file

So how can i resolve this php problem?

Note: im very new to linux, so please be fair to me, thanks.


Solution

  • The fact that it isn't serving as PHP and instead a download means something isn't quite right about the fpm and/or nginx proxy configuration.

    Key things to check for are:

    • Check your listen directive in your php fpm pool. The pool will either listen on a TCP socket (listen 127.0.0.1:9000) or a Unix socket (listen /var/run/php5-fpm.sock)
    • Determine that fpm is listening properly and the tcp socket or domain socket are up
    • Make sure your vhost in nginx is properly passing PHP requests to the right socket or tcp port. This will look something like:
    location ~ \.php$ {
      root           /path/to/docroot;
      fastcgi_pass   127.0.0.1:9000;  # If using TCP in php-fpm
      # OR
      fastcgi_pass   unix:/var/run/php5-fpm.sock;  # If using unix socket
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
      include        fastcgi_params;
    }
    

    And make sure that location block is in the appropriate vhost in nginx, otherwise it will not work.

    Sites that are going to be hammered and very busy will benefit from using a TCP socket instead of a Unix socket but this only matters for sites where you expect a lot of concurrent PHP requests.

    Hope that helps.