Lighttpd web server setup custom PHP.INI file for each user or domain

Posted on in Categories Howto, lighttpd, Linux, RedHat/Fedora Linux, Ubuntu Linux, UNIX last updated July 16, 2007

You can provide each user or domain its own php.ini file. There are two basic ways to provide each user a php.ini file:

a) Setup chrooted jail for each domain and user will get /etc/php.ini inside each jail
b) Setup individual fastcgi instance for each domain along with php.ini

Let us say you have two domains as follows

  1. php.ini location /home/lighttpd/
  2. php.ini location /home/lighttpd/
  3. /etc/php.ini – generic file for the rest of all domains

You need to add following directives to lighttpd.conf file:

$HTTP["host"]  =~ "(^|\.)theos\.in$" {
  server.document-root = "/home/lighttpd/"
  accesslog.filename         = "/var/log/lighttpd/"
  server.error-handler-404 = "/index.php?error=404"
  fastcgi.server    = ( ".php" =>
                "bin-path" => "/usr/bin/php-cgi -c /home/lighttpd/",
                "socket" => "/home/lighttpd/",

$HTTP["host"]  =~ "(^|\.)cyberciti\.biz$" {
  server.document-root = "/home/lighttpd/"
  accesslog.filename         = "/var/log/lighttpd/"
  server.error-handler-404 = "/index.php?error=404"
  fastcgi.server    = ( ".php" =>
                "bin-path" => "/usr/bin/php-cgi -c /home/lighttpd/",
                "socket" => "/home/lighttpd/",

Note option -c /path/to/my/custom/php.ini passed to /usr/bin/php-cgi. It will force php to Look for php.ini file in the directory path specified by us.

Now end users can modify php.ini as per requirements.


  • Although a user can make changes to php.ini file, you still need to restart a web server using root or equivalent privileges
  • This may also open your box to new security issue such as wrong php.ini settings or user can load any custom php modules

You can apply same settings to Apache web server using jail or lighttpd fastcgi as a proxy.

Can someone steal my PHP script without hacking server?

Posted on in Categories Apache, Howto, lighttpd, Linux distribution, Networking, php, Security, Tips, Troubleshooting last updated August 12, 2007

Adarsh asks:

Can someone steal my PHP code or program without hacking my Linux box? Can someone snoop script over plain HTTP session?

Short answer is no. PHP is server side thingy.

However a misconfigured webserver can easily give out php file to all end users. You need to make sure that mod_php / mod_fastcgi loaded and correct MIME type is setup. To avoid such problem always test your server before moving to production environment. Most Linux distro configures both Apache and PHP out of box.

How do I stop downloading php source code?

The first step should be stopping a webserver.
# /etc/init.d/httpd stop
# /etc/init.d/lighttpd stop

If you are using Lighttpd…

Next bind webserver to for testing purpose. Open lighttpd websever config file and bind server address to
# vi /etc/lighttpd/lighttpd.conf
Bind to localhost/
server.bind = ""
Start lighttpd:
# /etc/init.d/lighttpd start
Now follow these instructions to configure php as fastcgi module. Now test your configuration using url PHP should work on server. If not working, refer to server log file.

If you are using Apache…

Open httpd.conf file and bind apache to
# vi httpd.conf
The Listen directive instructs Apache to listen to more than one IP address or port; by default it responds to requests on all IP interfaces, but only on the port given by the Port directive.
Start apache:
# /etc/init.d/httpd start
Now make sure php is installed use apt-get or rpm command to verify the same:
# rpm -qa | grep -i php
# dpkg --list | grep -i php
If PHP is not installed just follow these instructions to install PHP. Next make sure httpd.conf or php.conf has following directives:
LoadModule php4_module modules/
AddType application/x-httpd-php .php

Note: the path may differ in your setup. Now restart httpd:
# /etc/init.d/httpd restart
A sample php code:

<?php   phpinfo(); ?>

Finally when php started to work properly, make sure you bind back a server IP address from to public IP address.

Another option is keep your source code out of webroot and server all php requests from php application server using mod_proxy and multiple back-end servers.

How to optimize a web page for faster and better experience

Posted on in Categories Apache, High performance computing, Howto, lighttpd, Linux, Tips, Tuning, UNIX last updated August 4, 2007

You may have noticed that most my webpage are loading bit faster. Here is what I did:

a) CSS code moved to its own file and included CSS at the top

b) Removed unnecessary (read as fancy web 2.0 stupid stuff) external javascript snippets

c) I’ve moved external javascript to bottom of page/template engine. For example google analytics JS code moved to bottom of webpage.

d) Turn on Apache gzip/mod_deflate compression

e) Turn on WordPress caching

f) Turn on php script caching (I’m using eAccelerator)

g) Tweak MySQL for optimization. Turn on query cache and other settings.

h) If possible switch to lighttpd or use squid / lighttpd as caching server for old good Apache.

If you have tons of cash to burn (assuming that your web app demands performance):

  • Consider using CDN (Content Delivery Network) such as Akamai or SAVVIS.
  • Server load balancing

However there are some external JS script snippets such as Google Adsense which slows down loading of a webpage. In few months I may roll out a new template and I will try to fix this issue :)

I’m interested to know what other people’s experiences with web page optimization. Feel free to share your tips.

Linux success story – Using Linux at Work

Posted on in Categories Beyond nixCraft, Linux desktop, Linux distribution, News last updated December 27, 2007

Yet another Linux success story, from the article:

I am by no stretch of the imagination a Linux expert, but my overall experience has been excellent and I shall continue to use Fedora for my day to day work. My productivity has not been affected at all, and anyone who wants to try something different, or take a cheaper OS route, should consider a look at Linux – it’s really not that scary.

I’ve been programming since a young age, and Linux has always seemed like a natural progression, especially as my development environment is PHP/MySQL/Apache. A while ago, this was all done on a Red Hat installed system, using the “Plesk” web interface. Although I spent quite a few hours at the console sorting out problems, Plesk hid the real nitty gritty from me and I was often just following “How Tos” in order to get things fixed. In saying that, I did manage to write a wrapper script that fixed a compatibility between MailMan and Plesk, so I wasn’t doing too badly. However, I would hardly say I felt confident in Linux, and using it for my day to day work seemed strangely frightening.

Read more, Using Linux at Work…

Lighttpd: Beware of Default PHP Session Path Permission [ session.save_path ]

Posted on in Categories lighttpd, php, Squid caching server, Troubleshooting last updated February 1, 2011

Session support in PHP consists of a way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site.
Continue reading “Lighttpd: Beware of Default PHP Session Path Permission [ session.save_path ]”

Howto: Performance Benchmarks a Webserver

Posted on in Categories Apache, FreeBSD, Howto, lighttpd, Linux, Networking, Troubleshooting, UNIX, Windows server last updated November 13, 2008

You can benchmark Apache, IIS and other web server with apache benchmarking tool called ab. Recently I was asked to performance benchmarks for different web servers.

It is true that benchmarking a web server is not an easy task. From how to benchmark a web server:

First, benchmarking a web server is not an easy thing. To benchmark a web server the time it will take to give a page is not important: you don’t care if a user can have his page in 0.1 ms or in 0.05 ms as nobody can have such delays on the Internet.

What is important is the average time it will take when you have a maximum number of users on your site simultaneously. Another important thing is how much more time it will take when there are 2 times more users: a server that take 2 times more for 2 times more users is better than another that take 4 times more for the same amount of users.”

Here are few tips to carry out procedure along with an example:
Continue reading “Howto: Performance Benchmarks a Webserver”