Wednesday, March 19, 2014

Install PHP 5.4 and MySQL 5.5 in CentOS 6.4 via Yum

How about default?

For example, look at PHP version.
CentOS
$ yum info php

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.sin3.sg.voxel.net
 * extras: mirrors.sin3.sg.voxel.net
 * updates: mirror.neu.edu.cn
Available Packages
Name        : php
Arch        : x86_64
Version     : 5.3.3
Release     : 23.el6_4
Size        : 1.1 M
Repo        : updates
Summary     : PHP scripting language for creating dynamic web sites
URL         : http://www.php.net/
License     : PHP
Description : PHP is an HTML-embedded scripting language. PHP attempts to make it
            : easy for developers to write dynamically generated webpages. PHP also
            : offers built-in database integration for several commercial and
            : non-commercial database management systems, so writing a
            : database-enabled webpage with PHP is fairly simple. The most common
            : use of PHP coding is probably as a replacement for CGI scripts.
            :
            : The php package contains the module which adds support for the PHP
            : language to Apache HTTP Server.
It’s 5.3 you know.

Add repository

There are a few popular repository for CentOS like bellow.
  • epel
  • remi
  • rpmforge
Let’s install them.
you need to do it with root privilege so use sudo or su - and get privilege.

epel

CentOS
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

remi

CentOS
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

rpmforge

CentOS
# rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

Check repository

CentOS
# yum repolist
you can find the repository names you installed.

Enable repository and Install

