Moving Beyond SSH: PHP

Published on Feb 5, 2009   //  Development
Off

Moving Beyond SSH

This week we’ll be installing PHP on our servers. PHP is a popular, open-source, server-side scripting language. It is one of the most commonly used programming language. It stands for PHP: Hypertext Preprocessor.

Alright, let’s start out by SSHing into our server, and getting the URL of the latest version of PHP 5.2 from the PHP downloads page (choose the .tar.gz file). First start by changing your working directory to /. Now, let’s download it to our server (replacing URL with the URL you got from the downloads page):

wget URL

Now we need to decompress the PHP files, which we do using these two commands (replace NN with the current version number):

gunzip php-NN.tar.gz
tar -xvf php-NN.tar

Before we get started with installing PHP, we need to stop Apache:

apachectl -k stop

Now, let’s change our directory to the one we extract (again replacing NN with the version of PHO you downloaded):

cd php-NN

Now, we need to configure the options for our PHP installation. We will be configuring it with MySQL, MySQL PDO and cURL support. We’re also adding in support for a couple extra libraries to support some tools we’ll be installing later on during the series. So, here’s our configuration command:

./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-curl --with-mcrypt --enable-mbstring --with-gd --enable-zip --with-bz2 --with-zlib

Now, we can start making the installation files:

make

After that’s completed, we can install PHP:

make install

We now need to copy a PHP configuration file to the system:

cp php.ini-recommended /usr/local/lib/php.ini

Now, we need to ensure that PHP gets loaded into Apache. Start off by opening up Apache’s configuration file:

nano /usr/local/apache2/conf/httpd.conf

Now, check to see if the following line was added to the file (if it wasn’t, add it yourself):

LoadModule php5_module modules/libphp5.so

Now, we need to tell Apache to process .php files as PHP. Add the following somewhere in Apache’s configuration file:


SetHandler application/x-httpd-php

Now, save that file by pressed Control-O and then hitting enter, then exit out of it by pressing Control-X.

After that, you can start Apache again:

apachectl -k restart

Congratulations, you have now installed PHP and will now be able to use PHP on your server.