Home > Dịch vụ VPS > Hệ điều hành Centos > How to Install PHP 5.4 and MySQL 5.5 in CentOS 6.4 via Yum

How to Install PHP 5.4 and MySQL 5.5 in CentOS 6.4 via Yum

In CentOS, packages are stable but old version by default. when you want to use newer one, you need to install from source or add extra repository. so then Let’s add extra repositories and install newer php and mysql.

How about default?

For example, look at PHP version.

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

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?

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