Installing PHP

As mentioned before, nginx simply handles web requests as quickly as possible. To
get PHP to work with nginx, we need to install an interface called FastCGI. This will
allow nginx to send requests to PHP and receive and display the response. To help
improve PHP performance, we will also install a PHP extension called Alternative
PHP Cache (APC). It is much faster and uses fewer resources than the standard
PHP caching.

After installing, PHP should be running, but we will restart it to make sure all the
extensions were loaded correctly.

apt-get install php5-fpm php-apc
service php5-frmp restart

We need to update the nginx virtual host's configuration file now to tell nginx how to
handle PHP requests. This time, you need to restart nginx after you save the file.
server {
listen 80;
root /var/www/local/web;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}

Create a new file named info.php in /var/www /local/web/ and add these simple
lines to it:
<?php
phpinfo();
?>
Save the file and navigate to it in your browser.

You should see something similar to the preceding screenshot. This means that PHP
is configured and you can use any PHP web application or write your own PHP
scripts now.

No comments:

Post a Comment