This post is the third in the series of setting up a Centos 6 VPS without WHM/cPanel (or any other panel). The previous post is setting up MySQL Database server. This post will list the steps to install MySQL and PHP on Centos 6.
The latest version of PHP at the time of writing this post is 5.6. Please adjust the command if installing different version.
First, download the PHP source from the nearest mirror and unpack it.
tar zxvf php-5.6.0.tar.gz
Note that Apache needs to be installed first before continuing the next step. If Apache is already installed and running, stop it first before configuring PHP installation.
Next, configure and install PHP
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-pdo-mysql --with-mysqli --enable-mbstring --with-bz2 --with-zlib --with-curl --enable-exif --with-gd --with-gettext --with-pear --enable-zip --with-mcrypt --with-jpeg-dir=/usr --with-png-dir=/usr --with-openssl --enable-intl
During my installation, I’ve got the following error when after I run the second line above
configure: error: xml2-config not found. Please check your libxml2 installation.
This only means that I don’t have the libxml2 library installed. So I install the livxml2 library using yum first before running ./configure again. Also install the libicu for intl.
yum install libxml2-devel
yum install libicu-devel
Once PHP is installed, copy the php.ini-development or php.ini-production to /usr/local/lib/
cp php.ini-development /usr/local/lib/php.ini
cp php.ini-production /usr/local/lib/php.ini
Edit the php.ini file to set timezone, post_max_size, upload_max_filesize.
Edit httpd.conf file and ensure the following line is uncommented
LoadModule php5_module modules/libphp5.so
Add the following lines to https.conf to tell Apache to parse files with .php extension as PHP.