How to Install Apache 2.x on Unix systems ?

Today now in this post i will show you How to Install Apache 2.x on Unix systems ? On this section it will contains some notes and hints of specific to Apache 2.x installation of PHP on the Unix systems.

We are know that  Apache Documentation is one of the most informatic source of information for the Apache 2.x server setup. For more information to know about installation options for Apache server may be you can found from there.

We know that most recent version of Apache HTTP Server may be we can obtained from the  Apache download site, and we can also fitting the PHP version from the above address i was mentioned before. For this quick guide this only covers the basics about how to get started with the Apache 2.x and PHP. Now for more the information you can read the  Apache Documentation for better idea. Here the version numbers we have been omitted here, for ensure the instructions are not incorrect. So in the examples the below, ‘NN’ you should be replaced with your specific version of Apache need used.

We are know that there are currently has two versions of Apache 2.x – one there’s 2.4 and 2.2. Now while there are the various reasons for the choosing for each, we know that 2.4 is the currently latest version, and also that one is highly recommended, if on that option is available for you. However, this instructions will be work for either 2.4 or 2.2.

1. For Obtain the Apache HTTP server from the location listed above, and how to unpack it:
tar -xzf httpd-2.x.NN.tar.gz

2. Likewise, need to obtain and unpack the PHP source:

tar -xzf php-NN.tar.gz

3. For Build and install Apache. Consult the Apache install the documentation for more details on building Apache.

cd httpd-2_x_NN
./configure --enable-so
make install

4. Now we have Apache 2.x.NN available under the /usr/local/apache2, for configured with the loadable module support and the standard MPM prefork. For test the installation use we are normal procedure for starting the Apache server, e.g.:

/usr/local/apache2/bin/apachectl start

and for stop the server to go on with the configuration for PHP:

/usr/local/apache2/bin/apachectl stop

5. Now, for configure and build PHP. On this is where we need to customize PHP with the various options, as like which are extensions will be enabled. need to Run ./configure –help for the list of available options. Now in my example i’ll do a very simple configure with theApache 2 and MySQL support.

If we are built Apache from the source, as as described above, in the below example it will match our path for the apxs, but if we need to installed Apache some other way, we’ll need to adjust the path for apxs accordingly. So need to note that some distros may rename to the apxs to apxs2.

cd ../php-NN
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-pdo-mysql
make install

If we are decide to change our configure options after the installation, we’ll have to re-run the configure, make, and then need to make install steps. we only need to restart the apache for the new module to take effect. So A recompile of the Apache is not needed.

Now you should noted that to the unless told otherwise, to the ‘make install’ it will be also install the PEAR, various PHP tools such as phpize, need to install the PHP CLI, and more.

6. Setup your php.ini
cp php.ini-development /usr/local/lib/php.ini

we may need to edit our .ini file to set the PHP options. Then If we are prefer to using php.ini in another location, then need to use –with-config-file-path=/some/path in our step 5.

If we instead choose the php.ini-production, it will be certain to read the list for changes within, as they affect how to PHP behaves.

7. For Edit our httpd.conf to load on the PHP module. Now this path on the right hand of the side to LoadModule statement it must be point to the path of the PHP module on our system. So it make the install from above may i have already added this for you, but be sure to check.

For PHP 8:

LoadModule php_module modules/

For PHP 7:

LoadModule php7_module modules/

8. For tell Apache to parse certain to extensions as PHP. For the example, it let’s have Apache to parse .php files as PHP. So Instead of the only by using the Apache need to AddType to directive, we need to avoid the potentially dangerous uploads and the created files such as exploit.php.jpg from the being executed as PHP. By using this example, we could have any type extension(s) parse as PHP by simply then adding them. i’ll add the .php to demonstrate.

<FilesMatch \.php$>
    SetHandler application/x-httpd-php

Or, if we need to allow the .php, .php2, .php3, .php4, .php5, .php6, and also .phtml files to be executed as PHP, but then nothing else, we need to use this:

<FilesMatch "\.ph(p[2-6]?|tml)$">
    SetHandler application/x-httpd-php

And for allow .phps files to be handled by the php source as filter, and the displayed as syntax-highlighted source code, for use this:

<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source

need mod_rewrite may be used for allow any of arbitrary .php file to be displayed as syntax-highlighted as source code, without using to rename or copy it to as a .phps file:

RewriteEngine On
RewriteRule (.*\.php)s$ $1 [H=application/x-httpd-php-source]

For the php source it filter should not be enabled on the production systems, where it may be expose confidential or otherwise the sensitive information embedded in the source code.

9. Use your normal procedure for starting the Apache server, e.g.:
/usr/local/apache2/bin/apachectl start


service httpd restart

For following the steps above we will have a running the Apache2 web server with the support for PHP as a SAPI module. So of course there are need to many more configuration options available to Apache and PHP. For the more information need to type ./configure –help in the corresponding source tree.

We know that Apache may be built the multithreaded by selecting the worker MPM, rather than the standard to prefork MPM, when we are build Apache . So this is done by the adding the following option to the argument need to passed ./configure, in step 3 in above:


Read Also : How to Create Custom Blade Directive in Laravel?

Thanks for read. I hope it help you. For more you can follow us on facebook.

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →