LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-30-2012, 02:52 PM   #1
dreamcoder
LQ Newbie
 
Registered: Jul 2012
Distribution: Ubuntu 12.04
Posts: 22

Rep: Reputation: Disabled
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
 
Old 07-30-2012, 05:00 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,165
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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
 
1 members found this post helpful.
Old 07-30-2012, 11:02 PM   #3
dreamcoder
LQ Newbie
 
Registered: Jul 2012
Distribution: Ubuntu 12.04
Posts: 22

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bathory View Post
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
 
Old 07-31-2012, 03:29 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,165
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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
 
1 members found this post helpful.
Old 07-31-2012, 04:27 AM   #5
dreamcoder
LQ Newbie
 
Registered: Jul 2012
Distribution: Ubuntu 12.04
Posts: 22

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bathory View Post
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
 
Old 07-31-2012, 07:31 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,165
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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

Last edited by bathory; 07-31-2012 at 08:59 AM.
 
Old 08-01-2012, 07:41 AM   #7
dreamcoder
LQ Newbie
 
Registered: Jul 2012
Distribution: Ubuntu 12.04
Posts: 22

Original Poster
Rep: Reputation: Disabled
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
 
Old 08-01-2012, 08:09 AM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,165
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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
 
1 members found this post helpful.
Old 08-02-2012, 08:46 AM   #9
dreamcoder
LQ Newbie
 
Registered: Jul 2012
Distribution: Ubuntu 12.04
Posts: 22

Original Poster
Rep: Reputation: Disabled
Thanks a lot bro

You're indeed very helpful
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How to Installing Nginx with PHP5-FastCGI and MySql Support on Ubuntu Server 12.04 LTS LXer Syndicated Linux News 0 06-15-2012 10:20 AM
nginx + php-fpm and nginx modules fantasygoat Linux - Server 0 06-09-2011 12:21 PM
Nginx experts help me-problem when using Nginx php-fpm !!! HuMan-BiEnG Linux - Server 2 04-17-2011 02:30 PM
NGINX with PHP-FPM vis NGINX with Spawn-FCGI WhisperiN Linux - Server 1 03-15-2011 06:39 PM
LXer: Drupal 6 Hosting With nginx And PHP-FastCGI On Ubuntu 9.10 LXer Syndicated Linux News 0 04-08-2010 02:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration