How to Install Apache2.4 PHP5 and MySQL from Source on Debian Linux

Valic —  March 6, 2012 — 11 Comments

1. Install Apache 2.4 from source:

1.1 Prerequisites:

For installing Apache2.4 on Debian you need APR library. You can install this using the following command:

apt-get install libaprutil1 libaprutil1-dev

1.2  Download Apache2.4:

Download the latest version from here: http://httpd.apache.org/download.cgi#apache24
Go to /usr/src directory and download the latest version.

cd /usr/src
wget http://lnx.apollo-hw.ro/apache//httpd/httpd-2.4.1.tar.gz

1.3. Extract and Install Apache2.4:

root@deb:/usr/src# tar -zxf httpd-2.4.1
cd httpd-2.4.1
./configure --enable-so
make
make install

 1.4  Start Apache2.4:

cd /usr/local/apache2/
bin/apachectl start

Now go to http://your_ip and you will see the message “It works!”

1.5 Set Apache2.4  to automatically start during system startup:

Modify the /etc/rc.local  file and add the following line before exit 0:

/usr/local/apache2/bin/apachectl start

2. Install MySQL from source:

If you are planning to use PHP5  with MySQL  you should install MySQL now.
You can install MySQL in two ways:

2.a You can download MySQL from MySQL.com and install using the following command:

dpkg -i mysql-5.5.21-debian6.0-i686.deb

2.b Or you can install MySQL using the command:

apt-get install mysql-server  mysql-server

 2.c Verify the MySQL and start MySQL server:

 mysql -V
mysql  Ver 14.14 Distrib 5.1.49, for debian-linux-gnu (i486) using readline 6.1

And start :

/etc/init.d/mysql start
Starting MySQL database server: mysqld.
Checking for corrupt, not cleanly closed and upgrade needing tables..

3. Install PHP5 from source:

3.1 Download PHP5

Download the latest PHP5 source code from here: Download PHP5
Current stable release is 5.3.10 .

cd /usr/src
wget http://www.php.net/get/php-5.3.10.tar.gz/from/ro.php.net/mirror

3.2 Extract and install PHP5

tar -zxf php-5.3.10.tar.gz
cd php-5.3.10
./configure --prefix=/etc/php --with-apxs2=/usr/local/apache2/bin/apxs –with-config-file-path=/etc/php –with-mysql
make
make install

First option –prefix=/etc/php tells configure script that we want PHP to be installed in /etc/php directory. Otherwise it’ll be installed in some default location (/usr/local).

Second option –with-apxs2 specifies that we want to install PHP as Apache 2 shared module.

Third option –with-config-file-path specifies that PHP should look for php.ini file in /etc/php directory.

Fourth option –with-mysql enables support to access mysql databases through PHP.

3.3 Configure httpd.conf for using PHP5

Add these directives are in /usr/local/apache/conf/httpd.conf :

vim /usr/local/apache2/conf/httpd.conf
LoadModule php5_module modules/libphp5.so
AddHandler php5-script .php

# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php

AddType text/html .php

3.4 Restart the apache2.4 server

/usr/local/apache2/bin/apachectl restart

3.4 Verify the PHP5 installation

Create a phpinfo.php under /usr/local/apache2/htdocs/  with the following content:

echo “<?php phpinfo(); ?>” > /usr/local/apache2/htdocs/phpinfo.php

Now to to http://your-ip/phpinfo.php  which will show a detailed information about all the PHP5 configuration.
Enjoy using Apache2.4 on Debian

Valic

Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

11 responses to How to Install Apache2.4 PHP5 and MySQL from Source on Debian Linux

  1. Newest version is php 5.4 you can try to install php5.4 from source :)

  2. I will write a tutorial for it.

  3. Muito bom o tutorial. Parabéns.

    But, …. tem um pequeno erro, se é que se pode chamar assim. No passo:
    1.3. Extract and Install Apache2.4:

    root@deb:/usr/src# tar -zxf httpd-2.4.1
    cd httpd-2.4.1
    ./configure –enable-so
    make
    make install

    A linha ./configure –enable-so, ao ser copiada do browser, dá pau.
    Porquê?
    Por que o caractere – não é reconhecido.
    Como resolver?
    É só trocá-lo por — (dois hífens)
    Então a linha fica assim:
    ./configure –enable-so

    E é só correr pra galera …. ;)

  4. please use english language

  5. Gigio said (in Portuguese):

    Very good tutorial. Congratulations.

    But, …. has a small error, if one can call it that. In step:
    1.3. Extract and Install Apache2.4:

    root @ deb :/ usr / src # tar-zxf httpd-2.4.1
    cd httpd-2.4.1
    . / configure-enable-so
    make
    make install

    The line. / Configure-enable-so, to be copied from the browser crashes.
    Why?
    Why the character – is not recognized.
    How to solve?
    Just replace it with – (two hyphens)
    So the line looks like this:
    . / configure-enable-so

  6. Thanks, The problem appears by the wordpress fault.

  7. I can’t find the php.ini, where is it?

  8. Sorry. Was a mistake in tutorials.
    Conpile php with the following command:

    ./configure –prefix=/etc/php –with-apxs2=/usr/local/apache2/bin/apxs –with-config-file-path=/etc/php –with-mysql

    I updated the tutorial with more details.

  9. Is the –enable-so really necessary? What does it is useful for?

  10. Using the –enable-so option, you can load modules to Apache at runtime via the Dynamic Shared Object (DSO) mechanism, rather than requiring a recompilation.

Trackbacks and Pingbacks:

  1. Run Virtual Machines with VirtualBox and Manage VirtualBox Installations with phpvirtualbox | Linux Debian Tutorials | Debian Squeeze Tutorials - October 3, 2012

    [...] Assuming that a Apache webserver is already installed on server, e.g. as described in the tutorial How to Install Apache2.4 PHP5 and MySQL from Source on Debian Linux , unzip phpvirtualbox archive in /var/www folder and rename the phpvirtualbox-4.2-0b to [...]

Leave a Reply