NGINX–PHP5.4–MYSQL INSTALLATION

NGINX–PHP5.4–MYSQL INSTALLATION

We have covered NGINX  installation in last article  http://how2install.in/Nginx-installation

 PHP?

PHP (now stands for PHP: Hypertext Preprocessor) is Server side scripting language which is generally used for web development applications. PHP is open source languages but it release under PHP License not GPL. PHP is very power full and light-weighted language for web development business and today more than 250 million website running on PHP with Apache & Ningx web server & MySql for database. The short form we generally used LAMP (Linux,apache,mysql,php) and second one is LEMP (Linux,Nginx,Mysql,php).PHP run on almost every kind of OS but mostly its run on LINUX based server for better performance.

 

Mysql?

Mysql is the world most famous database & it’s open source software so you use it without pay anything, but only Mysql Community Editions is freely available for download. The Enterprise editions of Mysql is not available free of cost, so if you want enterprise edition and its support then you have to pay some amount.

Mysql is the first choice of database for web based applications. It’s mostly used with LAMP and LEMP stack.

 

How to install Mysql-5.5.31?

By using Ubuntu/Debain default repository we will install Mysql-5.5.31. It’s very simple to install Mysql on Linux in just simple one line command. Open the root terminal and follow the below process

root@test:~# apt-get install mysql-server mysql-client

Prompt ask you to enter the password for Mysql root user with confirmationAfter installation you must restart Mysql services.

root@test:~# service mysql restart

mysql stop/waiting
mysql start/running, process 9098

root@test:~#

Mysql CLI mode login by root user. It will ask you to enter password for authentication, enter the same password which you have set during installation time.

root@test:~# service mysql restart

mysql stop/waiting
mysql start/running, process 9098

root@test:~#

Mysql CLI mode login by root user. It will ask you to enter password for authentication, enter the same password which you have set during installation time.

root@test:~# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.5.31-0ubuntu0.12.04.2 (Ubuntu)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

 How to Install PHP-5.4?

The Nginx-1.4.1 and PHP-5.4 in not available through OS default repository. So you need to install additional PPA repository. Nginx working with PHP-FPM (PHP-FastCGI Processor Manager is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.)

root@test:~# add-apt-repository ppa:ondrej/php5

root@test:~# apt-get update

root@test:~# apt-get install php5-fpm php5-cli php5-cgi php5-mysql php5-curl php5-cli php5-common php5-geoip php5-mcrypt php5-memcache php-xml-serializer php-xml-parser php-soap php5-ldap php5-gd php5-imap

Check PHP version?

We have installed PHP with various modules. Before configuration we must check the PHP version which we have installed in system.

root@test:~# php -v

PHP 5.4.15-1~precise+1 (cli) (built: May 13 2013 16:00:00)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

root@test:~#

 How to configure NGINX to server PHP pages?

Default configuration of Nginx serve only .html pages, now for PHP pages we need to configure Nginx default host configure file. 

root@test:~# vim /etc/nginx/sites-available/default

#Modify 25 number line same as below
index index.php index.html index.htm;

#Uncomment 62 69 70 71 72 number line same as below

location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

Now start Nginx & php5-fpm services:—

root@test:~# /etc/init.d/php5-fpm restart
* Restarting PHP5 FastCGI Process Manager php5-fpm [ OK ]
root@test:~# /etc/init.d/nginx restart
* Restarting nginx nginx [ OK ]
root@test:~#

Now put the .php page in webroot directory of Nginx:—

Under webroot directory I going to create info.php page which provide us php  packages and modules information. 

root@test:~# cd /usr/share/nginx/html/
root@test:/usr/share/nginx/html# ll
total 16
drwxr-xr-x 2 root root 4096 Jun 17 16:28 ./
drwxr-xr-x 3 root root 4096 Jun 17 16:28 ../
-rw-r--r-- 1 root root 537 May 6 15:56 50x.html
-rw-r--r-- 1 root root 31 Jun 17 20:17 index.html
root@test:/usr/share/nginx/html#
root@test:/usr/share/nginx/html# echo "<?php phpinfo(); ?>" >info.php
root@test:/usr/share/nginx/html#

Let’s check it on browser:–

open browser and type http://localhost/info.php , if you got the php information page same as here then your LEMP stack working fine.

Nginx-php


            

Leave a Reply

Time limit is exhausted. Please reload the CAPTCHA.