[CentOS 7LAMP Architecture 3], Apache installation and configuration#

Posted by onicsoft on Fri, 01 Nov 2019 11:11:16 +0100

shallow A kind of ove

Install Apache

  • Apache is the name of a foundation. httpd is the package we want to install. In the early days, its name was Apache.
  • Apache official website www.apache.org
  • wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.29.tar.gz
  • wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
  • wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2
  • apr and apr util are general function libraries, which make httpd easy to port (from linux to Windows) without caring about the underlying operating system platform.
  • tar zxvf httpd-2.4.29.tar.gz
  • tar zxvf apr-1.6.3.tar.gz
  • tar zxvf apr-util-1.6.1.tar.bz2
  • cd /usr/local/src/apr-1.6.3
  • ./configure --prefix=/usr/local/apr
  • make && make install
  • cd /usr/local/src/apr-util-1.6.1
  • ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  • make && make install
  • cd /usr/local/src/httpd-2.4.29
  • . / configure \ ා the backslash here is an escape character, plus it, we can write one line of command into multiple lines. --prefix=/usr/local/apache2.4
    --with-apr=/usr/local/apr
    --with-apr-util=/usr/local/apr-util
    --enable-so
    --enable-mods-shared=most
  • make && make install
  • ls /usr/local/apache2.4/modules
  • /usr/local/apache2.4/bin/httpd -M - view loaded modules

download

[root@localhost src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.29.tar.gz
--2017-12-16 05:48:11--  http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.29.tar.gz
Resolving mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.6.177, 2402:f000:1:416:101:6:6:177
Connecting to mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.6.177|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8638793 (8.2M) [application/octet-stream]
Saving to: 'httpd-2.4.29.tar.gz'

100%[=====================================================>] 8,638,793   78.8KB/s   in 65s    

2017-12-16 05:49:18 (129 KB/s) - 'httpd-2.4.29.tar.gz' saved [8638793/8638793]

[root@localhost src]# wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
--2017-12-16 05:49:21--  http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
Resolving mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.6.177, 2402:f000:1:416:101:6:6:177
Connecting to mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.6.177|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1072661 (1.0M) [application/octet-stream]
Saving to: 'apr-1.6.3.tar.gz'

100%[=====================================================>] 1,072,661   98.1KB/s   in 12s    

2017-12-16 05:49:34 (85.3 KB/s) - 'apr-1.6.3.tar.gz' saved [1072661/1072661]

[root@localhost src]# wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2
--2017-12-16 05:49:37--  http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2
Resolving mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.6.177, 2402:f000:1:416:101:6:6:177
Connecting to mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.6.177|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 428595 (419K) [application/octet-stream]
Saving to: 'apr-util-1.6.1.tar.bz2'

100%[=====================================================>] 428,595      218KB/s   in 1.9s   

2017-12-16 05:49:39 (218 KB/s) - 'apr-util-1.6.1.tar.bz2' saved [428595/428595]

[root@localhost src]# tar zxvf httpd-2.4.29.tar.gz
	Unpacking and decompression process
	.
	.
	.
[root@localhost src]# tar zxvf apr-1.6.3.tar.gz
	Unpacking and decompression process
	.
	.
	.
[root@localhost src]# bzip2 -d apr-util-1.6.1.tar.bz2
[root@localhost src]# tar xvf apr-util-1.6.1.tar
	//Unpacking process
	.
	.
	.

Compile and install apr first

[root@localhost src]# cd apr-1.6.3/
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr
	//Compiling process
	.
	.
	.
[root@localhost apr-1.6.3]# echo $?
0
[root@localhost apr-1.6.3]# make && make install
	//Compiling process
	.
	.
	.

Recompile and install APR util

[root@localhost apr-1.6.3]# ls /usr/local/apr
bin  build-1  include  lib
[root@localhost apr-util-1.6.1]# cd ../apr-util-1.6.1/
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
	#Compiling process
	.
	.
	.
[root@localhost apr-1.6.3]# make && make install
	#Compiling process
	.
	.
	.

Problems

xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory Solution: Yum install - y expat devel

[root@localhost ~]# yum install expat-devel
Loaded plugins: fastestmirror
base                                                                    | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                    | 7.2 kB  00:00:00     
epel                                                                    | 4.7 kB  00:00:00     
extras                                                                  | 3.4 kB  00:00:00     
updates                                                                 | 3.4 kB  00:00:00     
(1/3): extras/7/x86_64/primary_db                                       | 145 kB  00:00:01     
epel/x86_64/primary_db         FAILED                                          B  00:00:44 ETA 
http://mirror2.totbb.net/epel/7/x86_64/repodata/c7883ea243ee401d46c76adddb9d4b46d4cbe7d0f4fbb7f2f71d24ecaececa4a-primary.sqlite.bz2: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
(2/3): epel/x86_64/updateinfo                                           | 857 kB  00:00:02     
(3/3): epel/x86_64/primary_db                                           | 6.1 MB  00:00:14     
Loading mirror speeds from cached hostfile
 * epel: mirror01.idc.hinet.net
Resolving Dependencies
--> Running transaction check
---> Package expat-devel.x86_64 0:2.1.0-10.el7_3 will be installed
--> Processing Dependency: expat = 2.1.0-10.el7_3 for package: expat-devel-2.1.0-10.el7_3.x86_64
--> Running transaction check
---> Package expat.x86_64 0:2.1.0-8.el7 will be updated
---> Package expat.x86_64 0:2.1.0-10.el7_3 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================
 Package                 Arch               Version                     Repository        Size
===============================================================================================
Installing:
 expat-devel             x86_64             2.1.0-10.el7_3              base              57 k
Updating for dependencies:
 expat                   x86_64             2.1.0-10.el7_3              base              81 k

Transaction Summary
===============================================================================================
Install  1 Package
Upgrade             ( 1 Dependent package)

Total download size: 137 k
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/2): expat-devel-2.1.0-10.el7_3.x86_64.rpm                            |  57 kB  00:00:00     
(2/2): expat-2.1.0-10.el7_3.x86_64.rpm                                  |  81 kB  00:00:00     
-----------------------------------------------------------------------------------------------
Total                                                          208 kB/s | 137 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : expat-2.1.0-10.el7_3.x86_64                                                 1/3 
  Installing : expat-devel-2.1.0-10.el7_3.x86_64                                           2/3 
  Cleanup    : expat-2.1.0-8.el7.x86_64                                                    3/3 
  Verifying  : expat-devel-2.1.0-10.el7_3.x86_64                                           1/3 
  Verifying  : expat-2.1.0-10.el7_3.x86_64                                                 2/3 
  Verifying  : expat-2.1.0-8.el7.x86_64                                                    3/3 

