X

Compiling PHP from source on CentOS

PHP

PHP is a  open source scripting language, commonly used for web development. The code is executed on the server before being displayed to clients unlike other languages like JavaScript.  PHP can also be used for command line actions as well and has a wide range of libraries and frameworks for it.  This guide is  how to install PHP from source. Compiling packages from source can offer complete control on the build you have installed on your server, it can also allow to control the path its installed on. This also makes it easier to upgrade to newer releases, you would just compile a newer version and install it.

To start ssh to your server

Install dependencies through yum:

yum install -y wget gcc libxml2-devel openssl openssl-devel openssl-libs curl libcurl-devel libjpeg-turbo-devel libpng-devel freetype-devel libmcrypt libmcrypt-devel libxslt libxslt-devel

Obtain the PHP source package:

For this guide we are going to use the 5.6 release branch:

wget -O /usr/src/php-5.6.30.tar.gz http://php.net/get/php-5.6.30.tar.gz/from/this/mirror

Or select another mirror to download it from.

Unzip the compressed package:

cd /usr/src; tar xfvz php-5.6.30.tar.gz

Go into the directory:

cd php-5.6.30

Install the package:

Configure the package:

./configure  --with-mysql --with-mysqli --with-pdo-mysql --enable-soap --with-gd --with-curl --with-jpeg-dir=/opt --with-png-dir=/opt --with-freetype-dir=/opt --with-zlib --enable-mbstring --with-mcrypt=/usr/local/lib --with-xsl --with-openssl  --enable-ftp --enable-exif --with-apxs2=/usr/sbin/apxs

The above configuration line assumes you have Apache installed, if not remove  –with-apxs2=/usr/sbin/apxs. In this example we are just letting php install in the default location, however you can specific where you would like to install.

Install it:

make && make install

Make sure it works:

php -v

The above command should return the version of php you have installed.

Enable PHP in Apache

Add the following line to your apache configuration:

LoadModule php5_module        lib/apache/libphp5.so

Restart apache:

service httpd restart

To edit the default configuration file’s location by typing the following

php -i|grep php.ini

It will return the path and file it is using and you can edit it to add more configuration options.  Check out Zend OpCache to add more performance to your installation.

LinuxAdmin.io
1 1 vote
Article Rating
LinuxAdmin.io:

View Comments (3)

  • Right here is the perfect blog for anybody who would like to understand this topic. You know a whole lot its almost hard to argue with you (not that I really will need to…HaHa). You definitely put a new spin on a topic that's been discussed for ages. Great stuff, just excellent!

Related Post