Quantcast
Channel: Two Zero Three » CentOS
Viewing all articles
Browse latest Browse all 2

Installing PHP from source

$
0
0

Everything in this post assumes a 64 bit CentOS system and all commands to be entered at the console will be in italics.

Before downloading and installing the PHP source, it’s a good idea to remove any traces of PHP that might be installed by default via the packages system. We can see if we have any PHP packages by using the command yum list installed php*, if you find PHP is installed on your system you can use the command yum erase php* to remove it.

On the Rackspace Cloud VPS I use to double check these posts, PHP is not installed by default so I have a clean sheet to play with.

Before we can install PHP, we need to install libmcrypt from source, the reasons behind this are that libmcrypt is not available via the standard set of package repositories, and it’s required by one of the options we’ll be using to configure PHP.

So first, as root user, download the source with -

wget http://switch.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

If that’s gone well, running the command ls -al should show something like this -

[root@osprey ~]# ls -al
total 1344
dr-xr-x—. 2 root root 4096 Oct 4 09:39 .
drwxr-xr-x. 22 root root 4096 Oct 4 09:25 ..
-rw——- 1 root root 27 Oct 4 09:24 .bash_history
-rw-r–r–. 1 root root 18 May 20 2009 .bash_logout
-rw-r–r–. 1 root root 176 May 20 2009 .bash_profile
-rw-r–r–. 1 root root 176 Sep 23 2004 .bashrc
-rw-r–r–. 1 root root 100 Sep 23 2004 .cshrc
-rw-r–r– 1 root root 1335178 Feb 19 2007 libmcrypt-2.5.8.tar.gz
-rw-r–r–. 1 root root 129 Dec 3 2004 .tcshrc
[root@osprey ~]#

We now unpack this file with tar xvf libmcrypt-2.5.8.tar.gz

CD to the directory where the file has been unpacked – cd libmcrypt-2.5.8

Before we can compile and install libmcrypt, we need to install a few packages to enable the process

yum install gcc gcc-c++ make

If that’s gone cleanly, we can then

./configure –prefix=/usr –libdir=/usr/lib64 –mandir=/usr/share/man

make

make install

Now to PHP, first CD back to your root directory -

cd ..

wget http://uk.php.net/get/php-5.4.7.tar.gz/from/this/mirror

tar xvf php-5.4.7.tar.gz

cd php-5.4.7

yum install libxml2-devel openssl-devel bzip2-devel libcurl-devel libpng-devel

./configure –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 –mandir=/usr/share/man –infodir=/usr/share/info –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-libdir=lib64 –with-openssl –with-zlib –with-bz2 –with-curl –with-gd –enable-ftp –enable-mbstring –with-mcrypt –with-mysql –with-mysqli –with-pdo-mysql –enable-zip –enable-fpm –disable-debug

Note: If you’re installing PHP for use with Apache, use the following -

yum install libxml2-devel openssl-devel bzip2-devel libcurl-devel libpng-devel httpd httpd-devel

./configure –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 –mandir=/usr/share/man –infodir=/usr/share/info –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-libdir=lib64 –with-openssl –with-zlib –with-bz2 –with-curl –with-gd –enable-ftp –enable-mbstring –with-mcrypt –with-mysql –with-mysqli –with-pdo-mysql –enable-zip –enable-fpm –disable-debug –with-apxs2=/usr/sbin/apxs

make

make install

cp php.ini-production /etc/php.ini

If everything’s gone well so far you should see the following when typing php -v

[root@osprey conf]# php -v
PHP 5.4.7 (cli) (built: Oct 4 2012 10:26:40)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
[root@osprey conf]#

To test that PHP is working with Apache, create a file called phpinfo.php in your default Apache web folder (usually /var/www/html) with the following content -

<?php
phpinfo();
?>

You may need to add the following lines to your httpd.conf file and restart Apache to get things working.

AddHandler php5-script .php
AddType text/html .php

When browsing to <server IP>/phpinfo.php you should see a web page showing the configuration of PHP.

The post Installing PHP from source appeared first on Two Zero Three.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images