Installed:
  expat-devel.x86_64 0:2.1.0-10.el7_3                                                          

Dependency Updated:
  expat.x86_64 0:2.1.0-10.el7_3                                                                

Complete!

[root@localhost apr-util-1.6.1]# ls /usr/local/apr-util/
bin  include  lib

Compiling and installing Apache 2.4

[root@localhost apr-util-1.6.1]# cd ../httpd-2.4.29/
[root@localhost httpd-2.4.29]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
	#Compiling process
	.
	.
	.
[root@localhost httpd-2.4.29]# make && make install
	#Compiling process
	.
	.
	.
[root@localhost httpd-2.4.29]# echo $?
0

--Enable so dynamic extension --Enable mods shared = most supported modules

If configure: error: PCRE config for libpcre not found. PCRE is required and available from http://pcre.org/ similar error reporting You can try to use fuzzy search

[root@localhost httpd-2.4.29]# yum install -y pcre-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirror01.idc.hinet.net
Resolving Dependencies
--> Running transaction check
---> Package pcre-devel.x86_64 0:8.32-17.el7 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================
 Package                 Arch                Version                     Repository         Size
=================================================================================================
Reinstalling:
 pcre-devel              x86_64              8.32-17.el7                 base              480 k

Transaction Summary
=================================================================================================
Reinstall  1 Package

Total download size: 480 k
Installed size: 1.4 M
Downloading packages:
pcre-devel-8.32-17.el7.x86_64.rpm                                         | 480 kB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : pcre-devel-8.32-17.el7.x86_64                                                 1/1 
  Verifying  : pcre-devel-8.32-17.el7.x86_64                                                 1/1 

Installed:
  pcre-devel.x86_64 0:8.32-17.el7                                                                

Complete!

pcre is a dependency Library of regular expression

apache file introduction

[root@localhost httpd-2.4.29]# cd /usr/local/apache2.4/
[root@localhost apache2.4]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules

Executable directory

[root@localhost apache2.4]# ls bin/
ab         apxs      dbmmanage  envvars-std  htcacheclean  htdigest  httpd      logresolve
apachectl  checkgid  envvars    fcgistarter  htdbm         htpasswd  httxt2dbm  rotatelogs
[root@localhost apache2.4]# ls -l bin/httpd 
-rwxr-xr-x 1 root root 2334331 Dec 16 07:58 bin/httpd
[root@localhost apache2.4]# du -sh !$
du -sh bin/httpd
2.3M	bin/httpd

Profile directory

