Compile and Build Apache2 and PHP-Fpm From Source on Linux (Part 1)

Build Apache2 from souce manually. Install Apache2 and PHP-Fpm offline manually

Directory Structure

  1. opt
  2. src
  3. www

Download or copy apache.

Current Directory ~ src
https://apr.apache.org/download.cgi
sudo wget https://www-eu.apache.org/dist//httpd/httpd-2.4.41.tar.gz

sudo gunzip httpd-2.4.41.tar.gz 
or
gzip -d httpd-2.2.9.tar.gz
tar -xvf httpd-2.4.41.tar

 

First Install Apache2 dependencies

  1. APR
  2. APR-UTIL
  3. Apr-iconv
  4. Pcre
  5. Libexpat
  6. OpenSSL

Now install APR and APR-util and pcre

Download from this site

http://www.pcre.org/

wget https://www-us.apache.org/dist//apr/apr-1.7.0.tar.gz
wget https://www-us.apache.org/dist//apr/apr-util-1.6.1.tar.gz
wget https://www-us.apache.org/dist//apr/apr-iconv-1.2.2.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
wget https://github.com/libexpat/libexpat/releases/download/R_2_2_9/expat-2.2.9.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1.tar.gz

APR and APR-util installation system

APR and APR-UtilMake sure you have APR and APR-Util already installed on your system. If you don’t, or prefer to not use the system-provided versions, download the latest versions of both APR and APR-Util from Apache APR, unpack them into /httpd_source_tree_root/srclib/apr and /httpd_source_tree_root/srclib/apr-util (be sure the directory names do not have version numbers; for example, the APR distribution must be under /httpd_source_tree_root/srclib/apr/) and use ./configure‘s --with-included-apr option. On some platforms, you may have to install the corresponding -dev packages to allow httpd to build against your installed copy of APR and APR-Util.

 

Unzip tar file and configure

gzip -d apr-1.7.0.tar.gz

tar -xvf apr-1.7.0.tar

cd apr

./configure --prefix=/app/system/opt/lib/apr

make && make install

 

For Apr -Util

./configure --prefix=/app/system/opt/lib/apr-util --with-apr=/app/system/opt/lib/apr
make && make install

For Expact

./configure --prefix=/app/system/opt/lib/expat

make && make install

For Pcre

./configure --prefix=/app/system/opt/lib/pcre

make && make install

Other dependencies

Download and install openssl
./configure --prefix=/app/system/opt/lib/openssl

make && make install

Now download and unzip Apache files

Now go to src httpd-2.4.41 directory

cd httpd-2.4.41

./configure --prefix=/app/system/opt/apache2 \
	--enable-rewrite \
	--enable-so \
	--enable-proxy=shared \
	--enable-mods-shared=all \
	--enable-vhost-alias \
	--enable-ssl \
	--enable-session \
	--enable-session-cookie \
	--enable-http \
	--enable-log-config \
	--enable-log-debug \
	--enable-logio \
	--with-apr=/app/system/opt/lib/apr \
	--with-apr-util=/app/system/opt/lib/apr-util/ \
	--with-pcre=/app/system/opt/lib/pcre \
	--with-ssl=/app/system/opt/lib/openssl

make && make install

 

After installation go to

cd /app/system/opt/apache2/bin

./apachectl start

to top

./apachectl stop

 

Resolve known issue : Apache not starting

Config httpd.conf and httpd-vhost.conf

Edit: httpd.conf

nano /app/system/opt/apache2/conf

Change port exclude 1 to 1024 as they are reserved for system sudo user

#Listen 12.34.56.78:80
Listen 8443

User www-data
Group www-data

ServerName 127.0.0.1:8443

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

#Add this on the bottom of httpd-config file
ProxyErrorOverride on
#Enable this module to start apachactl 
LoadModule session_module modules/mod_session.so 

## To enable ProxyErrorOverride on and ProxyPassMatch enbale 
LoadModule proxy_module modules/mod_proxy.so 
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

Edit Extra/httpd-vhosts.conf

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#

listen 9443

<VirtualHost *:9443>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/app/system/www"
ServerName 127.0.0.1
#ServerAlias www.dummy-host.example.com
<Directory "/app/system/www">

# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.

# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
Options Indexes FollowSymLinks


# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
AllowOverride None


# Controls who can get stuff from this server.
Require all granted
</Directory>


# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>


# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
<Files ".ht*">
Require all denied
</Files>

#ErrorLog "logs/dummy-host.example.com-error_log"
#CustomLog "logs/dummy-host.example.com-access_log" common

# This is php-fpm to work with apache
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/app/system/www/$1

# Or Use Sethandler for php-fpm to work with apache
<FilesMatch \.php$> 
   SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
</VirtualHost>

 

Part 2

http://tuts.raihanchow.com/2020/04/01/compile-and-build-apache2-and-php-fpm-from-source-on-linux-part-2/

 

Leave a Reply

Your email address will not be published.