Articles Comments

{ Berbagi, Menulis, Dan Mengajar } Ilmu… » 7. Operating System » lighttp + MYSQL + PHP Setting

lighttp + MYSQL + PHP Setting

Share

Security, speed, compliance, and flexibility — all of these describe lighttpd (pron. lighty) which is rapidly redefining efficiency of a webserver; as it is designed and optimized for high performance environments. With a small memory footprint compared to other web-servers, effective management of the cpu-load, and advanced feature set (FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting and many more) lighttpd is the perfect solution for every server that is suffering load problems. And best of all it’s Open Source licensed under the revised BSD license.

Installing Lighttpd in Ubuntu


Lighttpd is available as a Ubuntu package, therefore we can install it like this

sudo apt-get install lighttpd

Now direct your browser to http://serverip and you should see the Lighttpd placeholder page

Lighttpd’s default document root is /var/www on Ubuntu, and the configuration file is /etc/lighttpd/lighttpd.conf.

Installing PHP5 in Ubuntu

We can make PHP5 work in Lighttpd through FastCGI. Fortunately, Ubuntu provides a FastCGI-enabled PHP5 package which we install like this:

sudo apt-get install php5-cgi

Configuring Lighttpd And PHP5

To enable PHP5 in Lighttpd, we must modify two files, /etc/php5/cgi/php.ini and /etc/lighttpd/lighttpd.conf. First we open /etc/php5/cgi/php.ini and add the line cgi.fix_pathinfo = 1 right at the end of the file:

sudo vi /etc/php5/cgi/php.ini

cgi.fix_pathinfo = 1

Then we open /etc/lighttpd/lighttpd.conf and add “mod_fastcgi”, to the server.modules stanza

sudo vi /etc/lighttpd/lighttpd.conf

server.modules = (
“mod_access”,
“mod_alias”,
“mod_accesslog”,
“mod_fastcgi”,
# “mod_rewrite”,
# “mod_redirect”,
# “mod_status”,
# “mod_evhost”,
# “mod_compress”,
# “mod_usertrack”,
# “mod_rrdtool”,
# “mod_webdav”,
# “mod_expire”,
# “mod_flv_streaming”,
# “mod_evasive”
)

and then right at the end of the file, we add the following stanza:

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

Installing MySQL 5.0

First we install MySQL 5.0 like this:

sudo apt-get install mysql-server mysql-client

Create a password for the MySQL user root (replace yourrootsqlpassword with the password you want to use):

sudo mysqladmin -u root password yourrootsqlpassword

Then check with

netstat -tap | grep mysql

on which addresses MySQL is listening. If the output looks like this:

tcp 0 0 localhost.localdo:mysql *:* LISTEN 2713/mysqld

which means MySQL is listening on localhost.localdomain only, then you’re safe with the password you set before. But if the output looks like this:

tcp 0 0 *:mysql *:* LISTEN 2713/mysqld

you should set a MySQL password for your hostname, too, because otherwise anybody can access your database and modify data:

sudo mysqladmin -h serverip -u root password yourrootsqlpassword

Testing PHP5 in Lighttpd

The document root of the default web site is /var/www. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

vi /var/www/test.php

<?php
phpinfo();
?>

Adding MySQL Support In PHP5

To get MySQL support in PHP, we can install the php5-mysql package. It’s a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:

sudo apt-cache search php5

Pick the ones you need and install them like this:

sudo apt-get install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-common

You might see a question like this one:

Continue installing libc-client without Maildir support? <– Yes

Now restart Lighttpd:

sudo /etc/init.d/lighttpd restart

(If you’ve installed the module php5-common and get warnings like this one:

PHP Warning: Module ‘json’ already loaded in Unknown on line 0

it means that the module got loaded twice. Open /etc/php5/cgi/php.ini, scroll down to the end and comment out the line extension=json.so:

sudo vi /etc/php5/cgi/php.ini

;extension=json.so

Then restart Lighttpd again:

sudo /etc/init.d/lighttpd restart

The warnings should now be gone.

Now reload http://serverip/test.php in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module

Filed under: 7. Operating System

Leave a Reply

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>