In Linux, installing Apache2 and PHP5 is easy. Always there is a related package to your distribution. But in many case, you’re not gonna prefer that environment. Because there may be some compile-time limits in your environment. For example, in Ubuntu, Apache2 comes with 256 ServerLimit configuration.
# apt-get install apache2 php5
Yesterday, I compiled Apache2 and PHP5 from source code to solve some performance problems for a media company and I’m gonna share compiling Apache2 and PHP5 parts with you.
If you don’t optimize your web server your web site will never work stable whatever your server specification is. Yesterday, when I hear the website working slowly, first I checked error logs. There are so many errors on the pages. Remember, you need to fix these errors before you apply a specific performance tuning.
When all errors gone away web site were still slow. So, I had to do something about that! This article is not for performance tuning. Because of that I won’t touch on tuning details.
There is a powerful server with Dual CPU and 8GB RAM. In that case, that server is web server and runs static pages 90 percent.
As I said before, there is a compile-time limit in Apache2 which is installed by apt-get in Ubuntu. To solve that problem I compiled Apache2 from source code with PHP5. Here are the instructions:
- Download Apache2 source from official web site.
- Unpack the source code.
ServerLimit is a compile-time option and it’s located in MPM (Multi-Processing Module) scripts. If you want to set that option you need to open prefork.c file which is located in /server/mpm/prefork directory in your Apache2 source directory and find DEFAULT_SERVER_LIMIT definition and change it to value you want to.
# ./configure –enable-so –enable-cgi –enable-info –enable-rewrite –enable-speling –enable-usertrack –enable-deflate –enable-ssl –enable-mime-magic
You have to install some extra packages to complete configure command with these options such as SSL, Deflate. You can use apt-get to install extra packages.
When you complete configure successfully it’s time to run make command. make will take times and then, you have to run make install to install Apache2. If you don’t use –prefix option in configure Apache2 will be installed into default directory. It’s probably /usr/local/apache2.
So, we’re completed to install Apache2. It’s PHP’s turn now.
- Download PHP5 source from official web site.
- Unpack source code.
./configure –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql –prefix=/usr/local/apache2/php –with-config-file-path=/usr/local/apache2/php –disable-cgi –with-zlib –with-gettext –with-gd –enable-ftp
You have to install some extra packages to complete configure command with these options such as MySQL, GD, ZLib.
When you complete configure successfully it’s time to run make command. make will take times and then, you have to run make install to install PHP5.
cp php.ini-recommended /usr/local/apache2/php/php.ini
In my case, these modules were required. You may want to change configure options.
If you completed to install successfully Apache2 and PHP5, you need to make some modifications in Apache2 configuration.
AddHandler php5-script php
DirectoryIndex index.php index.html
AddType text/html php
Now you have your own compiled Apache2 and PHP5.