GIT – This tutorial explains the installation of 5, bundled with Apache and server on a (Centos 5) machine. We will set up PHP as a shared module, being loaded into Apache2 dynamically during the server start up.


 At this point Apache web server must be installed. If you want MySQL support in PHP, MySQL server also must have been installed prior to the next steps.

MySQL Installation:

yum mysql-server mysql mysql-devel

To start mysql

/etc/init.d/mysql start

For stopping mysql

/etc/init.d/mysql stop

For checking mysql current status

/etc/init.d/mysql status

Apache Installation

latest apache version from the Apache 2.2 download page .


Once the file is copied to the folder. Once the file is copied on the Linux server (example: /usr/local/install).

1. Use the following to extract the tar file.

cd /usr/local/install

tar -xzf httpd-2.2.23.tar.gz

A directory will be created “httpd-2.2.23″

2. Now, Let’s execute the configuration script:

cd /usr/local/install/httpd-2.2.23

./configure –prefix=/usr/local/install/apache –enable-mods-shared=all –enable-proxy –enable-expires –enable-vhost-alias –enable-ssl

3. The following steps will compile Apache based upon the configuration defined:


4. The following step will install the Apache build:

make install

5. Use the following commands to control the Apache Web Server.

/usr/local/install/apache/bin/apachectl -k stop

/usr/local/install/apache/bin/apachectl -k start

6. Go to the internet browser and try the url http://host:80/.

Known Issues:

1):        When starting the httpd process you may receive the following error :

Starting httpd: httpd: Could not reliably determine the server’s fully qualified domain name, using for ServerName


You might get this error when restarting Apache. To resolve the issue add the following to your httpd.conf file :


2):        httpd: Syntax error on line 95 of /usr/local/install/apache/conf/httpd.conf: Cannot load /usr/local/install/apache/modules/ into server: /usr/apache2/modules/ cannot restore segment prot after reloc: Permission denied


Set the as permissive by the following way and restart the mach

cat /etc/sysconfig/selinux
This file controls the state of SELinux on the system.
#SELINUX= can take one of these three values:
#enforcing – SELinux policy is enforced.
#permissive – SELinux prints warnings instead of enforcing.
#disabled – SELinux is fully disabled.
#SELINUXTYPE= type of policy in use. Possible values are:
#targeted – Only targeted network daemons are protected.
#strict – Full SELinux protection.
#SETLOCALDEFS= Check local definition changes

PHP Installation:

Download Source

Get the source from At the time of writing this tutorial the best available version was 5.4.3. php-5.4.3.tar.gz ).


Unpack, Configure, Compile

Go to the directory whith the downloaded file and enter:

# tar -xzf php-5.4.3.tar.gz

# cd php-5.4.3

Execute the follwinf commands for php installation with curl,soap,mycrpt etc

 # ./configure –with-apxs2=/usr/local/install/apache/bin/apxs –prefix=/usr/local/install/apache/php –with-config-file-path=/usr/local/install/apache/php –enable-force-cgi-redirect –enable-pic –with-curl=/usr –with-curlwrappers –enable-ftp –enable-shared –with-gd=/usr –with-bz2 –with-db4=/usr –with-freetype-dir=/usr –with-png-dir=/usr –enable-gd-native-ttf –with-gettext –with-iconv –with-jpeg-dir=/usr –with-openssl –with-png –without-gdbm –with-xml –with-xmlrpc=shared –with-zlib –with-mime-magic=/usr/share/file/magic.mime –with-mysqli=/usr/bin/mysql_config –with-mysql=/usr –with-regex=php –with-mcrypt –enable-soap

Now run the following commands

# make

# make install

Edit Httpd.conf

All necessary changes to httpd.conf (Apache configuration file) should have already been made automatically during the installation, so usually you need not do anything. Nevertheless, check that following lines were added to the httpd.conf file:

LoadModule php5_module modules/

AddType application/x-httpd-php .php

If not, add them manually.

Importantly, you have to create a php.ini configuration file. Choose one of the pre-made files (preferably

php.ini-recommended) residing inside the php-5.4.3/ directory (it’s the folder to which the downloaded archive was extracted). Copy the file to the lib/ directory in the PHP installation directory.

# cp php-5.2.1/php.ini-recommended =/usr/local/install/apache/php/lib/php.ini

If you need to, edit the php.ini file:

# vi =/usr/local/install/apache/php/lib/php.ini

However, the default settings should work for everyone in most cases.

Restart Apache Server

After everything is set up, restart Apache

Known problems when installing php

1. configure: error: Please reinstall the BZip2 distribution

# yum install bzip2-devel

2. configure: error: DBA: Could not find necessary header file(s).

# yum install gdbm-devel

# yum install db4-devel

3. configure: error: libjpeg.(a|so) not found.

# yum install libjpeg-devel

4. configure: error: libpng.(a|so) not found.

# yum install libpng-devel

5. configure: error: freetype.h not found.

# yum install freetype-devel

6. configure: error: Please reinstall the libcurl distribution

# yum install curl

# yum install curl-devel

7. configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

# yum install libxslt-devel >>>> fixed

8. xml2-config not found. Please check your libxml2 installation.

# yum install libxml2-devel

9. Kalau error Perl-URI

# wget

#rpm -i perl-URI-1.35-3.noarch.rpm

10. configure: error: utf8_mime2text() has new signature

# yum install libc-client-devel

11. configure: error: libXpm.(a|so) not found.

# yum install gd-devel


#up2date -i gd-devel

12. Configure: error: Cannot find OpenSSL’s

# yum install openssl-deve

13. Checking for PCRE headers location… configure: error: Could not find pcre.h in /usr

# yum install pcre-devel

14. Configure: error: Unable to locate gmp.h

# yum install gmp-devel

15. configure: error: Cannot find pspell

# yum install aspell-devel

16. The ‘links’ package is required for this functionality.

# yum search links

# yum install elinks

17. Error : [warn] module php5_module is already loaded, skipping

# edit httpd.conf terus Uncomment : #LoadModule php5_module modules/

18. configure: error: Did not find pcre-config script at /usr/local

# yum -y install pcre-devel

19. warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897

# rpm -import

ERROR:                        cannot restore segment prot after reloc: Permission denied


chcon -t texrel_shlib_t /etc/httpd/modules/

20.If this error occur

configure: error: mcrypt.h not found. Please reinstall libmcrypt

Then do this

Mycrpt Installation

 cd /usr/local/src
tar xvfz libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
make install

Print Friendly, PDF & Email



Bài viết liên quan