How to install Apache, PHP and MySQL on Linux: Part 3

This tutorial explains the installation of Apache web server, bundled with PHP and MySQL server on a Linux machine. The tutorial is primarily for SuSE 9.2, 9.3, 10.0 & 10.1, but most of the steps ought to be valid for all Linux-like operating systems.

PHP 5 installation

We will set up PHP as a shared module, being loaded into Apache2 dynamically during the server startup. These instructions are known to work for PHP versions: 5.0.4 through 5.3.3 .


At this point Apache web server must be installed. If you want MySQL support in PHP, MySQL server also must have been installed prior to the next steps.

Download source

Get the source from . At the time of writing this tutorial the best available version was 5.3.3 ( php-5.3.3.tar.gz ).

Unpack, configure, compile

Go to the directory with the downloaded file and enter:

tar -xzf php-5.3.3.tar.gz
cd php-5.3.3
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql

The configuration options ought to be self-explaining; –prefix specifies the location where PHP is to be installed, –with-apxs2 with correct path pointing to bin/apxs in the Apache installation directory is mandatory for the installator to work. Since PHP 5, you need to explicitly bundle PHP with MySQL by –with-mysql directive (make sure you specified path to where MySQL is installed on your system).

There are many other options which turn on additional features. For all available configuration options and their default values type ./configure –help.

Tip: If you are performing an upgrade, you may want to copy config.nice from the old PHP installation directory (if available) to where you unpacked the new PHP tarball file. Run ./config.nice instead of ./configure. This way all the previous configure options will be applied to the new installation effortlessly.

Once you entered ./configure with all the options you need, compile and install the software:

make install

Edit httpd.conf

All necessary changes to httpd.conf (Apache configuration file) should have already been made automatically during the installation, so usually you need not do anything. Anyways, check that following lines were added to your httpd.conf file:

LoadModule php5_module modules/
AddType application/x-httpd-php .php

If not, add them manually.

Create php.ini file

Importanly, you have to create php.ini configuration file. Choose one of the pre-made files (preferably php.ini-recommended) residing inside the php-5.3.3/ directory (it’s the folder to which the downloaded archive was extracted). Copy the file to the lib/ directory in the PHP installation directory.

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

If you need to, edit the php.ini file:

vi /usr/local/php/lib/php.ini

However, the default settings should work for everyone in most cases.

Restart apache server

After everything is set up, restart Apache:

/usr/local/bin/apachectl stop
/usr/local/bin/apachectl start

Alternatively, simply enter:

/usr/local/bin/apachectl restart

Further reading

PHP Manual

Tags: ,

5 Responses to “How to install Apache, PHP and MySQL on Linux: Part 3”

  1. Sebi says:

    thank you for this how to!
    i have an error while config php. theres no makefile configured. the logfile says:

    configure: failed program was:
    #line 19399 “configure”
    #include “confdefs.h”
    /* System header to define __stub macros and hopefully few prototypes,
        which can conflict with char crypt_r(); below.  */
    /* Override any gcc2 internal prototype to avoid an error.  */
    /* We use char because int might match the return type of a gcc2
        builtin and then its argument prototype would still apply.  */
    char crypt_r();

    int main() {

    /* The GNU C library defines this for functions which it implements
        to always fail with ENOSYS.  Some functions are actually named
        something starting with __ and the normal name is an alias.  */
    #if defined (__stub_crypt_r) || defined (__stub___crypt_r)
    choke me

    can you help me please?

  2. [...] "Include conf/extra/httpd-ssl.conf" in the httpd.conf file. After you installed PHP (next part of this tutorial), few additional changes need to be done to httpd.conf (but they are usually made automatically [...]

  3. SKETSA says:


    [...]How to install Apache, PHP and MySQL on Linux: Part 3 |[...]…

  4. how to improve hearing naturally…

    How to install Apache, PHP and MySQL on Linux: Part 3 |…

  5. [...] Dear all, I have installed php-5.4.5.tar.gz in my linux box by using the below link and now in my system i want to install gd in my php and how do i install gd in already installed [...]

Leave a Reply

You must be logged in to post a comment.