Apache安装(CentOS)

简介:

在CentOS上安装Apache

安装环境及版本:

系统环境:CentOS Linux release 7.5.1804 (Core)

一、Yum安装

命令:yum install httpd

[root@localhost ~]# yum install httpd
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.bfsu.edu.cn
......
Running transaction
  Installing : mailcap-2.1.41-2.el7.noarch                                                                                                                                                                                              1/3 
  Installing : httpd-tools-2.4.6-93.el7.centos.x86_64                                                                                                                                                                                   2/3 
  Installing : httpd-2.4.6-93.el7.centos.x86_64                                                                                                                                                                                         3/3 
  Verifying  : httpd-tools-2.4.6-93.el7.centos.x86_64                                                                                                                                                                                   1/3 
  Verifying  : mailcap-2.1.41-2.el7.noarch                                                                                                                                                                                              2/3 
  Verifying  : httpd-2.4.6-93.el7.centos.x86_64                                                                                                                                                                                         3/3 

Installed:
  httpd.x86_64 0:2.4.6-93.el7.centos                                                                                                                                                                                                        

Dependency Installed:
  httpd-tools.x86_64 0:2.4.6-93.el7.centos                                                                                   mailcap.noarch 0:2.1.41-2.el7                                                                                  

Complete!

1.1 配置:httpd.conf

配置文件位于:vi /etc/httpd/conf/httpd.conf,主要涉及修改监听端口、发布目录路径以及默认首页名

监听端口:42 Listen 80

服务器名:95 #ServerName www.example.com:80

根目录:119 DocumentRoot “/var/www/html”

124 <Directory "/var/www">
125     AllowOverride None
126     # Allow open access:
127     Require all granted
128 </Directory>
129 
130 # Further relax access to the default document root:
131 <Directory "/var/www/html">

启动默认页面:

163 <IfModule dir_module>
164     DirectoryIndex index.html
165 </IfModule>

1.2 启停

1.2.1 启停

重启:[root@localhost ~]# systemctl restart httpd
停止:[root@localhost ~]# systemctl stop httpd
启动:[root@localhost ~]# systemctl start httpd

1.2.2 自启动

开机自启动[root@localhost ~]# systemctl enable httpd