These repository is not supported by CentOS, so for dependancy enable them only when you want to get special package.
CentOS
# vi /etc/yum.repos.d/epel.repo
/etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=0 # 1 -> 0 disable
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
CentOS
# vim /etc/yum.repos.d/rpmforge.repo
/etc/yum.repos.d/rpmforge.repo
[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/rpmforge
mirrorlist = http://mirrorlist.repoforge.org/el6/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 0 # 1 -> 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
setting them explicitly with option, you can use.
try to get information about php
CentOS
# yum --enablerepo=epel,remi,rpmforge info php

Name        : php
Arch        : x86_64
Version     : 5.4.22
Release     : 1.el6.remi
Size        : 2.7 M
Repo        : remi
Summary     : PHP scripting language for creating dynamic web sites
URL         : http://www.php.net/
License     : PHP and Zend and BSD
Description : PHP is an HTML-embedded scripting language. PHP attempts to make it
            : easy for developers to write dynamically generated web pages. PHP also
            : offers built-in database integration for several commercial and
            : non-commercial database management systems, so writing a
            : database-enabled webpage with PHP is fairly simple. The most common
            : use of PHP coding is probably as a replacement for CGI scripts.
            :
            : The php package contains the module (often referred to as mod_php)
            : which adds support for the PHP language to Apache HTTP Server.
OK, Let’s go on.
CentOS
# yum --enablerepo=epel,remi,rpmforge install php php-mysql php-devel
and install MySQL.
CentOS
# yum --enablerepo=epel,remi,rpmforge install mysql-server mysql-devel

Initialise

along with php, apache web server is installed automatically.if you type php -v, you can confirm it is installed but start web server and check it. because it’s very easy.
CentOS
# service httpd start
CentOS
# echo '<?php phpinfo(); ?>' > /var/www/html/phpinfo.php
Open a browser in host and type IP address you set. (ex, 192.168.56.10/phpinfo.php or centos that I set before)
Can you see this screen in your browser?
phpinfo
OK next setup MySQL
CentOS
# service mysqld start
CentOS
$ mysql_secure_installation
configure charcter set to UTF-8
CentOS
# vim /etc/my.cnf
/etc/my.cnf
[mysqld]
.
.
#add bellow
character-set-server = utf8
skip-character-set-client-handshake
After change config file, do restart.
CentOS
# service mysqld restart
Login and confirm setting.
CentOS
$ mysql -u root -p
Enter password: # while mysql_secure_installation you set password you know
MySQL
mysql> staus
.
.
# check them like this
Server characterset: utf8
Db     characterset: utf8
Client characterset: utf8
Conn.  characterset: utf8
 Link:http://webees.me/how-to-install-php-5-4-and-mysql-5-5-in-centos-6-4-via-yum/ 

PHP Modules

We are going to install all these following PHP modules in this installation.
  1. MySQL (php-mysql) – A extension for PHP applications that use MySQL databases.
  2. PostgreSQL (php-pgsql) – A extension for PostgreSQL database for PHP.
  3. MongoDB (php-pecl-mongo) – A driver for MongoDB database.
  4. SQLite (php-sqlite) – Extension for SQLite Database Engine.
  5. Memcache (php-pecl-memcache) – Memcached caching daemon.
  6. Memcached (php-pecl-memcached) – Memcached caching daemon.
  7. GD (php-gd) – GD extension for PHP application to serve graphics.
  8. XML (php-xml) – XML Parser for PHP applications.
  9. MBString (php-mbstring) – Mbstring extension is used to handle multi-byte string in PHP applications.
  10. MCrypt (php-mcrypt) – A Mcrypt library for PHP scripts.
  11. APC (php-pecl-apc) – APC module used to optimize and cache PHP code.
  12. CLI (php-cli) – Command-line interface for PHP.
  13. PEAR (php-pear) – Application Repository framework for PHP.
  14. PDO (php-pdo) – Database access module for PHP applications.
Install Apache 2.2.15, MySQL 5.5.34 & PHP 5.5.4 on RHEL 6.4/6.3/6.2/6.1/6.0/5.9/5.8/5.6, CentOS 6.4/6.3/6.2/6.1/6.0/5.9/5.8/5.6 and Fedora 12,13,14,15,16,17,18,19

Step 1: Installing Remi Repository

## Install Remi Repository on Fedora 19, 18, 17, 16, 15 ## rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm ## Fedora 19 ## # rpm -Uvh http://rpms.famillecollet.com/remi-release-19.rpm ## Fedora 18 ## # rpm -Uvh http://rpms.famillecollet.com/remi-release-18.rpm ## Fedora 17 ## # rpm -Uvh http://rpms.famillecollet.com/remi-release-17.rpm ## Fedora 16 ## # rpm -Uvh http://rpms.famillecollet.com/remi-release-16.rpm ## Fedora 15 ## # rpm -Uvh http://rpms.famillecollet.com/remi-release-15.rpm ## Fedora 14 ## # rpm -Uvh http://rpms.famillecollet.com/remi-release-14.rpm ## Fedora 13 ## # rpm -Uvh http://rpms.famillecollet.com/remi-release-13.rpm ## Fedora 12 ## # rpm -Uvh http://rpms.famillecollet.com/remi-release-12.rpm ## Install Remi & Epel Repository on RHEL/CentOS 6.4-6.0 - 32 Bit ## rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm ## Install Remi & Epel Repository on RHEL/CentOS 6.4-6.0 - 64 Bit ## rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm ## Install Remi Repository on RHEL/CentOS 5.9-5.0 - 32 Bit ## rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm ## Install Remi Repository on RHEL/CentOS 5.9-5.0 - 64 Bit ## rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

Step 2: Installing Apache 2.2.15, MySQL 5.5.34 & PHP 5.5.4

## Installing on Fedora 12, 13, 14, 15, 16, 17, 18, 19 ## # yum --enablerepo=remi install httpd mysql mysql-server php php-common ## Installing on RHEL/CentOS 5-6 ## # yum --enablerepo=remi,remi-test install httpd mysql mysql-server php php-common

Step 3: Installing PHP 5.5.4 Modules

## Installing on Fedora 12, 13, 14, 15, 16, 17, 18, 19 ## # yum --enablerepo=remi install php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml php-pecl-apc php-cli php-pear php-pdo ## Installing on RHEL/CentOS 5-6 ## # yum --enablerepo=remi,remi-test install php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml php-pecl-apc php-cli php-pear php-pdo

Step 4: Starting/Stopping Apache & MySQL

## Enable Apache and MySQL on Run-Levels ## # chkconfig --levels 235 httpd on # chkconfig --levels 235 mysqld on ## Apache Commands ## # /etc/init.d/httpd start # /etc/init.d/httpd stop # /etc/init.d/httpd status ## MySQL Commands ## # /etc/init.d/mysqld start # /etc/init.d/mysqld stop # /etc/init.d/mysqld status

Step 5: Verifying Apache 2.2.15, MySQL 5.5.34 & PHP 5.5.4

1. Create a page called phpinfo.php under your Apache root directory and add the following lines to it. For example (/var/www/html/phpinfo.php).
<?php phpinfo (); ?>
2. Now access the page via web browser like http://localhost/phpinfo.php. You will see below screenshot.
Install PHP 5.5.4
PHP 5.5.4 Preview
That’s it!. If you are having any trouble installing, let me know via our comment section.