Building PHP 5.4.3 on CentOS

Even though it’s easier to use yum, sometimes we need to compile PHP from source code. Below I’ll describe a method for compiling PHP 5.4.3 on CentOS, this works both on 5.x and 6.x and all the dependencies (except for PHP itself, of course ) will be retrieved via yum.

After a fresh install of CentOS, we will need the wget binary, if you don’t already have it, get it with yum.
yum install wget -y


For some of the dependencies to get installed, we’ll need the rpmforge repository, so let’s add it.
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm

rpm -i rpmforge-release-0.5.2-2.el5.rf.*.rpm

Now let’s install the dependencies for our PHP compilation. Keep in mind that these are only for the configuration I’ll describe below, if you use a different compilation, you’ll need to get different packages. Also keep in mind that here I’ll only download the x86_64 packages, if you’re using a different architecture, just delete the x86_64 on every package name that contains it. The reason I specifically used that notation is to avoid downloading i386 packages, which is unnecessary but yum insists on downloading anyway.
yum install gcc make automake autoconf perl.x86_64 httpd-devel.x86_64 libxml2-devel.x86_64 openssl-devel.x86_64 pcre-devel.x86_64 bzip2-devel.x86_64 curl-devel.x86_64 enchant-devel.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 libXpm-devel.x86_64 freetype-devel.x86_64 gmp-devel.x86_64 libicu-devel.x86_64 gcc-c++ libmcrypt-devel.x86_64 postgresql-devel.x86_64 aspell-devel.x86_64 libedit-devel.x86_64 recode-devel.x86_64 net-snmp-devel.x86_64 libtidy-devel.x86_64 libxslt-devel.x86_64 libcurl-devel.x86_64 libtool-ltdl-devel.x86_64 -y


Now let’s download the php 5.4.3 source code.
wget http://tr.php.net/get/php-5.4.3.tar.gz/from/this/mirror
tar xvzf php-5.4.3.tar.gz
cd php-5.4.3


We can start the configure-make-make install trio now.
./configure  --with-apxs2=/usr/sbin/apxs --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --target=x86_64-redhat-linux-gnu --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --cache-file=../config.cache --with-libdir=lib64 --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --disable-debug --with-pic --disable-rpath --with-bz2 --with-freetype-dir=/usr --with-png-dir=/usr --with-xpm-dir=/usr --enable-gd-native-ttf --without-gdbm --with-gettext --with-gmp --with-iconv --with-jpeg-dir=/usr --with-openssl --with-pcre-regex=/usr --with-zlib --with-layout=GNU --enable-exif --enable-ftp --enable-sockets --enable-sysvsem --enable-sysvshm --enable-sysvmsg --with-kerberos --enable-shmop --enable-calendar --with-libxml-dir=/usr --enable-xml --enable-pcntl --with-imap-ssl --enable-mbregex --enable-bcmath=shared --enable-dba=shared --with-db4=/usr --with-xmlrpc=shared --with-mysql --with-mysqli --enable-dom=shared --with-pgsql --enable-wddx=shared --with-snmp=shared,/usr --enable-soap=shared --with-xsl=shared,/usr --enable-xmlreader=shared --enable-xmlwriter=shared --with-curl --enable-json --enable-zip=shared --without-readline --with-libedit --with-pspell=shared --enable-phar=shared --with-tidy=shared,/usr --enable-sysvmsg=shared --enable-sysvshm=shared --enable-sysvsem=shared --enable-posix=shared --enable-fileinfo=shared --enable-intl=shared --with-icu-dir=/usr --with-enchant=shared,/usr --with-recode=shared,/usr --enable-mbstring --with-mcrypt --with-gd
make
make install


Now we have php installed.

Further we can configure the basic steps of Apache.
Edit your httpd.conf file : /etc/httpd/conf/httpd.conf
Find the line that says AddType application/x-tar .tgz Append these two lines below it.

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Also we should tell apache that index.php is an index file (or whatever index you want), so update your DirectoryIndex as following :

DirectoryIndex index.html index.html.var index.php index.htm

copy php.ini-production to /etc/php.ini and edit the file based on your performance requirements, please have a look at our security pages to secure your php configuration from the link.

Some suggestions: Increase upload limit, raise memory_limit to 256M and set date.timezone to your location, in our case it is:

date.timezone = Europe/Istanbul

After saving and exiting the httpd.conf file, restart your Apache services. ( service httpd restart )

Now you have /var/www/html as your default web home root, and PHP 5.4.3 running on it.
  • 98 Користувачі, які знайшли це корисним
Ця відповідь Вам допомогла?

Схожі статті

Setting time with NTP in LINUX

NTP (Network Time Protocol) could be used to set time synced with ntp clocks, to do this use the...

Linux version & Operating System info

LINUX Version Info To learn the architecture and kernel version info use the shell command...

Compile and build Apache + MySQL + PHP from the source [cite]

This is a complete working solution to build Apache (httpd-2.2.25), MySQL (MySQL-5.6.14) and PHP...

Using vi Editor

Vi is the one of the mostly used editor in Linux via terminal. In most cases where Linux is used...

Build PHP5.5 on CentOS 6.4 with MSSQL Support [cite]

Most of the yum repos doesn’t include PHP5.5.X on current releases for the time being. So...