[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

1.2.3 检查状态

[root@localhost ~]# systemctl status httpd

[root@localhost ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2020-06-30 03:04:49 EDT; 2min 2s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 1945 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─1945 /usr/sbin/httpd -DFOREGROUND
           ├─1946 /usr/sbin/httpd -DFOREGROUND
           ├─1947 /usr/sbin/httpd -DFOREGROUND
           ├─1948 /usr/sbin/httpd -DFOREGROUND
           ├─1949 /usr/sbin/httpd -DFOREGROUND
           └─1950 /usr/sbin/httpd -DFOREGROUND

Jun 30 03:04:49 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Jun 30 03:04:49 localhost.localdomain httpd[1945]: 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
Jun 30 03:04:49 localhost.localdomain systemd[1]: Started The Apache HTTP Server.

二、编译安装make

版本:
apr-1.5.0.tar.gz
apr-util-1.5.3.tar.gz
pcre-8.38.tar.gz
httpd-2.4.23.tar.gz

2.1 安装依赖包

命令:yum -y install unzip wget

[root@localhost ~]# yum -y install unzip wget
Loaded plugins: fastestmirror
Determining fastest mirrors
................
Installed:
  wget.x86_64 0:1.14-18.el7_6.1                                                                                                                                                                                                               

Updated:
  unzip.x86_64 0:6.0-21.el7                                                                                                                                                                                                                   

Complete!

命令:yum -y install gcc gcc-c++ autoconf libtool

[root@localhost ~]# yum -y install gcc gcc-c++ autoconf libtool
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
.....
Updated:
  gcc.x86_64 0:4.8.5-39.el7                                                                                           gcc-c++.x86_64 0:4.8.5-39.el7                                                                                          

Dependency Updated:
  cpp.x86_64 0:4.8.5-39.el7                   gcc-gfortran.x86_64 0:4.8.5-39.el7     libgcc.x86_64 0:4.8.5-39.el7              libgfortran.x86_64 0:4.8.5-39.el7     libgomp.x86_64 0:4.8.5-39.el7     libquadmath.x86_64 0:4.8.5-39.el7    
  libquadmath-devel.x86_64 0:4.8.5-39.el7     libstdc++.x86_64 0:4.8.5-39.el7        libstdc++-devel.x86_64 0:4.8.5-39.el7    

Complete!

2.2 安装apr

进入/usr/local/src目录:cd /usr/local/src/

[root@localhost ~]# cd /usr/local/src
[root@localhost src]# ll
total 0

下载文件:wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-1.5.0.tar.gz

[root@localhost src]# wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-1.5.0.tar.gz
--2020-07-02 19:22:05--  http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-1.5.0.tar.gz
Resolving oss.aliyuncs.com (oss.aliyuncs.com)... 118.178.29.25
Connecting to oss.aliyuncs.com (oss.aliyuncs.com)|118.178.29.25|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1016391 (993K) [application/x-gzip]
Saving to: ‘apr-1.5.0.tar.gz’

100%[====================================================================================================================================================================================================>] 1,016,391   1.53MB/s   in 0.6s   

2020-07-02 19:22:06 (1.53 MB/s) - ‘apr-1.5.0.tar.gz’ saved [1016391/1016391]

[root@localhost src]# ll
total 996
-rw-r--r--. 1 root root 1016391 Dec 26  2013 apr-1.5.0.tar.gz

解压缩下载文件:tar zxvf apr-1.5.0.tar.gz
并进入文件目录:cd apr-1.5.0

[root@localhost src]# tar zxvf apr-1.5.0.tar.gz 
.....
[root@localhost src]# cd apr-1.5.0
[root@localhost apr-1.5.0]# ll
total 1388
-rw-r--r--. 1 1000 1000   6903 Jun 20  2008 apr-config.in
-rw-r--r--. 1 1000 1000  53992 Nov  6  2013 apr.dep
-rw-r--r--. 1 1000 1000  22900 Nov  5  2013 apr.dsp
-rw-r--r--. 1 1000 1000   1777 Oct 18  2007 apr.dsw
.....
drwxr-xr-x. 3 1000 1000     18 Nov 13  2013 random
-rw-r--r--. 1 1000 1000   5633 Mar  1  2010 README
-rw-r--r--. 1 1000 1000   4377 Oct 10  2013 README.cmake
drwxr-xr-x. 6 1000 1000     54 Nov 13  2013 shmem
drwxr-xr-x. 2 1000 1000    134 Nov 13  2013 strings
drwxr-xr-x. 3 1000 1000     18 Nov 13  2013 support
drwxr-xr-x. 2 1000 1000     66 Nov 13  2013 tables
drwxr-xr-x. 4 1000 1000   4096 Nov 13  2013 test
drwxr-xr-x. 7 1000 1000     69 Nov 13  2013 threadproc
drwxr-xr-x. 4 1000 1000     31 Nov 13  2013 time
drwxr-xr-x. 2 1000 1000     29 Nov 13  2013 tools
drwxr-xr-x. 5 1000 1000     46 Nov 13  2013 user
[root@localhost apr-1.5.0]# 

检查安装环境:./configure –prefix=/usr/local/apr

[root@localhost apr-1.5.0]# ./configure --prefix=/usr/local/apr
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
......
config.status: creating test/Makefile
config.status: creating test/internal/Makefile
config.status: creating include/arch/unix/apr_private.h
config.status: executing libtool commands
rm: cannot remove 'libtoolT': No such file or directory
config.status: executing default commands

编译及安装:make && make install

[root@localhost apr-1.5.0]# make && make install
make[1]: Entering directory `/usr/local/src/apr-1.5.0'
..................
for f in libtool shlibtool; do \
    if test -f ${f}; then /usr/bin/install -c -m 755 ${f} /usr/local/apr/build-1; fi; \
done
/usr/bin/install -c -m 755 /usr/local/src/apr-1.5.0/build/mkdir.sh /usr/local/apr/build-1
for f in make_exports.awk make_var_export.awk; do \
    /usr/bin/install -c -m 644 /usr/local/src/apr-1.5.0/build/${f} /usr/local/apr/build-1; \
done
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config

2.3 安装apr-util

进入/usr/local/src目录:cd /usr/local/src/

[root@localhost apr-1.5.0]# cd /usr/local/src/
[root@localhost src]# ll
total 1000
drwxr-xr-x. 28 1000 1000    4096 Jul  2 19:28 apr-1.5.0
-rw-r--r--.  1 root root 1016391 Dec 26  2013 apr-1.5.0.tar.gz

下载文件:wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-util-1.5.3.tar.gz

[root@localhost src]# wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-util-1.5.3.tar.gz
--2020-07-02 19:32:08--  http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-util-1.5.3.tar.gz
Resolving oss.aliyuncs.com (oss.aliyuncs.com)... 118.178.29.25
Connecting to oss.aliyuncs.com (oss.aliyuncs.com)|118.178.29.25|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 874462 (854K) [application/x-gzip]
Saving to: ‘apr-util-1.5.3.tar.gz’

100%[====================================================================================================================================================================================================>] 874,462     1.63MB/s   in 0.5s   

2020-07-02 19:32:09 (1.63 MB/s) - ‘apr-util-1.5.3.tar.gz’ saved [874462/874462]

解压缩下载文件:tar zxvf apr-util-1.5.3.tar.gz
并进入文件目录:cd apr-util-1.5.3

[root@localhost src]# tar zxvf apr-util-1.5.3.tar.gz 
......
[root@localhost src]# cd apr-util-1.5.3
[root@localhost apr-util-1.5.3]# ll
total 1056
-rw-r--r--. 1 1000 1000   9058 Mar 29  2013 aprutil.dep
-rw-r--r--. 1 1000 1000  18886 Jul 18  2012 aprutil.dsp
-rw-r--r--. 1 1000 1000   9573 Dec  8  2011 aprutil.dsw
-rw-r--r--. 1 1000 1000  42729 Mar 29  2013 aprutil.mak
......
drwxr-xr-x. 2 1000 1000     28 Nov 13  2013 strmatch
drwxr-xr-x. 3 1000 1000   4096 Nov 13  2013 test
drwxr-xr-x. 2 1000 1000     23 Nov 13  2013 uri
drwxr-xr-x. 2 1000 1000     21 Nov 13  2013 xlate
drwxr-xr-x. 3 1000 1000     57 Nov 13  2013 xml

检查安装环境:./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr

[root@localhost apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
...........
config.status: creating test/Makefile
config.status: creating include/private/apu_config.h
config.status: executing default commands

编译及安装:make && make install

[root@localhost apr-util-1.5.3]# make && make install
Making all in xml/expat
make[1]: Entering directory `/usr/local/src/apr-util-1.5.3/xml/expat'
.................
----------------------------------------------------------------------
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config

2.4 安装pcre

进入/usr/local/src目录:cd /usr/local/src/

[root@localhost apr-util-1.5.3]# cd /usr/local/src/
[root@localhost src]# ll
total 1860
drwxr-xr-x. 28 1000 1000    4096 Jul  2 19:28 apr-1.5.0
-rw-r--r--.  1 root root 1016391 Dec 26  2013 apr-1.5.0.tar.gz
drwxr-xr-x. 20 1000 1000    4096 Jul  2 19:35 apr-util-1.5.3
-rw-r--r--.  1 root root  874462 Dec 26  2013 apr-util-1.5.3.tar.gz

下载文件:wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/pcre/pcre-8.38.tar.gz

[root@localhost src]# wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/pcre/pcre-8.38.tar.gz
--2020-07-02 19:37:03--  http://zy-res.oss-cn-hangzhou.aliyuncs.com/pcre/pcre-8.38.tar.gz
Resolving zy-res.oss-cn-hangzhou.aliyuncs.com (zy-res.oss-cn-hangzhou.aliyuncs.com)... 47.110.23.248
Connecting to zy-res.oss-cn-hangzhou.aliyuncs.com (zy-res.oss-cn-hangzhou.aliyuncs.com)|47.110.23.248|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2053336 (2.0M) [application/x-gzip]
Saving to: ‘pcre-8.38.tar.gz’

100%[====================================================================================================================================================================================================>] 2,053,336   1.59MB/s   in 1.2s   

2020-07-02 19:37:04 (1.59 MB/s) - ‘pcre-8.38.tar.gz’ saved [2053336/2053336]

解压缩下载文件:tar zxvf apr-util-1.5.3.tar.gz
并进入文件目录:cd apr-util-1.5.3

[root@localhost src]# tar zxvf pcre-8.38.tar.gz 
...........
[root@localhost src]# cd pcre-8.38
[root@localhost pcre-8.38]# ll
total 4548
-rwxr-xr-x. 1 1169 1169   7004 Oct 27  2015 132html
-rw-r--r--. 1 1169 1169  54592 Nov 23  2015 aclocal.m4
-rwxr-xr-x. 1 1169 1169   5826 Nov 23  2015 ar-lib
-rw-r--r--. 1 1169 1169    851 Apr 14  2015 AUTHORS
-rw-r--r--. 1 1169 1169 285447 Nov 23  2015 ChangeLog
-rwxr-xr-x. 1 1169 1169   1493 Jan 31  2014 CheckMan
..............
drwxr-xr-x. 2 1169 1169   4096 Nov 23  2015 sljit
drwxr-xr-x. 2 1169 1169   4096 Nov 23  2015 testdata
-rwxr-xr-x. 1 1169 1169   4640 Nov 23  2015 test-driver
-rw-r--r--. 1 1169 1169   5215 Sep 15  2014 ucp.h
[root@localhost pcre-8.38]# 

检查安装环境:./configure –prefix=/usr/local/pcre

[root@localhost pcre-8.38]# ./configure --prefix=/usr/local/pcre
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
........
    Link pcretest with libreadline .. : no
    Valgrind support ................ : no
    Code coverage ................... : no

编译及安装:make && make install

[root@localhost pcre-8.38]# make && make install
rm -f pcre_chartables.c
ln -s ./pcre_chartables.c.dist pcre_chartables.c
make  all-am
make[1]: Entering directory `/usr/local/src/pcre-8.38'
......
make[3]: Leaving directory `/usr/local/src/pcre-8.38'
make[2]: Leaving directory `/usr/local/src/pcre-8.38'
make[1]: Leaving directory `/usr/local/src/pcre-8.38'

2.5 安装Apache

进入/usr/local/src目录:cd /usr/local/src/

[root@localhost pcre-8.38]# cd /usr/local/src/
[root@localhost src]# ll
total 3884
drwxr-xr-x. 28 1000 1000    4096 Jul  2 19:28 apr-1.5.0
-rw-r--r--.  1 root root 1016391 Dec 26  2013 apr-1.5.0.tar.gz
drwxr-xr-x. 20 1000 1000    4096 Jul  2 19:35 apr-util-1.5.3
-rw-r--r--.  1 root root  874462 Dec 26  2013 apr-util-1.5.3.tar.gz
drwxr-xr-x.  9 1169 1169   12288 Jul  2 19:39 pcre-8.38
-rw-r--r--.  1 root root 2053336 Dec 12  2016 pcre-8.38.tar.gz

下载文件:wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/apache/httpd-2.4.23.tar.gz

[root@localhost src]# wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/apache/httpd-2.4.23.tar.gz
--2020-07-02 19:41:41--  http://zy-res.oss-cn-hangzhou.aliyuncs.com/apache/httpd-2.4.23.tar.gz
Resolving zy-res.oss-cn-hangzhou.aliyuncs.com (zy-res.oss-cn-hangzhou.aliyuncs.com)... 47.110.23.248
Connecting to zy-res.oss-cn-hangzhou.aliyuncs.com (zy-res.oss-cn-hangzhou.aliyuncs.com)|47.110.23.248|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8406575 (8.0M) [application/x-gzip]
Saving to: ‘httpd-2.4.23.tar.gz’

100%[====================================================================================================================================================================================================>] 8,406,575   1.76MB/s   in 4.6s   

2020-07-02 19:41:45 (1.74 MB/s) - ‘httpd-2.4.23.tar.gz’ saved [8406575/8406575]

解压缩下载文件:tar zxvf apr-util-1.5.3.tar.gz
并进入文件目录:cd apr-util-1.5.3

[root@localhost src]# tar zxvf httpd-2.4.23.tar.gz 
......
[root@localhost src]# cd httpd-2.4.23
[root@localhost httpd-2.4.23]# ll
total 1984
-rw-r--r--.  1 501 games   13496 Apr 15  2015 ABOUT_APACHE
-rw-r--r--.  1 501 games   24689 Jun 29  2016 acinclude.m4
-rw-r--r--.  1 501 games   65340 Jun 14  2016 Apache-apr2.dsw
-rw-r--r--.  1 501 games   79911 Jun 14  2016 Apache.dsw
............
drwxr-xr-x.  4 501 games    4096 Jul  2 19:42 support
drwxr-xr-x.  2 501 games     255 Jul  2 19:42 test
-rw-r--r--.  1 501 games    8183 Feb 28  2007 VERSIONING
[root@localhost httpd-2.4.23]# 

检查安装环境:./configure –prefix=/usr/local/apache –sysconfdir=/etc/httpd –enable-so –enable-cgi –enable-rewrite –with-zlib –with-pcre=/usr/local/pcre –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util –enable-mods-shared=most –enable-mpms-shared=all –with-mpm=event

[root@localhost httpd-2.4.23]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-cgi --enable-rewrite --with-zlib --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=event
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
...........
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands

编译及安装:make && make install

[root@localhost httpd-2.4.23]#make && make install
...........
Installing man pages and online manual
mkdir /usr/local/apache/man
mkdir /usr/local/apache/man/man1
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make[1]: Leaving directory `/usr/local/src/httpd-2.4.23'

2.6 配置httpd.conf

进入配置目录:cd /etc/httpd/

[root@localhost httpd-2.4.23]# cd /etc/httpd/
[root@localhost httpd]# ll
total 92
drwxr-xr-x. 2 root root  4096 Jul  2 19:46 extra
-rw-r--r--. 1 root root 18246 Jul  2 19:46 httpd.conf
-rw-r--r--. 1 root root 13077 Jul  2 19:46 magic
-rw-r--r--. 1 root root 53015 Jul  2 19:46 mime.types
drwxr-xr-x. 3 root root    37 Jul  2 19:46 original

编辑httpd.conf文件:vi httpd.conf

找到Directory参数,注释掉Require all denied添加Require all granted

    205 <Directory />
    206     AllowOverride none
    207     #Require all denied
    208 </Directory>

找到ServerName参数,添加ServerName localhost:80 然后,按Esc键后输入:wq保存退出

198 ServerName localhost:80

设置PidFile路径,在文件末尾添加

499 PidFile "/var/run/httpd.pid"

2.7 启动

进入apache安装bin目录:cd /usr/local/apache/bin/

[root@localhost bin]# cd /usr/local/apache/bin/
[root@localhost bin]# ll
total 2504
-rwxr-xr-x. 1 root root   98248 Jul  2 19:46 ab
-rwxr-xr-x. 1 root root    3434 Jul  2 19:43 apachectl
-rwxr-xr-x. 1 root root   23514 Jul  2 19:43 apxs
-rwxr-xr-x. 1 root root   13200 Jul  2 19:46 checkgid
-rwxr-xr-x. 1 root root    8925 Jul  2 19:43 dbmmanage
-rw-r--r--. 1 root root    1071 Jul  2 19:43 envvars
-rw-r--r--. 1 root root    1071 Jul  2 19:43 envvars-std
-rwxr-xr-x. 1 root root   23760 Jul  2 19:46 fcgistarter
-rwxr-xr-x. 1 root root   79872 Jul  2 19:46 htcacheclean
-rwxr-xr-x. 1 root root   47408 Jul  2 19:46 htdbm
-rwxr-xr-x. 1 root root   25160 Jul  2 19:46 htdigest
-rwxr-xr-x. 1 root root   49120 Jul  2 19:46 htpasswd
-rwxr-xr-x. 1 root root 2064888 Jul  2 19:46 httpd
-rwxr-xr-x. 1 root root   22072 Jul  2 19:46 httxt2dbm
-rwxr-xr-x. 1 root root   25024 Jul  2 19:46 logresolve
-rwxr-xr-x. 1 root root   41288 Jul  2 19:46 rotatelogs

启动:./apachectl start
查看80端口是否已经开启:netstat -tnlp

[root@localhost bin]# ./apachectl start
[root@localhost bin]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1058/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1271/master         
tcp6       0      0 :::80                   :::*                    LISTEN      49814/httpd         
tcp6       0      0 :::22                   :::*                    LISTEN      1058/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1271/master

浏览器输入:http://ip

2.8 设置开机启动

在rc.local文件中添加/usr/local/apache/bin/apachectl start,然后输入:wq保存退出:vi /etc/rc.d/rc.local

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

/usr/local/apache/bin/apachectl start

2.9 设置环境变量

编辑root环境变量:vi /root/.bash_profile
在PATH路径后添加::/usr/local/apache/bin

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/apache/bin

export PATH

使环境变量生效:source /root/.bash_profile

三、验证

浏览器页面输入:http://ip

image-15.png (1409×809)

如果打不开,确认防火墙是否关闭,没有的话,禁用防火墙

发表回复