[root@localhost apache2.4]# ls conf/
extra  httpd.conf  magic  mime.types  original
[root@localhost apache2.4]# vi conf/httpd.conf

Access page storage directory

[root@localhost apache2.4]# ls htdocs/
index.html

Log storage directory

[root@localhost apache2.4]# ls logs/

Help document

[root@localhost apache2.4]# ls man
man1  man8

Extension module

[root@localhost apache2.4]# ls modules/
httpd.exp               mod_dbd.so                  mod_proxy_hcheck.so
mod_access_compat.so    mod_deflate.so              mod_proxy_http.so
mod_actions.so          mod_dir.so                  mod_proxy_scgi.so
mod_alias.so            mod_dumpio.so               mod_proxy.so
mod_allowmethods.so     mod_env.so                  mod_proxy_wstunnel.so
mod_auth_basic.so       mod_expires.so              mod_ratelimit.so
mod_auth_digest.so      mod_ext_filter.so           mod_remoteip.so
mod_auth_form.so        mod_file_cache.so           mod_reqtimeout.so
mod_authn_anon.so       mod_filter.so               mod_request.so
mod_authn_core.so       mod_headers.so              mod_rewrite.so
mod_authn_dbd.so        mod_include.so              mod_sed.so
mod_authn_dbm.so        mod_info.so                 mod_session_cookie.so
mod_authn_file.so       mod_lbmethod_bybusyness.so  mod_session_dbd.so
mod_authn_socache.so    mod_lbmethod_byrequests.so  mod_session.so
mod_authz_core.so       mod_lbmethod_bytraffic.so   mod_setenvif.so
mod_authz_dbd.so        mod_lbmethod_heartbeat.so   mod_slotmem_shm.so
mod_authz_dbm.so        mod_log_config.so           mod_socache_dbm.so
mod_authz_groupfile.so  mod_log_debug.so            mod_socache_memcache.so
mod_authz_host.so       mod_logio.so                mod_socache_shmcb.so
mod_authz_owner.so      mod_macro.so                mod_speling.so
mod_authz_user.so       mod_mime.so                 mod_ssl.so
mod_autoindex.so        mod_negotiation.so          mod_status.so
mod_buffer.so           mod_proxy_ajp.so            mod_substitute.so
mod_cache_disk.so       mod_proxy_balancer.so       mod_unique_id.so
mod_cache.so            mod_proxy_connect.so        mod_unixd.so
mod_cache_socache.so    mod_proxy_express.so        mod_userdir.so
mod_cgid.so             mod_proxy_fcgi.so           mod_version.so
mod_dav_fs.so           mod_proxy_fdpass.so         mod_vhost_alias.so
mod_dav.so              mod_proxy_ftp.so            mod_watchdog.so
[root@localhost apache2.4]# du -sh !$
du -sh modules/
7.3M	modules/

View loaded modules

[root@localhost apache2.4]# /usr/local/apache2.4/bin/httpd -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_event_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)
[root@localhost apache2.4]# /usr/local/apache2.4/bin/apachectl -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_event_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)

Start apache

[root@localhost ~]# /usr/local/apache2.4/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

If you do not want to prompt, you can modify the configuration file

[root@localhost ~]# ps aux | grep httpd
root      66672  0.0  0.1  70904  2216 ?        Ss   08:24   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    66673  0.0  0.2 359868  4264 ?        Sl   08:24   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    66674  0.0  0.2 359868  4260 ?        Sl   08:24   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    66675  0.0  0.2 359868  4264 ?        Sl   08:24   0:00 /usr/local/apache2.4/bin/httpd -k start
root      66758  0.0  0.0 112660   976 pts/3    S+   08:26   0:00 grep --color=auto httpd
[root@localhost ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2627/master         
tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:59237           0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      1884/rpc.mountd     
tcp        0      0 0.0.0.0:47251           0.0.0.0:*               LISTEN      1566/rpc.statd      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1404/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2627/master         
tcp6       0      0 :::54207                :::*                    LISTEN      1566/rpc.statd      
tcp6       0      0 :::2049                 :::*                    LISTEN      -                   
tcp6       0      0 :::3306                 :::*                    LISTEN      3192/mysqld         
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::80                   :::*                    LISTEN      66672/httpd         
tcp6       0      0 :::20048                :::*                    LISTEN      1884/rpc.mountd     
tcp6       0      0 :::51574                :::*                    LISTEN      -                   
tcp6       0      0 :::22                   :::*                    LISTEN      1404/sshd 

Default listening port 80

Conclusion: In the process of compiling, some problems should be solved by using search engine. Personal questions. / configure works with make & & make install

Topics: Operation & Maintenance Apache EPEL yum RPM