LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-27-2012, 03:24 AM   #1
dreamcoder
LQ Newbie
 
Registered: Jul 2012
Distribution: Ubuntu 12.04
Posts: 22

Rep: Reputation: Disabled
PHP not working on Ubuntu 11.10 VPS with nginx


Hi Guys,

I have a Linux Virtual Private Server (VPS) with Ubuntu 11.10 Server on it.
So far I have successfully installed nginx 1.2.2 on it(thanks to my efforts and bathory's help).

And yesterday I installed PHP 5 on it but it doesn't seem to work, here are the steps I took to install PHP on my VPS:


1. First I dowloaded the php5-fpm module and some dependency packages, using:
Code:
aptitude install -y python-software-properties

add-apt-repository ppa:brianmercer/php && aptitude update

2. then I installed essential PHP modules using:
Code:
aptitude install -y php5-cli php5-common php5-suhosin

aptitude install -y php5-fpm php5-cgi

3. and then I installed some non-essential PHP modules using:
Code:
aptitude install -y php5-curl php5-gd php5-memcache php5-mysql php5-imagick imagemagick php-pear

sed -i "s/#/;/g" /etc/php5/conf.d/imagick.ini

4. after successfull installation I finally started PHP using the command:

Code:
/etc/init.d/php5-fpm start
Next up to test the php installation I saved: <?php phpinfo(); ?> into foo.php and
saved it to: /home/MyUsername/public_html/MyDomain.com/public/ and then I browsed to: http://MyvpsIPAddress/foo.php
but I didn't get the anticipated PHP info, instead there was a 404 not found error

Now when I run top on putty I can see php process running there



So I tried again but this time I put foo.php into the default nginx directory: /usr/local/nginx/html/ and then entered into my browser: http://MyvpsIPAddress/foo.php and yet again there was a 404 file not found error


So guys I can't figure out where the problem is ?
Guys I spent my entire day on it but to no use
Please help me out


Thanks a lot
 
Old 07-27-2012, 03:40 AM   #2
rosehosting.com
Member
 
Registered: Jun 2012
Location: Missouri, USA
Posts: 236

Rep: Reputation: 64
Did you create a vhost directive for your nginx to pass php requests to the php server either at localhost or through a socket?

here's an excerpt of what I have in the '/etc/nginx/sites-enabled/example-vhost' configuration file:

Code:
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;
}
hope that helps
 
1 members found this post helpful.
Old 07-27-2012, 04:07 AM   #3
dreamcoder
LQ Newbie
 
Registered: Jul 2012
Distribution: Ubuntu 12.04
Posts: 22

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rosehosting.com View Post
Did you create a vhost directive for your nginx to pass php requests to the php server either at localhost or through a socket?
Thanks for your response bro, I did create nginx virtual host file structure & symlinks at the path: /usr/local/nginx/sites-available/default which contains:

Code:
server  {
            listen       80;
            server_name  localhost;

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

            # redirect server error pages to the static page /50x.html
            error_page   500 502 503 504  /50x.html;
            location = /50x.html
            		   {
            			root   html;
            		   }
		}
and I've enabled it by using:

Code:
sudo ln -s /usr/local/nginx/sites-available/default /usr/local/nginx/sites-enabled/default
so will it be able to pass the php requests to the php server ?
 
Old 07-27-2012, 04:23 AM   #4
rosehosting.com
Member
 
Registered: Jun 2012
Location: Missouri, USA
Posts: 236

Rep: Reputation: 64
Quote:
Originally Posted by dreamcoder View Post
..so will it be able to pass the php requests to the php server ?
using the configuration you provided, php will not work. you need to add the snippet I posted in the previous reply. also, you may want to specify your:

Code:
root /path/to/public_html;
access_log /path/to/logs/access.log;
error_log /path/to/logs/error.log;
in the vhost configuration file as well. make sure you pass the requests to the port/socket where php-fpm is listening on. //'fastcgi_pass'.
 
1 members found this post helpful.
Old 07-28-2012, 12:05 PM   #5
dreamcoder
LQ Newbie
 
Registered: Jul 2012
Distribution: Ubuntu 12.04
Posts: 22

Original Poster
Rep: Reputation: Disabled
hey bro you're right, the prob was with the way I was configuring virtual host, so far what I have been doing is just copying down the virtual host config given on some or the other blog/wiki/site.....

I really don't understand how to configure the virtual host

Actually I want to first configure my VPS to install wordpress on my VPS's IP Address and then I'll update the dns of my domain to resolve it to my VPS's IP Addr.

So can you please point me to some tut or guide to learn to configure nginx virtual host so that I can install wordpress on my VPS IP

right now I have reinstalled Ubuntu 11.10 on my VPS

Thanks a lot

Last edited by dreamcoder; 07-28-2012 at 12:07 PM.
 
  


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
[SOLVED] Problem in starting nginx on Ubuntu 11.10 VPS dreamcoder Linux - Server 6 07-25-2012 03:05 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: Installing Nginx With PHP 5.3 And PHP-FPM On Ubuntu Lucid Lynx (10.04) LXer Syndicated Linux News 0 06-14-2010 11:42 PM
LXer: Installing PHP 5.3, Nginx And PHP-fpm On Ubuntu/Debian LXer Syndicated Linux News 0 02-10-2010 05:40 PM

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

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

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