How to Install Nginx With PHP5 And MySQL On Ubuntu 11.10
Nginx is a free, open-source, high-performance HTTP server. Nginx is known for its stability, rich feature set, simple configuration, and low resource consumption. This tutorial shows how to install Nginx on an Ubuntu 11.10 with PHP5 support (through PHP-FPM) and MySQL support.
Installing MySQL 5:
First we will install the MySQL by issuing the following command.
[email protected]untu~/ $ sudo apt-get install mysql-server mysql-client
You will be asked to provide a password for MySQL user “root“. The same password will be valid for the user [email protected] as well as [email protected] .
New password for the MySQL “root” user: <– yourrootsqlpassword
Repeat password for the MySQL “root” user: <– yourrootsqlpassword
Nginx is already available in the Ubuntu Package, so issue the following command to install Nginx.
[email protected]~/ $ sudo apt-get install nginx
Start the Nginx after the installation.
[email protected]~/ $ sudo /etc/init.d/nginx start
Test Your Nginx installation by opening your web browser and Navigate to http://192.168.0.10. You will get the following web page saying “Welcome to Nginx!“.
The default nginx document root on Ubuntu 11.10 is /usr/share/nginx/www. The configuration files are under /etc/nginx directory.
Next is to install PHP5 through PHP-FPM (PHP-FPM (FastCGI Process Manager), it is an alternative PHP FastCGI implementation. it has some additional features useful for sites of any size, especially busier sites). Install it by issuing the following command.
[email protected]~/ $ sudo apt-get install php5-fpm
after the installation of PHP5 restart the Nginx server.
[email protected]~/ $ sudo /etc/init.d/nginx reload
For testing the PHP, Place one PHP file on to the default directory of the nginx
Step 1. In the terminal copy/paste the following line:
[email protected]~/ $ sudo vi /usr/share/nginx/html/info.php
This will open up a file called info.php.
Step 2. Copy/Paste this line into the info.php file:
<?php phpinfo(); ?>
Step 3. Save and close the file. use Esc + ;wq for saving the file.
Step 4. Now open you’re web browser and type the following into the web address:
The page look like below:
From the above screen shot , PHP5 is working, and it’s working through FPM/FastCGI, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. You will find that MySQL is not listed there which means we don’t have MySQL support in PHP5 yet. we need to install the MySQL support on PHP 5.
MySQL Support In PHP5:
To get the MySQL support in PHP5 we can install the php5-mysql package.
[email protected]~/ $ sudo apt-get install php5-mysql
Once installed, restart the PHP-FPM.
[email protected]~/ $ sudo /etc/init.d/php5-fpm restart
Now refresh the Web browser that already you have opened for testing PHP.
You will find the MySQL modules list that are not listed before the installation of support package.