Using source code to install Apache server under Ubuntu


1. Download
I downloaded httpd-2.4.2 tar.bz2

2. Ubuntu Apache unzip

Put the downloaded file in the main directory and unzip it

tar zxvf httpd-2.4.2.tar.gz 

After decompressing, a file named httpd-2.4.2 is obtained in the main directory

3. Create destination folder

mkdir /usr/local/apache

That is to say, the Ubuntu Apache to be installed in this folder

4. Ubuntu Apache configuration

Return to the original folder generated after decompression

cd  httpd-2.4.2
./configure --prefix=/usr/local/apache --enable-module=shared

You need to add the following parameters, otherwise you can’t use PHP

There will be an error.

configure: error: APR not found . Please read the documentation.

The main reason is that the APR package is not installed.

Then download the APR package. Website:
I downloaded apr-1.4.6 tar.gz Put it in the home directory and extract tar – zxvf apr-1.4.2 tar.gz Get a file named apr-1.4.6 in the home directory

cd   apr-1.4.6    
sudo ./configure
sudo  make
sudo make install

Continue to step 4 after installing the APR packagecd httpd-2.4.2And then

./configure --prefix=/usr/local/apache --enable-module=shared

When found, they reported an error:

configure:error: APR-util not found . Please read the documentation.

The main reason is that the APR util package is not installed.

So download the APR util package at
I downloaded apr-util-1.4.1 tar.gz Put it in the main directory and unzip ittar -zxvf apr-1.4.2.tar.gzGet a file named apr-util-1.4.1 in the home directory

cd apr-1.4.1    
sudo ./configure
sudo make
sudo make install

. / configure still prompts

APR-util not found

Add — with APR = / usr / local / APR — with APR util = / usr / local / APR util parameter input

./configure --prefix=/usr/local/apache --enable-module=shared --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util


configure: error: pcre-config for libpcre not found. PCREis required and available from

This is because PCRE is not installed.

So download the PCRE website as I downloaded in the main directory and then

cd pcre-8.10
sudo ./configure --prefix=/usr/local/pcre  
sudo make  
sudo make install

During the installation process, you will be prompted that libtool is not installed and can be usedsudo apt-get install libtoolInstallation. Then there will be:

libtool: ignoring unknown tag CXX
libtool: unrecognized option `-DHAVE_CONFIG_H’
Try `libtool –help’ for more information.
make1: *** [pcrecpp.lo] Error 1

It can be concluded that this error is caused by the lack of system package. Just sudo apt get install G + +, reconfigure, make & & make install can complete the installation of PCRE.

Then continue with the first part of step 4,

cd  httpd-2.4.2 
./configure --prefix=/usr/local/apache --enable-module=shared  --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre


sudo make
sudo make install 

Complete the installation of Apache server.

5. Start, restart and stop

/Usr / local / Apache / bin / apachectl - K start 
/usr/local/apache/bin/apachectl -k restart
/usr/local/apache/bin/apachectl -k stop

During startup, you will be prompted that the program “apachectl” has not been installed. You can install using the following command:

sudo apt-get install apache2.2-common

Then input it at the terminal

sudo apt-get install apache2.2-common

When you’re done, you can start. Use sudo when starting, otherwise an error will be reported

Permission denied: AH00072: make_sock: could not bind to address listenin sockets available

Simple start Apache command

Copy the Apache startup file to the directory where you installed Apache in front of usr / SBIN.

cp /usr/local/apache/bin/apachectl   /usr/sbin/

When you start Apache, you can simply type instead of typing for a long time.

sudo apachectl start 

It’s ready to start

Set Apache boot

#vi /etc/rc.d/rc.local

Add a line / SBIN / apachectl start

6. Configuration file

gedit /usr/local/apache/conf/httpd.conf

Modify the following configuration (of course, these changes are the most basic changes. For more advanced ones, refer to other Ubuntu Apache configuration manuals)

AddType application/x-gzip .gz .tgz

Add below:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

DirectoryIndex index.html

Add after index.php :
DirectoryIndex index.html index.php


It is amended as follows:
ServerName localhost:80
Remember to remove the “in front”
Otherwise, the following error message will appear:

httpd: Could not reliably determine the server’s fully qualified domain name, using for ServerName

Install PHP

1. Download PHP I downloaded php-5.3.14 tar.bz2
Put it in the main directory and unzip it.

tar  -zjvf  php-5.3.14.tar.bz2

After decompressing, get a php-5.3.14 file in the main directory.

cd php-5.3.14

sudo ./configure --prefix=/usr/local/php --with-mysql=/usr/share/mysql --with-apxs2=/usr/local/apache/bin/apxs

When you do this directly, you will see an error like this:

configure: error: xml2-config not found. Please check your libxml2 installation.

sudo apt-get install libxml2(press tab twice) there will be libxml2 libxml2 dev libxml2 headers libxml2 utils

Install libxml2 dev

sudo apt-get install libxml2-dev  

Then continue to install PHP. Configure

Then an error is reported:

Note that the MySQL client library is not bundled anymore!

This is because MySQL header file is not installed when MySQL is installed, or the path is not specified correctly, and PHP cannot find MySQL header file.


  • Check whether MySQL header is installed on your system
    find / -name mysql.h
    If so. Please specify--with-mysql=/Follow your normal path.
    without. Then install:
    apt-get install libmysqlclient15-dev

The last step is to add the configuration option of PHP — with MySQL = / usr! (I didn’t try this step. Configure is still the original configuration.) then continue

sudo ./configure --prefix=/usr/local/php --with-mysql=/usr/share/mysql --with-apxs2=/usr/local/apache/bin/apxs


sudo make
sudo make  install

Complete the installation.

Install Apache after restart

sudo /usr/local/apache/bin/apachectl -k stop  
sudo /usr/local/apache/bin/apachectl -k  start

2. Test whether it is available.

Write a PHP file.

sudo gedit /usr/local/apache/htdocs/index.php

Fill it in


Then enter it in the browser. http://localhost/index.php See the PHP related information and the installation is successful.

Recommended Today

Django docker containerized deployment: Django docker MySQL nginx gunicorn cloud deployment

In the previous chapter, we added MySQL database to docker, but the development server adopted is easy to use, but it has poor performance and low reliability, so it can not be applied in production environment. Therefore, this chapter will implement the docker + Django + MySQL + nginx + gunicorn container project to complete […]