Install apache httpd with php support

From PVPGN

Revision as of 23:35, 19 March 2009 by Supermarine9 (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Installing apache httpd with php support from sources on linux

This article is optional for a working pvpgn server, but it's a must for every pvpgn admin that want's to run a website for his server and for it's players.

The easy part - getting the sources

First of all we need to get the apache httpd webserver sources
and then the php sources. Let's do the trick:

  • you can get apache httpd webserver from:
http://httpd.apache.org/download.cgi

*at the moment of writing this the latest version is 2.2.8
*i recommend using the 2.2 branch due to the fact that is the most advanced version of them all.

  • you can get the php sources from:
http://www.php.net/downloads.php#v5

*at the moment of writing this the latest version is 5.2.6
*i recommend using the 5 branch due to the fact that version 4 branch will not be continued.

After getting the sources you can upload them to your host
( if you downloaded them on your working station with WinSCP )
or you can move them ( if you downloaded them on server ) to /usr/src/ directory.
Once the file where moved you must unpack them ( using tar ) like:

[root@mybox]#tar xf httpd-2.2.8.tar.gz
[root@mybox]#tar xf php-5.2.6.tar.gz

After unpacking them you'll have 2 new folder with the following names:

/usr/src/httpd-2.2.8/
/usr/src/php-5.2.6/

The not so easy part - compiling / installing

After we have done all the above things is time to start compiling apache httpd. We must enter the httpd source directory:

[root@mybox]#cd /usr/src/httpd-2.2.8/

Now we can issue the configure command:

[root@mybox]#./configure --prefix=/opt/apache228 --enable-mods-shared=most --enable-so --enable-cache --enable-file-cache --enable-disk-cache --enable-mem-cache

*use --prefix parameter to install apache httpd to a specified directory ( in our case /opt/apache228 )
*use --enable-mods-share=most parameter to force compiling to create almost all the modules ( in our case will be all the modules that we'll ever need )
*use --enable-so parameter to enable the binary modules support ( in our case will be php )
*use all the cache parameters to improve your website load times and lower your machine load ( on high loaded servers )

If everything will be fine you'll be able to issue the make and make install commands:

[root@mybox]#make
[root@mybox]#make install

Now you should be able to start your webserver by issuing the commands:

[root@mybox]#apachectl start - if you compiled without the --prefix parameter

or

[root@mybox]#/opt/apache228/bin/apachectl start - if you used the --prefix=/opt/apache228/ parameter

If everything was done correctly, after the issuing one of the above
commands your cursor should be similar:

[root@mybox]# 

If not you should get some errors or warnings ( warnings are not so harmfully but still not ok )
You can also check the logs from apache by opening the error_log file from the logs directory created
by apache httpd installation ( in our example this would be /opt/apache228/logs/ )
You can check to see if apache httpd is running in background using the following command:

[root@mybox]#ps ax | grep httpd

If the httpd server is running you should get similar output:

[root@mybox]#ps ax | grep httpd
26073 ?        Ss     0:00 /opt/apache228/bin/httpd -k start
16670 ?        S      0:01 /opt/apache228/bin/httpd -k start
16837 ?        S      0:00 /opt/apache228/bin/httpd -k start
16838 ?        S      0:01 /opt/apache228/bin/httpd -k start
16839 ?        S      0:00 /opt/apache228/bin/httpd -k start
16841 ?        S      0:00 /opt/apache228/bin/httpd -k start
16842 ?        S      0:00 /opt/apache228/bin/httpd -k start
16843 ?        S      0:00 /opt/apache228/bin/httpd -k start
16846 ?        S      0:00 /opt/apache228/bin/httpd -k start
16848 ?        S      0:01 /opt/apache228/bin/httpd -k start
16998 ?        S      0:00 /opt/apache228/bin/httpd -k start
30228 pts/1    R+     0:00 grep httpd

If all above are ok, you can test it by entering in your browser address bar the ip / dns of your server:
(we'll assume that your server has a public ip address and will assume that the address is 10.10.10.250 -
don't start yelling, i know that this isn't possible for real but we assume )

http://10.10.10.250/

or

http://your.dns.record/
default page that inform us about the running httpd server
default page that inform us about the running httpd server

Now we can shutdown the httpd server for the moment by issuing:

[root@mybox]#apachectl stop - if you compiled without the --prefix parameter

or

[root@mybox]#/opt/apache228/bin/apachectl stop - if you used the --prefix=/opt/apache228/ parameter

Now it's time for php! We must exit the apache httpd source directory:

[root@mybox]#cd ../

and enter the php source directory:

[root@mybox]#cd php-5.2.6/

Now we must start the compiling thing:

[root@mybox]#./configure --prefix=/opt/php526/ \
>--with-apxs=/path/to/apache/bin/folder/apxs \
>--with-mysql=/path/to/mysql \
>--enable-fastcgi \
>--enable-calendar \
>--enable-bcmath \
>--enable-exif \
>--enable-mbstring \
>--with-gettext \
>--with-gd \
>--with-pear

*use --prefix parameter to install php to a specified directory ( in our case /opt/php526 )
*use --with-apxs to specify the apache httpd apxs binary ( if you installed apache by using the --prefix parameter )
*use --with-mysql to specify the mysql installation path ( if installed by using the --prefix parameter - check Install_on_unix_from_sources )
*use all other --enable and --with parameters to compile php with the added usability offered by those parameters

If everything went well you can start compiling and installing php:

[root@mybox]#make
[root@mybox]#make install

If everything went well the next thing is copying a php.ini file from the source directory
to the /lib/ directory or to the /lib/ directory inside the directory entered on parameter --prefix:

[root@mybox]#mv php.ini-recommended php.ini     - renaming the included php.ini to the usable name
[root@mybox]#cp php.ini /lib/                   - copy to the lib directory if install path is default 

or

[root@mybox]#cp php.ini /opt/php526/lib/php.ini - copy to the lib directory from the install path configured with the --prefix parameter

At this time there is no need to configure anything more in php.ini, but in time, if you want to take
full advantage of you machine and your software then you should take a look inside that file. The install
script will use apxs binary to make the necessary changes in the httpd config file to include the php
binary module. The last thing you have to do is to open the httpd config file ( in our example it is located
in /opt/apache228/conf/httpd.conf ) and add the following lines:

look for:

<IfModule dir_module> 
    DirectoryIndex index.html
</IfModule>

and change to:

<IfModule dir_module> 
    DirectoryIndex index.html index.php
</IfModule>

look for:

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

and change to:

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php

and after that save and close the httpd.conf file.

Now you can start again your httpd server and go to the htdocs directory ( in our case it is /opt/apache228/htdocs )
and create an empty file ( which in this tutorial we'll call it phpinfo.php ) in which you must write:

<?
phpinfo();
?>

and save the file.

If the installation was a success you will be able to tell by pointing your browser to:

http://10.10.10.250/phpinfo.php

or

http://your.dns.record/phpinfo.php

If you had done everything right you should get similar output:

page output of phpinfo() function
page output of phpinfo() function

If you see this you have successfully compiled and installed apache httpd webserver
with php module support and mysql database integration.