guide

Improving Apache performance by cleaning up its configuration

Posted in apache, guide, tunning on February 16th, 2010 by fseek – 3 Comments

Simple steps to improve Apache performance by cleaning up unused modules.

Apache is the most used web server on Linux systems and it has lots of features. By default, it generally comes with many of these features enabled, but if you don’t need them, why waste memory, cpu and at the end performance?

Let’s tune it a bit!

Default Apache

With the default Apache installation (on CentOS), it generally uses this ammount of memory:

# top |grep httpd
apache 3682 0.0 6.7 37408 24836 ? S Feb13 1:30 /usr/sbin/httpd

So around 37m for the worker processes. I also did a simple test with “ab” (Apache benchmark) to see how many requests per second it can take:

# ab -n 500 http://fseek.me/
..
Requests per second: 2.31 [#/sec] (mean)
..

So about 2.32 requests per second (I re-did this time a few times to get an average).

Cleaning up the configuration

I went to the Apache configuration (/etc/httpd/conf/httpd.conf) and disabled the modules that I was sure I wouldn’t use:

#LoadModule authn_dbm_module modules/mod_authn_dbm.so
#LoadModule ldap_module modules/mod_ldap.so
#LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
#LoadModule dav_module modules/mod_dav.so
#LoadModule dav_fs_module modules/mod_dav_fs.so
#LoadModule speling_module modules/mod_speling.so
#LoadModule userdir_module modules/mod_userdir.so
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule cgi_module modules/mod_cgi.so

So I commented the proxy modules, cgi, ldap, etc.

Apache after the cleanup

After the cleanup (and restarting Apache), lets see how much memory it is using:

# top |grep httpd
apache 15715 0.8 4.4 29900 16588 ? S 15:24 0:00 /usr/sbin/httpd

So it went down from 37m to 29m of memory usage. If you are in a VPS (or slow box), that can really help performance. So, in addition to the memory usage reduction, let’s see if it improved the performance for our end users (average number of requests per second)

# ab -n 500 http://fseek.me/
..
Requests per second: 2.93 [#/sec] (mean)
..

That’s a good improvement too! From 2.32 requests per second, we increased to almost 3 per second (using ab, non-concurrent). The average time to complete the request also dropped from 429ms to 410ms…

It may look not much, but for such a simple change, why not do it?

Setting up your VPS – From the default install to a full Wordpress blog

Posted in guide, howto, vps, wordpress on February 13th, 2010 by fseek – 2 Comments

Easy step by step guide to setup your Linode Centos 5.3 server (via SSH without cpanel). We will show you how to install the LAMP stack (Apache, MySQL, PHP) and Wordpress.

Linode as well as most VPS (Virtual Private Servers), generally come with the minimum install of Linux by default, so to get to a full Wordpress blog running, you need a bit of work. This how-to will get you done very quickly.

First action: Update the box with a simple yum upgrade:

# yum upgrade

Say “yes” to all the questions to get everything updated before we move on.

1-Install Apache, PHP and the MySQL Server:

# yum install httpd.i386 php.i386 mysql.i386 php-mysql.i386 mysql-server.i386

After that is done, we can start Apache and configure it to start during the boot:

# chkconfig –level 3 httpd on
# /etc/init.d/httpd start
Starting httpd:                                                      [  OK  ]

You should now see Apache running with the “netstat” command:

#netstat -tanep |grep LISTEN
tcp        0      0 :::80                       :::*                        LISTEN      0          21928      3098/httpd
tcp        0      0 :::22                       :::*                        LISTEN      0          20513      3030/sshd

Very simple and easy.

2-Configure MySQL

Before we start MySQL we need to secure and tune it a little bit. MySQL comes with the “mysql_secure_installation” command to help automate this work. To get started, run:

[root@li65-185 ~]# /usr/bin/mysql_secure_installation

And say yes to all the questions:( and remember the MySQL root password since you will need it later)

Set root password? [Y/n] Y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

After that, you can start MySQL, configure it to start during boot and check if it is running with the “netstat” command:

# /etc/init.d/mysqld start
# chkconfig –level 3 mysqld on
# netstat -tanep
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       User       Inode      PID/Program name
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      27         22517      3246/mysqld

If you see the “mysqld” command on port 3306 it means you are all set to go.

3-Setting up database for Wordpress:

Once you have MySQL and Apache running, we can create the necessary tables in the database for Wordpress. These three queries are enough for it (you just need to change wpsite1 for the database name you want and wpuser/wppass for the username/password combination you prefer)

# mysql -u root -e “CREATE DATABASE wpsite1″ -p
# mysql -u root -e ‘GRANT ALL PRIVILEGES ON wpsite1.* TO “wpuser”@”localhost” IDENTIFIED BY “wppass”;’ -p
# mysql -u root -e ‘FLUSH PRIVILEGES;’ -p

Note that it will ask for your MySQL password you gave when you ran the “mysql_secure_installation” command. I hope you kept it in memory.

4- Installing Wordpress

Wordpress is very easy to install and widely documented. You just need to download it to your htdocs directory (in our case /var/www), uncompress and rename it to your site name (for this example we will use “yoursite.name”):

# cd /var/www
# wget http://wordpress.org/latest.tar.gz
# tar -zxvf latest.tar.gz
# mv wordpress yoursite.name
# cd /var/www/yoursite.name

Now, you need to rename wp-config-sample.php to wp-config.php and edit it with the
database name, user and pass you specified before:

# mv wp-config-sample.php wp-config.php
# vim wp-config.php

define(‘DB_NAME’, ‘wpfseek’);
define(‘DB_USER’, ‘wpfseeku’);
define(‘DB_PASSWORD’, ‘wpfseekp’);

Now that wordpress is done you need to configure apache to read /var/www/yoursite.name as the main root
for your site. To do that, create a file at /etc/httpd/conf.d like that (remember, always change yoursite.name for your real domain and 1.2.3.4 for your IP address):

# cat > /etc/httpd/conf.d
NameVirtualHost 1.2.3.4:80

<VirtualHost 1.2.3.4:80>
DocumentRoot “/var/www/yoursite.name”
ServerName yoursite.name
ErrorLog logs/error.log
CustomLog logs/access.log combined
<Directory “/var/www/yoursite.name”>
Options Indexes FollowSymLinks MultiViews Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Restart Apache and now you should be able to access your site to start blogging:

/etc/init.d/httpd restart

All commands to get the server ready for MySQL:

yum install httpd.i386 php.i386 mysql.i386 php-mysql.i386 mysql-server.i386
chkconfig –level 3 httpd on
chkconfig –level 3 mysqld on
/usr/bin/mysql_secure_installation
/etc/init.d/httpd start
/etc/init.d/mysqld start

Forgot my MySQL root password, how to recover it?

Posted in guide, howto, mysql on February 11th, 2010 by fseek – Be the first to comment

Uh-oh, did you just forgot your MySQL root password? Here’s how to recover it.

1-Stop MySQL:

# /etc/init.d/mysqld stop

2-Start Mysql without the grant table (so it will not ask for a password):

# /usr/bin/mysqld_safe –skip-grant-tables &

3-Log in as root:

# mysql –user=root mysql

4-Set up new password for the user root:

mysql> update user set Password=PASSWORD(‘mynewpwd’) WHERE User=’root’;

*Change mynewpwd for whatever password you want.

5-Restart mysql

# /etc/init.d/mysqld restart

That’s it! Your new password should now work.