Installing httpd and PHP on Centos 5
Introduction
Apache is the software that allows websites to be displayed through a web browser such as Microsoft Internet explorer, Mozilla Firefox, Opera and Google Chrome etc. Apache on its own can only display HTML (Hyper Text Mark-up Language) Files.
PHP allows you to run server side code, Web Applications, Dynamic Websites can be run or created on the server. Many websites use PHP such as Facebook, Wikipedia, Yahoo, Digg, Joomla, WordPress, Drupal etc.
PHP is required to run many Web Applications, such as
Blogs:
- Wordpress
Galleries:
- Gallery
- Camera Life
Forums:
- phpBB
- Invision Power Board
- PHP Forum Script
Content Management Systems:
- PHPNuke
- Drupal
- PHP-Fusion
Tools:
- Webmin
- Drupal
- Squirrel Mail
PHP doesn’t just run with Apache, you can use PHP to run code at the command line too.
Installation
[root@vps ~]# yum install httpd php php-mysql
N.B Dont worry if what comes up on your screen is different to this. Software Versions and dependencies change.
Setting up Install Process Setting up repositories update 100% |=========================| 951 B 00:00 base 100% |=========================| 1.1 kB 00:00 addons 100% |=========================| 951 B 00:00 extras 100% |=========================| 1.1 kB 00:00 Reading repository metadata in from local files Parsing package install arguments Resolving Dependencies --> Populating transaction set with selected packages. Please wait. ---> Downloading header for php to pack into transaction set. php-4.3.9-3.29.i386.rpm 100% |=========================| 26 kB 00:00 ---> Package php.i386 0:4.3.9-3.29 set to be updated ---> Downloading header for httpd to pack into transaction set. httpd-2.0.52-41.ent.6.cen 100% |=========================| 65 kB 00:00 ---> Package httpd.i386 0:2.0.52-41.ent.6.centos4 set to be updated ---> Downloading header for php-mysql to pack into transaction set. php-mysql-4.3.9-3.29.i386 100% |=========================| 21 kB 00:00 ---> Package php-mysql.i386 0:4.3.9-3.29 set to be updated --> Running transaction check --> Processing Dependency: apr >= 0.9.4-24.2 for package: httpd --> Processing Dependency: file >= 4.0 for package: php --> Processing Dependency: /usr/share/magic.mime for package: httpd Importing Additional filelist information for dependency resolution filelists.xml.gz 100% |=========================| 2.5 MB 00:01 update : ################################################## 538/538 filelists.xml.gz 100% |=========================| 1.9 MB 00:00 base : ################################################## 1599/1599 filelists.xml.gz 100% |=========================| 183 B 00:00 filelists.xml.gz 100% |=========================| 71 kB 00:00 extras : ################################################## 141/141 --> Processing Dependency: libaprutil-0.so.0 for package: httpd --> Processing Dependency: libidn.so.11 for package: php --> Processing Dependency: /etc/mime.types for package: httpd --> Processing Dependency: libaspell.so.15 for package: php --> Processing Dependency: httpd-suexec for package: httpd --> Processing Dependency: libpspell.so.15 for package: php --> Processing Dependency: php-pear for package: php --> Processing Dependency: libapr-0.so.0 for package: httpd --> Processing Dependency: libcurl.so.3 for package: php --> Restarting Dependency Resolution with new changes. --> Populating transaction set with selected packages. Please wait. ---> Downloading header for file to pack into transaction set. file-4.10-8.el4.i386.rpm 100% |=========================| 10 kB 00:00 ---> Package file.i386 0:4.10-8.el4 set to be updated ---> Downloading header for php-pear to pack into transaction set. php-pear-4.3.9-3.29.i386. 100% |=========================| 47 kB 00:00 ---> Package php-pear.i386 0:4.3.9-3.29 set to be updated ---> Downloading header for curl to pack into transaction set. curl-7.12.1-11.1.el4_8.2. 100% |=========================| 10 kB 00:00 ---> Package curl.i386 0:7.12.1-11.1.el4_8.2 set to be updated ---> Downloading header for aspell to pack into transaction set. aspell-0.50.5-4.EL4.i386. 100% |=========================| 16 kB 00:00 ---> Package aspell.i386 12:0.50.5-4.EL4 set to be updated ---> Downloading header for libidn to pack into transaction set. libidn-0.5.6-1.i386.rpm 100% |=========================| 7.2 kB 00:00 ---> Package libidn.i386 0:0.5.6-1 set to be updated ---> Downloading header for httpd-suexec to pack into transaction set. httpd-suexec-2.0.52-41.en 100% |=========================| 24 kB 00:00 ---> Package httpd-suexec.i386 0:2.0.52-41.ent.6.centos4 set to be updated ---> Downloading header for mailcap to pack into transaction set. mailcap-2.1.17-1.noarch.r 100% |=========================| 5.0 kB 00:00 ---> Package mailcap.noarch 0:2.1.17-1 set to be updated ---> Downloading header for apr to pack into transaction set. apr-0.9.4-24.9.el4_8.2.i3 100% |=========================| 7.7 kB 00:00 ---> Package apr.i386 0:0.9.4-24.9.el4_8.2 set to be updated ---> Downloading header for apr-util to pack into transaction set. apr-util-0.9.4-22.el4_8.2 100% |=========================| 5.5 kB 00:00 ---> Package apr-util.i386 0:0.9.4-22.el4_8.2 set to be updated --> Running transaction check --> Processing Dependency: aspell-en for package: aspell --> Restarting Dependency Resolution with new changes. --> Populating transaction set with selected packages. Please wait. ---> Downloading header for aspell-en to pack into transaction set. aspell-en-0.51-11.i386.rp 100% |=========================| 4.4 kB 00:00 ---> Package aspell-en.i386 50:0.51-11 set to be updated --> Running transaction check Dependencies Resolved ============================================================================= Package Arch Version Repository Size ============================================================================= Installing: httpd i386 2.0.52-41.ent.6.centos4 update 903 k php i386 4.3.9-3.29 update 1.3 M php-mysql i386 4.3.9-3.29 update 38 k Installing for dependencies: apr i386 0.9.4-24.9.el4_8.2 update 93 k apr-util i386 0.9.4-22.el4_8.2 update 52 k aspell i386 12:0.50.5-4.EL4 base 320 k aspell-en i386 50:0.51-11 base 1.9 M curl i386 7.12.1-11.1.el4_8.2 update 231 k file i386 4.10-8.el4 base 259 k httpd-suexec i386 2.0.52-41.ent.6.centos4 update 31 k libidn i386 0.5.6-1 base 169 k mailcap noarch 2.1.17-1 base 14 k php-pear i386 4.3.9-3.29 update 483 k Transaction Summary ============================================================================= Install 13 Package(s) Update 0 Package(s) Remove 0 Package(s) Total download size: 5.7 M Is this ok [y/N]:
Dont worry about the extra packages showing up in the list, these extras are required to make PHP and Apache work.
Press Y and then Enter.
Downloading Packages: (1/13): file-4.10-8.el4.i 100% |=========================| 259 kB 00:00 (2/13): httpd-2.0.52-41.e 100% |=========================| 903 kB 00:01 (3/13): php-pear-4.3.9-3. 100% |=========================| 483 kB 00:00 (4/13): curl-7.12.1-11.1. 100% |=========================| 231 kB 00:00 (5/13): aspell-0.50.5-4.E 100% |=========================| 320 kB 00:00 (6/13): libidn-0.5.6-1.i3 100% |=========================| 169 kB 00:00 (7/13): httpd-suexec-2.0. 100% |=========================| 31 kB 00:00 (8/13): php-4.3.9-3.29.i3 100% |=========================| 1.3 MB 00:01 (9/13): mailcap-2.1.17-1. 100% |=========================| 14 kB 00:00 (10/13): apr-0.9.4-24.9.e 100% |=========================| 93 kB 00:00 (11/13): aspell-en-0.51-1 100% |=========================| 1.9 MB 00:00 (12/13): apr-util-0.9.4-2 100% |=========================| 52 kB 00:00 (13/13): php-mysql-4.3.9- 100% |=========================| 38 kB 00:00 Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing: apr ####################### [ 1/13] Installing: libidn ####################### [ 2/13] Installing: file ####################### [ 3/13] Installing: curl ####################### [ 4/13] Installing: apr-util ####################### [ 5/13] Installing: mailcap ####################### [ 6/13] Installing: aspell ####################### [ 7/13] Installing: httpd ####################### [ 8/13] Installing: httpd-suexec ####################### [ 9/13] Installing: aspell-en ####################### [10/13] Installing: php ####################### [11/13] Installing: php-pear ####################### [12/13] Installing: php-mysql ####################### [13/13] Installed: httpd.i386 0:2.0.52-41.ent.6.centos4 php.i386 0:4.3.9-3.29 php-mysql.i386 0:4.3.9-3.29 Dependency Installed: apr.i386 0:0.9.4-24.9.el4_8.2 apr-util.i386 0:0.9.4-22.el4_8.2 aspell.i386 12:0.50.5-4.EL4 aspell-en.i386 50:0.51-11 curl.i386 0:7.12.1-11.1.el4_8.2 file.i386 0:4.10-8.el4 httpd-suexec.i386 0:2.0.52-41.ent.6.centos4 libidn.i386 0:0.5.6-1 mailcap.noarch 0:2.1.17-1 php-pear.i386 0:4.3.9-3.29 Complete!
Now that Yum has completed installing Apache and PHP, we just need to create a system start-up link, so that Apache starts when the server does. PHP doesn't need this doing, as it utilised when Apache needs it.
[root@vps ~]# chkconfig httpd on
Finally all we need to do is to start Apache
[root@vps ~]# service httpd start Starting httpd: [ OK ]
You can check to make sure its working by going to your server IP in your web browser.

You should see the Apache test page.
Basic Configuration Httpd
The apache config file is located /etc/httpd/conf/httpd.conf
At this stage there isn't really anything that needs changing in the config file, except maybe the server email address.
Editing the config file with vi (vi is a text editor) for more information about text editors click here
[root@vps ~]# vi /etc/httpd/conf/httpd.conf
if you wish to add your email address, find
# # ServerAdmin: Your address, where problems with the server should be # e-mailed. This address appears on some server-generated pages, such # as error documents. e.g. admin@your-domain.com # ServerAdmin root@localhost
Update root@localhost and then save the file.
If you make any changes to the config file, you will need to restart httpd.
[root@vps ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
Basic Configuration PHP
The PHP config file can be found /etc/php.ini. At this time there isn't anything that needs changing as part of the basic setup. However if you do need to change any settings with in PHP then its the same process as described in Basic Configuration Httpd but with the path to php.ini instead.

