LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Nginx not passing the PHP scripts to FastCGI server listening on 127.0.0.1:9000 (http://www.linuxquestions.org/questions/linux-server-73/nginx-not-passing-the-php-scripts-to-fastcgi-server-listening-on-127-0-0-1-9000-a-4175419417/)

dreamcoder 07-30-2012 02:52 PM

Nginx not passing the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 
Hi Guys,

I have installed nginx 1.2.2, php and mysql on my Ubuntu 11.10 VPS

To install wordpress on my vps I made the following configurations:

1. created a directory for my wordpress site:
Code:

/home/username/public_html/mysite
2. created a virtual host file for my wordpress site at: /usr/local/nginx/sites-available/mysite, with the following contents:
Code:

server {
            listen  SERVER_NAME:80;
            server_name SERVER_NAME;
            access_log /home/username/public_html/mysite/logs/access.log;
            error_log  /home/username/public_html/mysite/logs/error.log;

            location /  {
                        root  /home/username/public_html/mysite/;
                        index  index.php index.html;
                        }

            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
          location ~ \.php$
{
    try_files $uri =404;
    fastcgi_pass 127.0.0.1:9000;
    #fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_param  REQUEST_URI    $request_uri;
    fastcgi_param  DOCUMENT_URI  $document_uri;
    fastcgi_param  DOCUMENT_ROOT  $document_root;
    fastcgi_param  REMOTE_ADDR    $remote_addr;
    fastcgi_param  REMOTE_PORT    $remote_port;
    fastcgi_param  SERVER_ADDR    $server_addr;
    fastcgi_param  SERVER_PORT    $server_port;
    fastcgi_param  SERVER_NAME    $server_name;
    fastcgi_param  QUERY_STRING  $query_string;
    fastcgi_param  REQUEST_METHOD $request_method;
    fastcgi_param  CONTENT_TYPE  $content_type;
    fastcgi_param  CONTENT_LENGTH $content_length;

    #Prevent php version info leakage
    fastcgi_hide_header X-Powered-By;
}
      }


3. And added symlink using:
Code:

sudo ln -s /usr/local/nginx/sites-available/mysite /usr/local/nginx/sites-enabled/mysite
4. restarted the nginx server using: service nginx restart

5. To test the proper functioning, I created two files in the root dir (/home/username/public_html/mysite/)

foo.html and bar.php

Now when I enter in the browser http://MyVPSIP/foo.html it works perfectly but when I enter http://MyVPSIP/bar.php instead of the php output I get a 404 Not Found Error

This means that nginx is not passing the PHP scripts to FastCGI server listening on 127.0.0.1:9000

Whereas I don't get this problem when working with php scripts in the nginx web root directory



I don't understand why I'm getting this problem

Please help me out

Thanks a lot :)

bathory 07-30-2012 05:00 PM

Hi,

You don't need a location for the vhost. Use:
Code:

server {
            listen  SERVER_NAME:80;
            server_name SERVER_NAME;
            access_log /home/username/public_html/mysite/logs/access.log;
            error_log  /home/username/public_html/mysite/logs/error.log;
            root  /home/username/public_html/mysite/;
            index  index.php index.html;
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
          location ~ \.php$
{
 <- SNIP Put the php-frm stuff here ->
}
      }

Regards

dreamcoder 07-30-2012 11:02 PM

Quote:

Originally Posted by bathory (Post 4741646)
Hi,

You don't need a location for the vhost. Use:....

Regards


Thanks bathory once again for your reponse :)

But I didn't get you regarding the "php-frm stuff", can you please be a bit more elaborative

Thanks :)

bathory 07-31-2012 03:29 AM

Hi,

Quote:

But I didn't get you regarding the "php-frm stuff", can you please be a bit more elaborative
I mean you have to add the fastcgi directives as in your 1st post, that I thought it was useless to write again. Anyway this is the complete snippet:
Code:

