Create your personal Web hosting 2

Now we know that Apache can handle a sufficient number of request, the next step is to test with a real running server. For this purpose I will use WordPress.
WordPress needs a database, but the box use a sdcard as a mass storage, which is not recommended and should be avoid. To handle this problem I will use an USB port to plug a USB key or later a hd disk if needed. To easily switch I will do an logical link in the system to change the target of the mass storage. Insure that you install a raid solution (see http://olinuxino.4pro-web.com/how-to-speedup-access/)

apt-get install mysql-server
mysql_secure_installation
apt-get install php5  php5-mysql
apachectl restart

Now download wordpress

cd /mnt/raid
wget https://wordpress.org/latest.zip
unzip latest.zip
chmod  -R 755 wordpress
chown -R www-data
String link = "http://www.megatome.com";
System.out.println("Hello World");
System.out.println("Goodbye World");

Now it’s time to install wordpress

Edit the file /etc/apache2/sites-enabled/000-default and change the value DocumentRoot to your external hd ( /mnt/raid/wordpress in my case)
Then go to your laptop and in your web browser type your box ip adress (192.168.1.71 in my case).

Be careful if you have errors like can not insert or create databases, ensure that the mass storage have 755 authorization?

Now if you succeed installed wordpress, from your laptop, you have a site in 192.168.1.71

Now we gonna tweak apache. As I have already said sd card are not reliable. So we gonna put logs from apache to memory. The log will be

accesed like a filesystem, but will be stored in memory and will deleted if you reboot your box. Nevertheless you can add a script to store at specific time.
Debian has a specific filesystem named tmpfs, so my /etc/fstab looks like:

1
2
3
4
5
6
7
8
9
10
11
12
13
# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/root      /               ext4    noatime,errors=remount-ro 0 1
tmpfs    /run/shm    tmpfs    defaults    0 0
tmpfs    /tmp        tmpfs    defaults    0 0
tmpfs    /var/tmp    tmpfs    defaults    0 0
tmpfs    /var/log/apache2    tmpfs    defaults,size=50M    0 0
/dev/nanda   /media/nand auto    rw,user,noauto,exec   0   0
#/dev/sda1   /media/hdd auto    rw,user,noauto,exec   0   0
/dev/sda1       /mnt/sdb1           ext4    defaults        0       0 
/dev/sdb1       /mnt/sdb2           ext4    defaults        0       0
/dev/md0 	/mnt/raid	ext2	defaults 	0	1

Now we have the same problem with the mysql database, so I will move it into the Usb key (raid1 in our case).
To do so:

1
2
3
4
5
6
service mysql stop 
mv /var/lib/mysql /var/lib/mysql-old
mkdir /mnt/raid/mysql
ln -s /mnt/raid/mysql /var/lib/mysql
cp -pr /var/lib/mysql-old/* /mnt/raid/mysql 
/etc/init.d/mysqld start
1
ab -n 400 -c 50 -g test_data_1.txt http://192.168.1.71/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Document Path:          /
Document Length:        251 bytes
 
Concurrency Level:      50
Time taken for tests:   30.235 seconds
Complete requests:      400
Failed requests:        0
Non-2xx responses:      400
Total transferred:      242800 bytes
HTML transferred:       100400 bytes
Requests per second:    13.23 [#/sec] (mean)
Time per request:       3779.398 [ms] (mean)
Time per request:       75.588 [ms] (mean, across all concurrent requests)
Transfer rate:          7.84 [Kbytes/sec] received

Result are not very good. Indeed we can serve only 13rq/s. So let’s try to optimize:

sudo apt-get install php-apc 
vi /etc/php5/apache2/php.ini
add extension=apc.so at the end of the file

Add WP Super Cache to your WordPress installation and then we have a fully functional site.

At conclusion we can support 50rq/s

our environment can support a big number of requests,son in the last part of these articles I will show you how to put your website on the web.

ab -n 400 -c 50 -g test_data_1.txt http://5.49.77.158/
Server Software:        Apache/2.2.22
Server Hostname:        5.49.77.158
Server Port:            80
 
Document Path:          /
Document Length:        9287 bytes
 
Concurrency Level:      50
Time taken for tests:   4.262 seconds
Complete requests:      400
Failed requests:        0
Total transferred:      3836400 bytes
HTML transferred:       3714800 bytes
Requests per second:    93.84 [#/sec] (mean)
Time per request:       532.798 [ms] (mean)
Time per request:       10.656 [ms] (mean, across all concurrent requests)
Transfer rate:          878.96 [Kbytes/sec] received

Leave a Reply