Tag Archives: memcached

Installing Apache, MySQL, PHP and Memcached on CentOS

10 Jun

Introduction

This page covers installation and configuration of Apache, MySQL, PHP and Memcached.

Configure Additional Yum Repositories

  1. Install the EPEL YUM Repository
  1. Install the REMI Yum Repository
  2. For more information see EPEL and REMI

MySQL installation

Install MySQL packages

    1. yum –enablerepo=remi install mysql-server mysql mysql-devel
    2. chkconfig mysqld on (enables /etc/init.d/mysqld to run at startup)
    3. /etc/init.d/mysqld start OR service mysqld start

Setup MYSQL users:

    1. Setup a user/password for localhost. Replace ‘XXXXX’ with password.
      1. /usr/bin/mysqladmin -u root password ‘XXXXX’
    2. Setup remote users. Replace ‘XXXXX’ with password

      Setup Localhost user

      #mysql -p
      Enter password:
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 6
      Server version: 5.0.77 Source distribution
      
      Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
      
      mysql>
      mysql>
      mysql> CREATE USER 'root'@'10.16.35.211' IDENTIFIED BY 'XXXXX';
      Query OK, 0 rows affected (0.00 sec)
      
      mysql> CREATE USER 'root'@'10.16.35.212' IDENTIFIED BY 'XXXXX';
      Query OK, 0 rows affected (0.00 sec)
      
      mysql> GRANT ALL PRIVILEGES ON * . * TO 'root'@'10.16.35.211' IDENTIFIED BY 'XXXXX' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
      Query OK, 0 rows affected (0.01 sec)
      
      mysql> GRANT ALL PRIVILEGES ON * . * TO 'root'@'10.16.35.211' IDENTIFIED BY 'XXXXX' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
      Query OK, 0 rows affected (0.00 sec)
      
      mysql> GRANT ALL PRIVILEGES ON * . * TO 'root'@'10.16.35.212' IDENTIFIED BY 'XXXXX' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
      Query OK, 0 rows affected (0.00 sec)

Memcached (server-side) installation

Install Memcached packages

    1. yum install libevent
    2. yum install memcached
    3. chkconfig memcached on (enables /etc/init.d/memcached to run at startup)

To start Memcached

  1. Add memcached startup options to /etc/sysconfig/memcached

    /etc/sysconfig/memcached

    PORT="11211"
    USER="root"
    MAXCONN="1024"
    CACHESIZE="2048"
    OPTIONS=""
    1. To start memcached:
      1. /etc/init.d/memcached start OR service memcached on
    2. Listens on port 11211 with memory size of 2GG

Apache Installation

  • yum install httpd
  • chkconfig httpd on (enables /etc/init.d/httpd to run at startup)
  • /etc/init.d/httpd start OR service httpd start

PHP Installation

The following PHP packages will be installed:

  • php
  • mysql (Mysql CLI)
  • php-mysql
  • php-bcmath
  • php-xml
  • APC
    • php-pear
    • php-devel
    • httpd-devel
  • Memcache (client side)
    • zlib-devel (this is a prerequisite for the pecl memcache client library)

Install the PHP packages

Install all packages except APC.
  1. yum –enablerepo=remi install php mysql php-mysql php-bcmath php-xml
  1. To upgrade to the latest PHP/PHP-FPM packages: yum –enablerepo=remi upgrade
Install APC support.
  1. yum –enablerepo=remi install php-pear php-devel httpd-devel
  2. pear install pecl/apc-beta
  3. echo “extension=apc.so” > /etc/php.d/apc.ini
Install Memcache (client side) support.
  1. yum install zlib-devel
  2. pear install pecl/memcache
  3. echo “extension=memcache.so” > /etc/php.d/memcache.ini
Install Memcached (client-side) support.
  1. These three packages are required for the next step to build the libmemcached source code:
    1. yum install libevent memcached gcc-c++
  2. Download the latest version from http://libmemcached.org:
    1. mkdir /opt/libmemcached
    2. cd /opt/libmemcached
    3. wget http://launchpad.net/libmemcached/1.0/0.42/+download/libmemcached-0.42.tar.gz
    4. tar xvfz libmemcached-0.42.tar.gz
    5. cd libmemcached-0.42
    6. ./configure
    7. make
    8. make install (installs the libmemcached files to /usr/local)
  3. Next install the pecl/memcached client
    1. yum install zlib-devel (not required if you already installed it as part of memcache (client-side) support)
    2. pear install pecl/memcached
    3. echo “extension=memcached.so” > /etc/php.d/memcached.ini
Install PCRE
  1. yum install pcre pcre-devel
Compile and Install Bstrlib
  1. Download and extract the bstrlib source code from http://bstring.sourceforge.net/
  2. After extracting run the following commands to compile and install the package
    1. gcc -c -fPIC -O3 bstrlib.c -o bstrlib.o
      1. Note: -fPIC is required for 64bit systems. Optional otherwise.
    2. ar rcs libbstrlib.a bstrlib.o
    3. cp libbstrlib.a /usr/lib

Installing rpc.rstatd for remote performance monitoring

  1. yum install rusers-server
  2. chkconfig rstatd on
  3. /etc/init.d/rstatd start
  • We’ll be using HP LoadRunner for performance testing. rstatd is required by Loadrunner for Unix kernel performance metrics.
  • See http://www.pirzyk.org/?p=504 for more details on rstatd

Configuring SELinux on CentOS to enable Apache remote networking

This step is required otherwise PHP won’t be able to connect to a remote MySQL instance.

  • setsebool -P httpd_can_network_connect true