How to Build a Web Server with PHP 5 and MySQL 5 Support

Configuring and Installing PHP 5

Now it is time for downloading, configuring and installing PHP 5. You must install MySQL 5 client BEFORE configuring PHP 5, otherwise you will get a series of error messages. So if you came directly to this page, please go back to the previous page and follow the steps described there.

Before compiling PHP 5, you need to install several dependencies, if they aren’t already installed. They are Zlib, Jpeg and Png. They are required if you want to run GD, which is a module for editing images on the fly. We recommend enabling GD support, thus we will install these three items:

For zlib, download its latest version at https://www.zlib.net/ and do:

cd /root
wget https://www.zlib.net/zlib-1.2.3.tar.gz
tar -xvzf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure –prefix=/usr/lib
make
make install

For png support, download Libpng at https://www.libpng.org/pub/png/libpng.html and do:

cd /root
wget https://prdownloads.sourceforge.net/libpng/libpng-1.2.16.tar.gz?download
tar -xvzf libpng-1.2.16.tar.gz
cd libpng-1.2.16
./configure –prefix=/usr/lib
make
make install

For Jpeg support:

cd /root
wget ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
tar -xvzf jpegsrc.v6b.tar.gz
cd jpegsrc.v6b
./configure –prefix=/usr/lib
make
make install

These are the support libraries for GD. On our installation on Debian, we needed to install the following libraries to solve dependency errors while compiling PHP 5:

Apt-get install libxml2
Apt-get install libxml2-dev
Apt-get install libxml2-utils
apt-get install autoconf
dpkg -s autoconf

Now it is time for downloading, configuring and compiling PHP. PHP can be downloaded from https://www.php.net/downloads.php. The step-by-step would be:

cd /root
wget https://www.php.net/get/php-5.2.1.tar.gz/from/us2.php.net/mirror
tar -xvzf php-5.2.1.tar.gz
cd php-5.2.1
./configure –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql=/usr/local/bin/mysql_config –with-mysqli=/usr/local/bin/mysql_config –prefix=/usr/local/apache2/php –with-config-file-path=/usr/local/apache2/php –with-zlib-dir=/usr/lib –with-gd –with-imap=/usr/local/imap-2004a –with-xml –enable-shmop –with-zlib –with-png –with-jpeg-dir=/usr/lib –enable-gd-native-ttf –enable-exif –with-kerberos –with-imap-ssl
make
make install
cp php.ini-dist /usr/local/apache2/php/php.ini

Of course this configuration is the one we needed based on the PHP scripts we were going to run; your configure line can be different.

The major trick here are the –with-mysql and –with-mysqli parameters. They must tell configure script the location of mysql_config file: it can be at /usr/local/bin/ or at /usr/local/mysql/bin, depending wether you installed only MySQL 5 client or both client and server, respectively. The major problem with PHP 5 configuration with MySQL 5 support resides on these two parameters. If they are misconfigured, you will get errors such as:

configure: error: Cannot find MySQL header files under /usr/bin/mysql.
Note that the MySQL client library is not bundled anymore.

or

configure: error: mysql configure failed. Please check config.log for
more information.

Notice that php was installed at /usr/local/apache2/php.

Now you need to configure httpd.conf file to add PHP 5 support. Run vi /usr/local/apache2/conf/httpd.conf and look for the line below:

LoadModule php4_module        modules/libphp4.so

If it exists, please add a # in front of it. Now check if the line below exists and if it is uncommented. If it doesn’t exist, please add it:

LoadModule php5_module        modules/libphp5.so

Also look for the following line:

AddHandler php-script   php

If it exists, add a # in front of it. Now check if the line below exists and if it is uncommented. If it doesn’t exist, please add it:

AddHandler php5-script php

Now look for the following line and if it is uncommented. If it doesn’t exist, add it:

AddType text/html       php

Exit vi (Esc wq <Enter>) and restart Apache with the following command:

/usr/local/apache2/bin/apachectl restart

Now you need to check if you installation was successful by creating a file called phpinfo.php with the following contents:

<?
Echo phpinfo();
?>

Put it at the root directory of your webserver (e.g., /www/your-website) and call it with your web browser (https://www.your-website.com/phpinfo.php). Of course you must have configured httpd.conf first in order to make Apache to know which directory it should use for your website. Even if you don’t have an URL pointing to your server IP address yet or if the server you are building is a local server on your own network, you can configure Apache (at its httpd.conf file) to answer requests based on the server IP address, thus you can use https://192.168.0.2/phpinfo.php (where 192.168.0.2 is obviously our web server IP address).

You should get a detailed description of how PHP is configured on your server. If you get this screen, congratulations, Apache and PHP are up and running. You should look if the following sessions exist on this page (below “Configuration”) and if they are enabled: mysql (“MySQL Support: Enabled” and if “Client API version” is the same as you installed, 5.0.21 on the example we used on our tutorial), mysqli (“MySQLi Support: Enabled” and if “Client library version” is the same as you installed, 5.0.37 on the example we used on our tutorial) and GD (“GD Support: Enabled”). If you can’t find them, check the configuration and installation process.

If everything is fine with your Apache and PHP 5 with MySQL 5 support installation, you can go ahead to the final step, which is installing a PHP cache and optimizer, which is a module that will save CPU resources from your web server, improving its performance.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *