Ubuntu 16.04 source compilation and installation of Apache 2.4.25 tutorial

  • 2020-05-17 07:27:53
  • OfStack

This article introduced the Ubuntu 16.04 source code compilation and installation of Apache, for your reference, the specific content is as follows

apache installation guide: http: / / httpd apache. org docs / 2.4 / install html

The installation guide provides detailed instructions for the installation process, but here are just a few caveats:

1. To compile and install apache, some dependent environments must be installed, otherwise the following compilation will report that the corresponding multiple files cannot be found:

APR (Apache portable Run - time libraries, Apache portable runtime) and APR - Util,, can see apr http: / / www cnblogs. com/iLumia p / 4214886 html download address: http: / / apr apache. org /

PCRE library if not install pcre, please download: http: / / www pcre. org
In addition, there are some disk space requirements, C compiler, time synchronization, Perl5 can be adjusted as needed.

2. Next are the detailed installation steps:
Here I'm used to putting the source code under /usr/local/src, switching directories according to my habit.

1). Install apr-1.5.2
Switch to the source directory of apr


cd /usr/local/src/apr-1.5.2/

Installation and compilation


./configure --prefix=/usr/local/apache/apr
make -j4( X according to the audit number of your computer 2 To set the parallel compilation parameters to improve the compilation speed )
sudo make install

2). Install apr-util-1.5.4

Switch to the source directory of apr-util


cd /usr/local/src/apr-util-1.5.4/

Installation and compilation


./configure --prefix=/usr/local/apache/apr-util --with-apr=/usr/local/apache/apr
make -j4
make install

3). Install pcre-8.39

Go to the installation directory


cd /usr/local/src/pcre-8.39/

Installation and compilation


./configure --prefix=/usr/local/pcre
make -j4
make install

4. After installing the dependencies, you can install apache
Enter the apache source directory


cd /usr/local/src/httpd-2.4.25/

Installation and compilation

We need to specify the location of the dependent package we just installed with the wounwith parameter


./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
make -j4
make install

At this point, we have completed the source installation of apache, and now we are ready to serve apache
Add startup script:


cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

Add environment variables:


echo 'export PATH=$PATH:/usr/local/apache/bin' > /etc/profile.d/httpd.sh
chmod a+x /etc/profile.d/httpd.sh
source /etc/profile.d/httpd.sh

You can then manage httpd in a variety of ways. If you need to boot yourself up, just add the startup command to /etc/ rc.local.

sudo /usr/local/apache/bin/apachectl start

An error may be reported that the port is occupied and the httpd.conf file needs to be modified

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

Then change the ServerName line to ServerName 127.0.0.1:80

Change Listen line 80 to Listen line 127.0.0.1:80

Then save and start the apache service.

service httpd start

Note:
If the profile cannot be found when starting the service, one way is to copy one profile to the corresponding path,
Or when you start apache, add the -f parameter to indicate the absolute path to the profile.


Related articles: