I have shown you how to setup a LAMP server Linux, Apache, MySQL, PHP on Centos 6 before with default CentOS Provided Repositories CentOS-Base.repo. Hate it or love it, Apache web server has 55% market share which nginx or IIS (Microsoft) can’t beat it yet. By default Centos 6.5 will install:
- Apache 2.2.15 http HyperText Transfer Protocol web server
- MySQL 5.1.73 database management server
- PHP 5.3.3 server-side scripting language
To show your httpd web server version
# httpd -v
Sample output
Server version: Apache/2.2.15 (Unix) Server built: Apr 3 2014 23:56:16
# mysql -u root -p
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 5.1.73 Source distribution
# yum list installed | grep "php"
php.x86_64 5.3.3-27.el6_5 @updates php-cli.x86_64 5.3.3-27.el6_5 @updates php-common.x86_64 5.3.3-27.el6_5 @updates php-gd.x86_64 5.3.3-27.el6_5 @updates php-mbstring.x86_64 5.3.3-27.el6_5 @updates php-mysql.x86_64 5.3.3-27.el6_5 @updates php-pdo.x86_64 5.3.3-27.el6_5 @updates
If you want to use bleeding edge technology, the current newest stable PHP 5.5.11, MySQL Community Server 5.5.37 with Apache 2.2 on Centos, you will have to add some third party repositories EPEL (Extra Packages for Enterprise Linux) and REMI (Les RPM de Remi).
REMI repository was created and is maintained by Remi, remi repository has the lastest versions of Apache, PHP, MySQL (LAMP stack) and many other software packages for Redhat, Centos, Fedora,…
Extra Packages for Enterprise Linux (EPEL) repository was created and maintains by a group of Fedora Special Interest. Packages from EPEL repository will never conflict with packages with packages from other redhat based distributions.
Installing EPEL and REMI Repository for Centos 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
# 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
# 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
Backup your data, remove old Apache/httpd, MySQL, PHP packages
You don’t have to do this step if you on a fresh installed Centos or Fedora system. Note: if you are using some sort of virtualization environment like openvz, kvm, or xen, most of the time your hosting/vps providers use openvz/kvm/xen precreated templates. Those templates may have apache/http and/or php/mysql pre-installed. You want to remove old Apache/http, MySQL, and PHP packages from your system to prevent any error or conflict later, trust me removing old packages and install newer one is better doing upgrading packages. I spent hours to troubleshoot errors when I upgrade from PHP 5.3.3 and MySQL 5.1.73 to PHP 5.5.11 and MySQL 5.5.37. At the end I removed all old php/mysql and install newer versions, the process went smoothly without any error.
To backup Apache config file
# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bk
To backup PHP config file
# cp /etc/php.ini /etc/php.ini.bk
To backup MySQL config file
# cp /etc/my.cnf /etc/my.cnf.bk
Your Apache/PHP/MySQL configure files will be at the same directory as the original file with .bk file extension at the end.
Remove old Apache/PHP/MySQL packages
# yum remove httpd* php* mysql* -y
Install Apache 2.2 server
Centos 5.10 / Centos 6.5
# yum --enablerepo=remi,remi-php55 install httpd
Fedora 20 Heisenbug / 19 Schrödinger’s Cat
# yum --enablerepo=remi install httpd
Fedora 18 Spherical Cow / 17 Beefy Miracle
# yum --enablerepo=remi,remi-test install httpd
To start Apache
# service httpd start
To start Apache at Startup
# chkconfig httpd on
or
# chkconfig --level 235 httpd on
Install MySQL 5.5 server
MySQL 5.5 support multi-core CPUs better than older versions. Instead of waiting for CPUs get faster, you can take advantages today multi’cores CPU technology. There are many new features from Diagnostic improvements, Unicode, IPv6, and MySQL Cluster. The biggest change in MySQL 5.5 is default storage engine, older MySQL use MyISAM but 5.5 version use InnoDB as default storage engine.
Centos 5.10 / Centos 6.5
# yum --enablerepo=remi,remi-php55 install mysql-server
Fedora 20 Heisenbug / 19 Schrödinger’s Cat
# yum --enablerepo=remi install mysql-server
Fedora 18 Spherical Cow / 17 Beefy Miracle
# yum --enablerepo=remi,remi-test install mysql-server
To start MySQL database server
# service mysqld start
To start MySQL server at Startup
# chkconfig mysqld on
or
# chkconfig --level 235 mysqld on
Hardening MySQL with mysql_secure_installation command
Default MySQL installation isn’t safe since there is no default root password nor any user’s privilege. By using mysql_secure_installation the command will help to improve MySQL server more secure. With mysql_secure_installation, you can:
- Set MySQL’s root password
- Remove root’s remote access
- Remove anonymous users
- Disallow root login remotely
- Reload privilege tables
# mysql_secure_installation
Install PHP 5.5.11
PHP 5.5.x provides many new features like finally keyword, password hashing API, Apache 2.4 handler, and more… The thing I like the most is OPcache extension (Zend Optimiser plus opcode cache) is added which improve PHP performance by caching precompiled script bytecode in ram.
Centos 5.10 / Centos 6.5
# yum --enablerepo=remi,remi-php55 install php php-common
Fedora 20 Heisenbug / 19 Schrödinger’s Cat
# yum --enablerepo=remi install php php-common
Fedora 18 Spherical Cow / 17 Beefy Miracle
# yum --enablerepo=remi,remi-test install php php-common
Restart Apache after install PHP
# service httpd restart
Install PHP 5.5 modules
Depends on your need, there are some typical php’s modules which are required for general php’s scripts like PhpMyAdmin, phpbb, WordPress.
Centos 5.10 / Centos 6.5
# yum --enablerepo=remi,remi-php55 install php-mysql php-cli php-pear php-xml php-tidy php-pecl-apc php-pdo php-mysqlnd php-gd php-mbstring php-mcrypt
Fedora 20 Heisenbug / 19 Schrödinger’s Cat
# yum --enablerepo=remi install php-mysql php-cli php-pear php-xml php-tidy php-pecl-apc php-pdo php-mysqlnd php-gd php-mbstring php-mcrypt
Fedora 18 Spherical Cow / 17 Beefy Miracle
# yum --enablerepo=remi,remi-test install php-mysql php-cli php-pear php-xml php-tidy php-pecl-apc php-pdo php-mysqlnd php-gd php-mbstring php-mcrypt
Restart Apache after install PHP modules
# service httpd restart
For full list of php packages from remi repository
# yum --enablerepo=remi search php-
Check your LAMP server if it’s working properly
The simplest way to check your LAMP server (Linux Apache MySQL PHP) is working right, create a phpinfo file to see php version, and if you can view phpinfo file on your web browser means apache is working also. Creating phpinfo file
# nano /var/www/html/info.php
with the content for info.php file
<?php phpinfo(); ?>
Note:
To start/restart/stop Apache web server
# service httpd start # service httpd restart # service httpd stop
# service mysqld start # service mysqld restart # service mysqld stop
# yum --enablerepo=remi
# yum --enablerepo=remi,remi-php65 install httpd mysql-server php php-common php-cli php-mysql