Updated-V2 : Compile and Build Apache2 and PHP-Fpm From Source on Linux (Part 1)
Build Apache2.4.46 from souce manually. Install Apache2.4.46 and PHP-Fpm-7.3.27 offline manually
Directory Structure
- opt
- src
- www
Download or copy apache.
Current Directory ~ src https://apr.apache.org/download.cgi wget https://www-eu.apache.org/dist//httpd/httpd-2.4.46.tar.gz gunzip httpd-2.4.46.tar.gz or gzip -d httpd-2.2.9.tar.gz tar -xvf httpd-2.4.46.tar
First Install Apache2 dependencies
- APR
- APR-UTIL
- Libexpat
- Apr-iconv
- Pcre
- OpenSSL
- Nghttp2
- Zlib
Now install APR and APR-util and pcre
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.
For Apr
wget https://www-us.apache.org/dist//apr/apr-1.7.0.tar.gz 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 Expact
wget https://github.com/libexpat/libexpat/releases/download/R_2_2_9/expat-2.2.9.tar.gz tar -xvf expat-2.2.9.tar.gz cd expat-2.2.9 ./configure --prefix=/app/system/opt/lib/expat make && make install
For Apr -Util
wget https://www-us.apache.org/dist//apr/apr-util-1.6.1.tar.gz tar -xvf apr-util-1.6.1.tar.gz cd apr-util-1.6.1 ./configure --prefix=/app/system/opt/lib/apr-util \ --with-apr=/app/system/opt/lib/apr \ --with-expat=/app/system/opt/lib/expat make && make install
For Pcre
wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz tar -xvf pcre-8.41.tar.gz cd pcre-8.41 ./configure --prefix=/app/system/opt/lib/pcre make && make install
For Zlib
wget https://zlib.net/zlib-1.2.11.tar.gz tar -xvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure --prefix=/app/system/opt/lib/zlib make && make install
For Nghttp2
https://github.com/nghttp2/nghttp2/releases wget https://github.com/nghttp2/nghttp2/releases/download/v1.43.0/nghttp2-1.43.0.tar.gz tar -xvf nghttp2-1.43.0.tar.gz cd nghttp2-1.43.0 ./configure --prefix=/app/system/opt/lib/nghttp2 --enable-lib-only make && make install
Other dependencies
Download and install openssl
wget https://www.openssl.org/source/openssl-1.1.1j.tar.gz tar -xvf openssl-1.1.1j.tar.gz cd openssl-1.1.1j ./config --prefix=/app/system/opt/lib/openssl make && make install
Now download and unzip Apache files
Apache2 configure inspired by Bitnami LAMP-7.3.27-0
Now go to src httpd-2.4.46 directory
cd httpd-2.4.46 "./configure" \ "--prefix=/app/system/opt/apache2" \ "--enable-so" \ "--enable-mods-shared=most" \ "--disable-auth_dbm" \ "--without-berkeley-db" \ "--enable-deflate" \ "--with-z=/app/system/opt/lib/zlib" \ "--enable-ssl" \ "--with-ssl=/app/system/opt/lib/openssl" \ "--enable-proxy" \ "--enable-proxy-http" \ "--enable-proxy-balancer" \ "--enable-rewrite" \ "--with-apr=/app/system/opt/lib/apr" \ "--with-apr-util=/app/system/opt/lib/apr-util" \ "--with-pcre=/app/system/opt/lib/pcre" \ "--enable-mpms-shared=all" \ "--with-nghttp2=/app/system/opt/lib/nghttp2" \ "--with-mpm=prefork" 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
