Wednesday, February 10, 2010

Setting Up LAMP + memcached on Ubuntu Server 9.10

This post will show a guide on how to setup LAMP with memcached on three machines. Perhaps this will help us on writing technical report..huahuha
We are currently running our performance test on our web and database server using memcached. The test is used to monitor the cpu and memory usage using cacti. Thanks to khairina for SNMP and cacti configuration :)

We have installed LAMP server in two 64-bit machines, whereas 1 machine running apache2 with php5 while another one running MySQL 5.1.
We also have a dedicated memcached server. Since we are using php5, thus we chosen php as our memcached client.
Then it can be simply tested using 'ab' (apache bench).

Step 1: Setting up Web Server (192.168.0.101)
Installing apache2 and php5
$ sudo apt-get install apache2 php5 libapache2-mod-php5

Note: In ubuntu, php5 will use php5-prefork by default

Installing MySQL module for php5
$ sudo apt-get install libapache2-mod-auth-mysql php5-mysql

Then, edit php configuration file to add mysql extension
$ sudo vi /etc/php5/apache2/php.ini

Then add this line
extension=msql.so

Installing memcache module for php5
$ apt-get install php5-memcache

Then, edit php configuration file to add memcached extension
$ sudo vi /etc/php5/apache2/php.ini

Then add this line
extension=memcache.so

To ease us in locating our php file on our web server, we have changed the default location.
Edit /etc/apache2/sites-available/default. Don't forget to backup it first. (use gedit,vi or nano)
$ sudo vi /etc/apache2/sites-available/default

Then, find this two lines.
DocumentRoot /var/www/

Edit it into preferred directory, so it become
DocumentRoot /home/username/web/

Make sure the directory exists
$ mkdir /home/username/web/

Restart apache2
$ sudo /etc/init.d/apache2 restart

Now, we can create our php code inside the web directory.

Step 2: Setting up Database Server (192.168.0.102)
Installing MySQL server 5.1
$ sudo apt-get install mysql-server

Then edit mysql configuration file to bind address so it can be connected from any machines
$ sudo vi /etc/mysql/my.cnf

Edit this line
bind-address = 127.0.0.1
to (MySQL server IP address)
bind-address = 192.168.0.102

then, restart mysql server
$ sudo /etc/init.d/mysql restart

Add a user to enable to mysql client connect from different host (as mysql server) see the manual here

Step 3: Installing Memcached (192.168.0.103)
Get the latest memcached source file (current version is 1.4.4) that can be download from this site. Then, follow this guide

Or simply install using apt-get. In ubuntu 9.10 the memcached version is 1.2.8
$ sudo apt-get install memcached

Create a file, put the php code below and save it as index.php into /home/username/web directory (or /var/www/ if haven't do any changes)


Open web browser the type http://webserver_ipaddress/index.php. Then, the memcached module for php5 can be found in this page as figure below

Now, we can test our web and database server :D


References:

No comments:

Post a Comment