Posts

How to Install PHP in nginx

Prerequisites

Install nginx web server

Step 1: Install PHP & PHP-FPM

Install packages php & php-fpm package on server using epel repository.

# yum --enablerepo=epel -y install php php-mbstring php-pear php-fpm

Step 2: Configure PHP-FPM

Modify user and group name in php-fpm configuration file.

# vi /etc/php-fpm.d/www.conf

user = nginx
group = nginx

Step 3: Start Service

Start php-fpm service.

# /etc/rc.d/init.d/php-fpm start

Starting php-fpm: [ OK ]
# chkconfig php-fpm on

Step 4: Configure default.conf file

Modify default.conf file.

# vi /etc/nginx/conf.d/default.conf
    # add follows in a "server" section

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        /etc/nginx/fastcgi_params;
    }

Step 5: Restart Service

Restart nginx server to execute the latest configurations.

# /etc/rc.d/init.d/nginx restart

Stopping nginx: [ OK ]
Starting nginx: [ OK ]

Step 6: Create a PHP Page

Create a PHP test page and save the file.

# echo "" > /usr/share/nginx/html/info.php

Open Your favorite browser and hit the URL: http://Your-IP-Address/info.php
phpinfo

How to Install PHP in Linux

Step 1: Prerequisite

Step 2: Install PHP

Run the yum install command

# yum install php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml

Step 3: How to configure PHP

# vi /etc/php.ini
memory_limit = 128M
max_execution_time = 120
max_upload_size = 50M
post_max_size = 50M

Step 4: Create PHP page

Create the /var/www/html/phpinfo.php file with the following text:

# touch /var/www/html/phpinfo.php
# vi /var/www/html/phpinfo.php
<?php
phpinfo();
?>

Step 5: Restart Apache Server

Now restart Apache Server

# service httpd restart

Step 6: Open Page on Browser

Test the php page on your favorite browser:
http://Your-IP-address/phpinfo.php

How to Install phpmyadmin in CentOS / RedHat / Fedora

Step 1: Prerequisites

Step 2: Download Package

Download rpm package for CentOS / RedHat /Fedora

# rpm -ivh http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/6/i386/epel-release-6-8.noarch.rpm
# yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
# yum check-update

Step 3: Install phpmyadmin

# yum install phpMyAdmin

Step 4: Reload Apache Service

# service httpd restart

Step 5: Check on Browser

Open your favorite browser and Hit the  URL:http://192.168.1.1/phpMyAdmin

Troubleshooting

»  #2002 – Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
The server is not responding (or the local server’s socket is not correctly configured).
( This means your mysql server service is stopped , you must start the service  “service mysql start”)

» You don’t have permission to access /phpMyAdmin/ on this server.
Open /etc/httpd/conf.d/phpMyAdmin.conf file and find the lines “Deny from All” and comment those lines and restart httpd service

vi /etc/httpd/conf.d/phpMyAdmin.conf

» If you are installing phpmyadmin on Redhat 7 you may face this issue:
Error: Package: php-php-gettext-1.0.11-10.el7.noarch (epel)
Requires: php-mbstring
Error: Package: php-tcpdf-6.0.091-1.el7.noarch (epel)
Requires: php-bcmath
Error: Package: phpMyAdmin-4.2.8.1-2.el7.noarch (epel)
Requires: php-mbstring >= 5.3.0
Error: Package: php-tcpdf-6.0.091-1.el7.noarch (epel)
Requires: php-mbstring
You could try using –skip-broken to work around the problem
You could try running: rpm -Va –nofiles –nodigest

In order to resolve this issue follow the following steps:

# wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/7/x86_64/yum-plugin-replace-0.2.7-1.ius.el7.noarch.rpm

Install yum replace package and replace entire PHP stack

# rpm -i yum-plugin-replace-0.2.7-1.ius.el7.noarch.rpm 
# yum replace php --replace-with php56u