Anda di halaman 1dari 5

How To Install Apache Server Source Package On Linux Server?

Posted in Servers by Surendra Anne On December 24, 2010. No comments

How to install apache server source package on Linux server?
Step1 : Check if the package is installed or not
#find / -iname httpd.conf
If you did not find any thing related to apache by using above find command
you can install the source package.
Step2 : We can install source package in /opt for our requirement. Download
the package from apache software foundation site
#cd /opt
Step3 : Uncompress it and change the directory to source directory
#tar xvfz httpd-2.2.17.tar.gz
#cd httpd-2.2.17
Step4 : Now compile the source code

#make install


The above three commands can be clubbed together to save time

#./configure && make && make install
Note1 : All the configuration files related to apache are stored in
/usr/local/apache2/ When we install the source package by default. But if we install it
through package installation softwares such as rpm/yum/apt-get the configuration files
are stored in /etc/httpd folder
Note2 : This is important and interview question too. Can we run two apache
servers at a time?
Ans : The answer to this question is yes. And its possible if we use source package to install
in two different locations say in /opt and /opt1 and the variable Listen is set to
different. Ports for this two servers(Bit complex to understand. If you have any questions our new Linux/Unix forums not officially announced.
Step5 : Now start the service.
#/usr/local/apache2/bin/apachectl start
Step6 : Check if the web server is running or not by accessing local host
#elinks localhost


Access localhost from browser

Install PHP and Apache from source

Installing software in Linux using a package manager is easy as typing "yum install
the-name-of-the-thing". But sometimes you want to make deep customizations or
make multiple installations of the same software (different PHP or Apache httpd
versions for example). Then the only thing you can do is install the software from its
source, and this is not that easy. In the following lines you will learn how to install
PHP (with PHP-FPM and OPcache) and Apache from source code.
Installation steps
The steps are the same for both PHP and Apache httpd.
1. Download the archive containing the source and extract it to some directory
2. Install dependencies (if any)
3. Configure the installer (enable or disable features)
4. Run the installer
5. Configure the software
What to expect at the end
After executing the following commands, you will have a fresh PHP installation, a
running PHP-FPM daemon and an Apache HTTP server that will be executing PHP
files with the help from the PHP-FPM daemon (Apache will proxy PHP files to PHPFPM).

Compiling PHP and Apache httpd requires a compiler. Let's install it.
yum install gcc

Let's create a user that will be used by Apache and PHP and the dir where our files
will be located
mkdir /var/www groupadd www-group useradd -d /var/www -g www-group -s
/bin/false www-user chown www-user:www-group /var/www

Create the dir where the source will be downloaded and extracted (it may already
mkdir /usr/local/src/

Installing PHP from source

Create the dir where PHP will be installed
mkdir /opt/php-7.0.4

Download the PHP source and extract it to the target directory

wget -O
/usr/local/src/php-7.0.4.tar.bz2 tar jxf /usr/local/src/php-7.0.4.tar.bz2
-C /usr/local/src

Install some dependencies

yum install libxml2 libxml2-devel

Change the current directory

cd /usr/local/src/php-7.0.4

Configure the installer

./configure --prefix=/opt/php-7.0.4 --enable-fpm --enable-opcache

Build and install the software

make && make install

Create the configuration files (or copy the recommended ones) to their proper
cp /usr/local/src/php-7.0.4/php.ini-production /opt/php-7.0.4/lib/php.ini
cp /opt/php-7.0.4/etc/php-fpm.conf.default /opt/php-7.0.4/etc/php-fpm.conf

In the php.ini file (located at /opt/php-7.0.4/lib/php.ini) add the following code

zend_extension=/opt/php-7.0.4/lib/php/extensions/no-debug-non-zts20151012/ opcache.enable = 1 opcache.enable_cli = 1
opcache.memory_consumption = 128 opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 10000 opcache.use_cwd = 0
opcache.validate_timestamps = 0 opcache.save_comments = 0
opcache.load_comments = 0 opcache.enable_file_override = 1

In the php-fpm.conf file (located at /opt/php-7.0.4/etc/php-fpm.conf) make some


Remove the following line (it should be last in the file)


Add the following lines

pid = run/ [www] user = www-user group = www-group listen = pm = dynamic pm.max_children = 10 pm.start_servers = 2
pm.min_spare_servers = 2 pm.max_spare_servers = 4

/opt/php-7.0.4/sbin/php-fpm --fpm-config /opt/php-7.0.4/etc/php-fpm.conf

You can stop it later with the following command

pkill php-fpm

It's done! Now we have a PHP installation and a running PHP-FPM daemon. Let's
install Apache httpd and point it towards PHP-FPM.

Installing Apache httpd from source

Create the dir where Apache will be installed
mkdir /opt/httpd-2.4.20

Download the Apache source and extract it to the target directory

wget -O
/usr/local/src/httpd-2.4.20.tar.bz2 tar jxf /usr/local/src/httpd2.4.20.tar.bz2 -C /usr/local/src

Download some dependencies

wget -O /usr/local/src/httpd2.4.20/srclib/apr-1.5.2.tar.bz2 tar jxf /usr/local/src/httpd2.4.20/srclib/apr-1.5.2.tar.bz2 -C /usr/local/src/httpd-2.4.20/srclib mv
/usr/local/src/httpd-2.4.20/srclib/apr-1.5.2 /usr/local/src/httpd2.4.20/srclib/apr wget
-O /usr/local/src/httpd-2.4.20/srclib/apr-util-1.5.4.tar.bz2 tar jxf
/usr/local/src/httpd-2.4.20/srclib/apr-util-1.5.4.tar.bz2 -C
/usr/local/src/httpd-2.4.20/srclib mv /usr/local/src/httpd-2.4.20/srclib/aprutil-1.5.4 /usr/local/src/httpd-2.4.20/srclib/apr-util yum install pcre-devel

Change the current directory

cd /usr/local/src/httpd-2.4.20/

Configure the installer

./configure --prefix=/opt/httpd-2.4.20 --enable-so

Build and install the software

make && make install

In the httpd.conf file (located at /opt/httpd-2.4.20/conf/httpd.conf) make the

following changes

Enable (uncomment) these modules

LoadModule proxy_module modules/ LoadModule proxy_fcgi_module


Change the user and the group

User www-user Group www-group

Add the following line at the end

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://$1

Start Apache
/opt/httpd-2.4.20/bin/apachectl start

You can stop it later by running

/opt/httpd-2.4.20/bin/apachectl stop

Create a test file to test the installations

echo "<?php phpinfo();" >> /var/www/info.php

Done! We now have running Apache and PHP.

Thank you for sharing