nginx.oldfords.cz

  • Öka teckenstorlek
  • Standard teckenstorlek
  • Minska teckenstorlek
Home NGINX Setting Nginx, PHP Fastcgi and XCache on a new Ubuntu

Setting Nginx, PHP Fastcgi and XCache on a new Ubuntu

Skicka sidan Skriv ut PDF
There are no translations available.

  • Setup the new vps with nginx, php-fastcgi, etc as described later in the post
  • To verify the setup on new vps, edit the local host file depending upon your operating system
  • view plaincopy to clipboardprint?
    1. /private/etc/hosts (mac)
    2. /etc/hosts (ubuntu)
    3. C:\Windows\System32\drivers\etc\hosts (windows)

    Go ahead and add the following host entry:

    1. 99.198.122.216 nginx.oldfords.cz 

    where, 99.198.122.216 is my new vps ip address and abhinavsingh.com is a vhost configured to handle by nginx on my new vps

  • Now, whenever I visit http://nginx.oldfords.cz in my browser, my local machine will point it to my new vps box. However, all other visitors will still be served by apache on old vps.
  • After verifying the setup, I simply remove previously added host setting on my local box and update the DNS settings for my site at godaddy.

To start with, just add up the required host setting on your local system.

Installing Nginx and configuring vhosts:
Follow these steps to install nginx webserver:

  • Update and upgrade apt-get and install nginx
    1. sudo apt-get update
    2. sudo apt-get upgrade
    3. sudo apt-get install nginx
  • Configure vhost for nginx by creating a file /etc/nginx/sites-available/mysite.com as follows:
    1. server {
    2. listen   80;
    3. server_name  mysite.com;
    4. access_log  /var/log/nginx/mysite.access.log;
    5. root   /var/www/mysite;
    6. index  index.php index.html index.htm;
    7. location / {
    8. }
    9. }
  • Enable vhost by creating a symlink as follows:
    1. cd /etc/nginx/sites-enabled
    2. ln -s /etc/nginx/sites-available/mysite.com mysite.com
    3. sudo /etc/init.d/nginx restart
  • Assuming you have configured your local host file correctly, try visiting http://mysite.com and your browser will take it to the new vps

Setting up php-fastcgi and xcache:
Here are the steps to configure php-fastcgi and how to ensure php-fastcgi is up and running even after system reboot. We will also configure xcache for better performance.

  • sudo apt-get install php5-cgi php5-cli php5-xcache
  • Download php-fastcgi default config and place it at /etc/default/php-fastcgi
  • Download php-fastcgi init.d script and place it at /etc/init.d/php-fastcgi
  • Add php-fastcgi init.d as startup script
    1. update-rc.d -f php-fastcgi defaults
  • Update following fields inside /etc/php5/conf.d/xcache.ini:
    1. xcache.admin.user = "admin"
    2. xcache.admin.pass = "pass"
    3. xcache.size  =  128M
    4. xcache.count = 4

    xcache.count should ideally be equal to cat /proc/cpuinfo |grep -c processor

  • Setup xcache admin interface:
    1. cd /var/www
    2. ln -s /usr/share/xcache/admin xcache
  • Update /etc/php5/cgi/php.ini as per your requirements and start php-fastcgi process
    1. sudo /etc/init.d/php-fastcgi start
  • Visit xcache admin panel http://vps_ip_address/xcache

Stitching php-fastcgi and nginx vhosts:
Now lets enable php for vhosts configured with nginx:

  • Download nginx fastcgi param config file and place it at /etc/nginx/fastcgi.conf
  • Update /etc/nginx/sites-available/mysite.com with following config:
    1. location ~ \.php$ {
    2. fastcgi_pass    127.0.0.1:9000;
    3. fastcgi_index   index.php;
    4. fastcgi_param   SCRIPT_FILENAME /var/www/mysite$fastcgi_script_name;
    5. include /etc/nginx/fastcgi.conf;
    6. }
  • Restart nginx and we are done

Here we complete the vps setup and vhost configurations. Verify the new vps setup and once satisfied update site’s DNS settings.

Senast uppdaterad 2010-07-24 16:35