Installing Apache, MySQL, PHP, PHPMyAdmin on CentOS 6 with PHP Memcache for Drupal 6 Memcache API

Installing Apache, MySQL, PHP, PHPMyAdmin on CentOS 6 with PHP Memcache for Drupal 6 Memcache API

Login to Centos server as root user

Using command prompt check whether you are logged in as root user or not. If you are not logged in as root user, you will not be able to run any installation commands.

su –

The above command will ask you for root password if you are not logged in as root user, else if you are logged in as root user than it will not display any message.

Install Apache


First step is to install the Apache server.

yum install httpd httpd-devel

To start the apache server you can use:

service httpd start


/etc/init.d/httpd start

(Not required at this point) If you want to restart the Apache server you can use:

service httpd restart


Install MySQL


To install the MySQL server type in

yum install mysql mysql-server mysql-devel

The above command will install MySQL server with username as root and password is empty.

To change the MySQL server password, start the MySQL server by:

/etc/init.d/mysqld start




The above two commands will take you to the MySQL command prompt where you can use MySQL commands. To change the root password to a new one from security point of view. Use the MySQL commands to change the root user password.

mysql USE mysql;


mysql UPDATE user SET Password= ('newpassword') WHERE user='root';




mysql exit;


Once done, check by logging in:

mysql -u root -p

Enter Password:

After changing the password you might not be able to log in, if you have previously installed MySQL or it prompts an error that you can’t logging using password empty for root@localhost than change the password again by using:

service mysqld stop


rm -fr /var/lib/mysql/*


service mysqld start


mysqladmin -u root password 'rawr'


rawr is the new password.

To login to MySQL command prompt as root user use

mysql –u root –p

The above command will ask for root password for MySQL admin, entering your root password will log you in as root user for MySQL.

Install PHP


For installing php you need to update the EPCL package for the centos, as in centos some php modules are missing like php-mycrypt etc. which is required by phpMyAdmin for login as root user to phpMyAdmin.

To get the package for CentOS 6

cd /tmp




rpm -ivh epel-release-6-7.noarch.rpm


After installing the package you can install the php with other php extensions by:

yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml

To test whether php is working or not

You can create an index.php file in your root folder, usually at /var/www/html



On your browser type in localhost/index.php will display the php info and other extensions installed.

Installing phpMyAdmin


PHPMyAdmin will is a free MySQL database Administration Tool. You can install phpMyAdmin by using the yum install phpMyAdmin command. Make sure you have installed the php-mcrypt modules as it is required by phpMyAdmin to login as root user for phpMyAdmin.

yum install phpmyadmin


Installing PHP Memcache & PECL - Memcache

Memcache and PECL are included in the default package for CentOS, so we need to install the epel-release-6-5.noarch.rpm as explained in the PHP section before we run the installation commands for PECL and Memcache. First we will install the PECL and then will install PHP Memcache.

yum install php-pecl-memcache


yum install memcached


The above two commands will install the PECL and PHP Memcache. After this add extension to your php.ini file which you can usually found at /etc/php.ini.

To make memcache server to start on booting CentOS than add Memcached to chkconfig

chkconfig --add memcached

Restart the apache, MySQL and memcache services.

service httpd start


service mysqld start


service memcached start


To check whether memcache is installed or not, you need to create a php info file as explained under php installation section. Your php info will display a block that shows the memcache port and other settings.

For displaying the different instance of phpmemcache.

ps –e | grep memcached


Installing Drupal Memcache module


Download the Memcache Api module from the Drupal website and place it in your sites/all/modules/ folder. Install the Drupal module from the admin/build/modules section and configure the settings.php file in your sites/default/ folder to work with memcache. For changing the settings.php file follow the readme and install.txt file in memcache module.

Example for adding memcache configuration in your settings.php, add the below array in your settings.php

$conf = array(

'cache_inc' => './sites/all/modules/memcache/',

'memcache_servers' => array('localhost:11211' => 'default',


In above array you can replace localhost with the name or IP address of your server. If you get permission denied error in your Drupal status report, than run the following commands in your Linux command prompt.

setenforce 0

Restart the apache and memcache services again to apply the changes. You can see the memcache statics in Drupal admin section.

Leave a comment