Activities

November 2014
M T W T F S S
« Oct   Dec »
 12
3456789
10111213141516
17181920212223
24252627282930

Ngnix webserver :- Php – CodeIgniter hosting

I had to deploy one php site on Rails server to setup admin UI for a mobile application. This is the first time I’m using Ngnix for hosting PHP application.

After few usual Google I got the fix. Adding this line try_files $uri $uri/ /index.php; in virtual hosting area did the trick.

How do I install Ngnix server using yum

Create repository file on yum config folder (/etc/yum.repos.d/nginx.repo) and add the following lines. Or you can download the respective package file from here http://nginx.org/packages/

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

[root@ph-web01 ~]# yum clean all
[root@ph-web01 ~]# yum install nginx

2. Installing php-fpm
PHP-FPM is a FastCGI Process Manager which will compile php page much faster. We can start and stop the CGI process activity using this module. This fpm has
a. advanced process management with graceful stop/start.
b. stdout and stderr logging;
c. emergency restart in case of accidental opcode cache destruction.
d. basic SAPI status info (similar to Apache mod_status)

[root@ph-web01 ~]# yum install php5-fpm.

Now you need to set the php-fpm Lister to socket rather than using port. Add the line “listen = /var/run/php-fpm/php-fpm.sock” on /etc/php-fpm.d/www.conf

[root@ph-web01 ~]# cat  /etc/php-fpm.d/www.conf | grep "listen"
#listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock

Restart both php-fpm and nginx server

[root@ph-web01 ~]#service nginx restart
[root@ph-web01 ~]#service php-fpm restart

Virtaul host entry for the CodeIgniter site is as showing below,

server {
    listen       80;
    server_name  admin.domain.com;
      autoindex on;
      index index.php;

    location / {
        root    /home/adminapp/public_html;
        index  index.html index.php;
         try_files $uri $uri/ /index.php;
         allow all;
#       try_files $uri $uri/ /index.php?$args;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
location ~ \.php$ {
 root            /home/adminapp/public_html;
 fastcgi_split_path_info ^(.+\.php)(/.+)$;
 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;
 }

}

php-fpm

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>