Install Lighttpd, PHP5, and MySQL on CentOS

This is a tutorial to install Lighttpd, MySQL, and PHP5 on your CentOS server.

To begin, let’s install MySQL. Run the following command as root:

yum install nano mysql* -y

Once that completes, it is time to remove any preinstalled software such as Apache and then we need to install dependencies. Run the following commands to take care of this:

yum remove httpd -y
yum install libjpeg libjpeg-devel zlib zlib-devel libxml2 libxml2-devel libpng* gcc gcc-c++ make flex bison openssl* pcre* -y
yum install mysql* -y

Once that completes, it’s time to download Lighttpd and PHP.

cd ~
wget http://www.lighttpd.net/download/lighttpd-1.4.19.tar.gz
wget http://us3.php.net/get/php-5.2.6.tar.gz/from/this/mirror

When the downloads have completed, we need to untar the software.

tar -xf lighttpd-1.4.19.tar.gz
tar -xf php-5.2.6.tar.gz

After they untar (which can take thirty seconds to five minutes depending on the server), it’s time to start compiling. Run the following commands:

cd lighttpd-1.4.19
./configure –with-bzip2 –with-pcre –with-mysql=/usr/bin/mysql_config –with-ldap
make
make install

When this completes, you have successfully installed Lighttpd on your server. It is now time for PHP.

cd ..
cd php-5.2.7
./configure –enable-fastcgi –enable-discard-path –enable-force-redirect –with-gettext=/usr –with-exec-dir=/usr/bin –with-zlib –enable-magic-quotes –with-regex=system –with-ttf –with-db –enable-mbstring –enable-mbstr-enc-trans –enable-track-vars –enable-wddx=shared –enable-mm=shared –enable-xml –enable-ftp –disable-debug –with-libdir=/usr/lib
make
make install

When this is complete, PHP has also successfully been installed on your server. When this is done, there are a few more directories that need to be created.

cp /root/lighttpd-1.4.18/doc/lighttpd.conf /etc
cd /var/run
mkdir lighttpd
cd ..
cd log
mkdir lighttpd
cd lighttpd
touch access.log
mkdir /srv
mkdir /srv/www
mkdir /srv/www/htdocs

At this point, you have successfully installed Lighttpd 1.4.19, PHP 5.2.7, and MySQL 5.0.45 on your server.

To complete the set up, there is a small amount of configuration required by Lighttpd.

Edit /etc/lighttpd.conf with your preferred editor.

Find:

# “mod_fastcgi”,

Uncomment it.

Find:

#fastcgi.server = ( “.php” =>
# ( “localhost” =>
# (
# “socket” => “/tmp/php-fastcgi.socket”,
# “bin-path” => “/usr/local/bin/php-cgi”
# )
# )
# )

Replace with:

fastcgi.server = ( “.php” =>
( “localhost” =>
(
“socket” => “/tmp/php-fastcgi.socket”,
“bin-path” => “/usr/local/bin/php-cgi”
)
)
)

To launch Lighttpd, run “lighttpd -f /etc/lighttpd.conf” and the server will start.

Place your files to be served by Lighttpd in /srv/www/htdocs.

Comments

One Response to “Install Lighttpd, PHP5, and MySQL on CentOS”

  1. Help installing Lighttpd - Overclock.net - Overclocking.net on October 4th, 2009 1:28 am

    [...] to install Lighttpd on my server with moderate luck. I am running CentOS 5.3. I am following this guide and I am stuck at the point where I compile Lighttpd. Here is the point for reference. [...]

Leave a Reply