Links: Homepage | Downloads
Dependencies: Apache | LibJPEG | LibPNG | LibMCrypt | FreeType
Version: 5.5.3

PHP is a general-purpose server-side scripting language that is especially suited to web development.

Get the Code

Switch to /usr/local/src and download the source package.

cd /usr/local/src
curl --location --output php-VERSION.tar.gz

Extract the archive and move into the folder.

tar -xzvf php-VERSION.tar.gz
cd php-VERSION

Compile and Install

Configure, compile and install into /usr/local/php-VERSION.

./configure \
	--prefix=/usr/local/php-VERSION \
	--with-config-file-path=/usr/local/php-VERSION/etc \
	--enable-bcmath \
	--enable-mbstring \
	--enable-sockets \
	--enable-zip \
	--with-apxs2=/usr/local/apache/bin/apxs \
	--with-bz2 \
	--with-curl \
	--with-freetype-dir=/usr/local/freetype \
	--with-gd \
	--with-imap-ssl \
	--with-jpeg-dir=/usr/local/libjpeg \
	--with-mcrypt=/usr/local/libmcrypt \
	--with-mysql=mysqlnd \
	--with-mysqli=mysqlnd \
	--with-pear \
	--with-pdo-mysql=mysqlnd \
	--with-pgsql \
	--with-png-dir=/usr/local/libpng \
	--with-openssl \
	--with-xmlrpc \
	--with-xsl \
make install

Create a symbolic link that points /usr/local/php to /usr/local/php-VERSION.

ln -s php-VERSION /usr/local/php

PHP Configuration

Copy a PHP configuration template to the target folder.

cp php.ini-development /usr/local/php/etc/php.ini

You can configure any of the php.ini directives by editing this file.

Apache Configuration

Edit Apache's configuration file.

nano /usr/local/apache/conf/httpd.conf

Copy and paste the following text at the end of the aforementioned file.

<IfModule mime_module>
  AddType application/x-httpd-php .php


Execute the following lines to update your Bash startup script.

echo 'export PATH=/usr/local/php/bin:$PATH' >> ~/.bash_profile
echo 'export MANPATH=/usr/local/php/man:$MANPATH' >> ~/.bash_profile

Load the new shell configurations.

source ~/.bash_profile

Restart the Web Server

The web server must be restarted for the changes to take effect.

sudo /usr/local/apache/bin/apachectl -k restart

Verify the Installation

To verify that you have correctly installed PHP, execute the following command. It should display the version number along with other information.

php --version