How to install web server on FreeBSD

For those who have never tried FreeBSD including Windows and Linux, I would like to recommend to try it just once. FreeBSD is one of the most efficient operating system for heavy-load internet server. Below are what I did to setup a web server on FreeBSD. In this article I will focus on FreeBSD 6.1, Apache 2.2.3, MySQL 5.0.26, PHP 5.1.6, FastCGI 1.09, eAccelerator 0.95-rc1, and LimitIPConn 0.22.

Apache 2.2.3

cd /usr/ports/www/apache22
make WITH_MISC_MODULES=yes WITH_CACHE_MODULES=yes WITH_MPM=worker
make install

Add below line into /etc/rc.conf.

apache22_enable="YES"

Now you are able to start it immediately.

/usr/local/etc/rc.d/apache22 start

MySQL 5.0.26

cd /usr/ports/databases/mysql50-server
make WITH_CHARSET=tis620 WITH_XCHARSET=all WITH_COLLATION=tis620_thai_ci BUILD_OPTIMIZED=yes
make install
cd /usr/ports/databases/mysql50-client
make
make install

Add below line into /etc/rc.conf.

mysql_enable="YES"

Now you are able to start it immediately.

/usr/local/etc/rc.d/mysql-server start

PHP 5.1.6

cd /usr/ports/lang/php5
make
make install
cd /usr/ports/lang/php5-extensions
make
make install

Add index.php to directive DirectoryIndex in /usr/local/etc/apache22/httpd.conf

DirectoryIndex index.html index.php

Create a php.ini from php.ini-recommended.

cp /usr/local/etc/php.ini-recommended /usr/local/etc/php.ini

Modify below setting in /usr/local/etc/php.ini.

short_open_tag = On
memory_limit = 128M
post_max_zie = 32M
upload_max_filezie = 32M

Don't forget to restart apache22 to activate the change in php.ini.

/usr/local/etc/rc.d/apache22 restart

mod_fcgid 1.09

There are 2 FastCGI implementation which are completely compatible. I had tried mod_fastcgi first but it seemed mod_fcgi was much better.

cd /usr/ports/www/mod_fcgid
make
make install

Create a file /usr/local/etc/apache22/Includes/fastcgi.conf.


    AddHandler  fcgid-script .fcgi
    Action  application/x-httpd-php /cgi-bin/php5.fcgi
    AddHandler  application/x-httpd-php .php

Create a file /usr/local/www/apache22/cgi-bin/php5.fcgi.

#!/bin/sh
PHPRC="/usr/local/etc"
export PHPRC
#PHP_FCGI_CHILDREN=4
#export PHP_FCGI_CHILDREN
#PHP_FCGI_MAX_REQUESTS=5000
#export PHP_FCGI_MAX_REQUESTS
exec /usr/local/bin/php-cgi

Don't forget to make it executable.

chmod +x /usr/local/www/apache22/cgi-bin/php5.fcgi

Then restart apache22 again.

/usr/local/etc/rc.d/apache22 restart

eAccelerator 0.9.5-rc1

If your web server are loaded by lots of concurrent users, you might try eAccelerator to cache the state of PHP.

cd /usr/ports/www/eaccelerator
make
make install

Add below lines into /usr/local/etc/php.ini.

zend_extension="/usr/local/lib/php/20050922/eaccelerator.so"
eaccelerator.shm_size="16" 
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0" 
eaccelerator.filter=""
eaccelerator.shm_max="0"  
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

mod_limitipconn 0.22

In case of your web server has been loaded too much by the same IP address, limitipconn2 might help you to solve the problem.

cd /usr/ports/www/mod_limitipconn2
make
make install

Tags: , ,

Post new comment