server {
            listen  SERVER_NAME:80;
            server_name SERVER_NAME;
            access_log /home/username/public_html/mysite/logs/access.log;
            error_log  /home/username/public_html/mysite/logs/error.log;
            root  /home/username/public_html/mysite/;
            index  index.php index.html;
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
          location ~ \.php$
{
    try_files $uri =404;
    fastcgi_pass 127.0.0.1:9000;
    #fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_param  REQUEST_URI    $request_uri;
    fastcgi_param  DOCUMENT_URI  $document_uri;
    fastcgi_param  DOCUMENT_ROOT  $document_root;
    fastcgi_param  REMOTE_ADDR    $remote_addr;
    fastcgi_param  REMOTE_PORT    $remote_port;
    fastcgi_param  SERVER_ADDR    $server_addr;
    fastcgi_param  SERVER_PORT    $server_port;
    fastcgi_param  SERVER_NAME    $server_name;
    fastcgi_param  QUERY_STRING  $query_string;
    fastcgi_param  REQUEST_METHOD $request_method;
    fastcgi_param  CONTENT_TYPE  $content_type;
    fastcgi_param  CONTENT_LENGTH $content_length;

    #Prevent php version info leakage
    fastcgi_hide_header X-Powered-By;
}
      }

BTW, I guess that with SERVER_NAME you mean the actual vhost name, so you can omit it from the listen directive.

Regards

dreamcoder 07-31-2012 04:27 AM

Quote:

Originally Posted by bathory (Post 4741984)
Hi,

I mean you have to add the fastcgi directives as in your 1st post, that I thought it was useless to write again. Anyway this is the complete snippet:

BTW, I guess that with SERVER_NAME you mean the actual vhost name, so you can omit it from the listen directive.

Regards

Thanks a lot bro, it worked, Once again YOU ROCK !!

sorry to make you repeat mate and I've omitted the vhost name from the listen directive and it's working perfectly :)


Now that everything is working fine, if I download (via ftp ) my wordpress site from my shared hosting account and ftp it to /home/username/public_html/mysite/, by doing so will my wordpress site work on vps also ?

Thanks :)

bathory 07-31-2012 07:31 AM

Quote:

Now that everything is working fine, if I download (via ftp ) my wordpress site from my shared hosting account and ftp it to /home/username/public_html/mysite/, by doing so will my wordpress site work on vps also ?
Normally it should work.
The only problem you may encounter could be the usage of .htaccess files (if you ran your site on apache on the previous hosting provider), that you need to transform in nginx configuration directives. There are lot's of examples on the net about this.
Anyway you can copy your site on nginx, do your tests and go online once ready.

Regards

dreamcoder 08-01-2012 07:41 AM

Thanks Man, I copied my wordpress site 'as it is' to my vps at /home/username/public_html/mysite and when I enter in the browser http://MyVPSIP/wp-admin I get nothing - just a blank page
At the moment I'm working on configuring my site to work on nginx(LEMP stack) because my shared hosting is having CentOS 5.5 LAMP stack,
I think migrating my site from apache to nginx will take some time

Also, on my shared hosting I have been accessing my emails using http://MYDomain.com/webmail, I want to migrate the emails also to my vps, so do I have to install some mail client on my vps ??

Thanks :)

bathory 08-01-2012 08:09 AM

Quote:

I copied my wordpress site 'as it is' to my vps at /home/username/public_html/mysite and when I enter in the browser http://MyVPSIP/wp-admin I get nothing - just a blank page
A blank page means some php error. Maybe you can find it looking at the logs.
Anyway, as I've told, if you're migrating from apache then you should take care of the stuff in .htaccess files. See this for help, or use google to find complete nginx/wordpress configuration

Quote:

Also, on my shared hosting I have been accessing my emails using http://MYDomain.com/webmail, I want to migrate the emails also to my vps, so do I have to install some mail client on my vps ??
Sure. You'll need an imap/pop3 server and some webmail software. Not to mention the mta (mailserver). Check with your previous provider and use the same programs if possible

Regards

dreamcoder 08-02-2012 08:46 AM

Thanks a lot bro :)

You're indeed very helpful


All times are GMT -5. The time now is 05:02 PM.