Install the required software for Apache
- apr-1.6.2.tar.gz
- apr-util-1.6.0.tar.gz
- httpd-2.4.29.tar.bz2
These three packages need to be placed in the opt directory
[root@localhost ~]# cd /opt
[root@localhost opt]# ll
[root@localhost opt]# tar zxvf apr-1.6.2.tar.gz
[root@localhost opt]# tar zxvf apr-util-1.6.0.tar.gz
[root@localhost opt]# tar jxvf httpd-2.4.29.tar.bz2
[root@localhost opt]# mv apr-1.6.2 httpd-2.4.29/srclib/apr
[root@localhost opt]# mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
Installation Environment
[root@localhost opt]#
yum -y install \
gcc \
gcc-c++ \
make \
pcre-devel \
expat-devel \
perl
Configuration module
[root@localhost opt]# cd /opt/httpd-2.4.29/
./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
annotation:
- –Prefix: Specify the directory to which the httpd service program is installed, such as /usr/local/httpd
- --Enable-so: enable dynamic loading module support, so that httpd has the ability to further expand its functions.
- --Enable-rewrite: Enable web address rewrite function for website optimization and catalog migration maintenance.
- --Enable-charset-lite: enable character set support to support the use of various character set encoding network
- --Enable-cgi: Enable CGI script program support, which is convenient for expanding the application access capability of the website.
Compile and install
[root@localhost opt]# make -j3
[root@localhost opt]# make install
Note:
-j3 is the number of your cores, and the maximum number should not exceed the number of cores of the virtual machine.
Optimize execution path
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/
httpd -v ###查看HTTP版本
Create [service].service configuration file to add system to service
[root@localhost ~]# cd /lib/systemd/system/
[root@localhost system]# vim httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/httpd/logs/httpd.pid
ExecStart= /usr/local/bin/apachectl $OPTIONS
ExecrReload= /bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@localhost system]# systemctl start httpd.service
[root@localhost system]# systemctl enable httpd.service ###开机自启http
[root@localhost system]# systemctl start httpd.service ###检查HTTP单元是否启动
**Note:** Remember! ! ! Remember! ! ! Turn off the firewall first! ! !
httpd.conf modify the configuration file
vi /usr/local/httpd/conf/httpd.conf
ServerName www.51xit.top:80 ###更改下
systemctl restart httpd ####重启httpd服务
Verify with the system browser
netstat -anpt | grep 80 #过滤80端口,检验是否开启
Note:
You can use the ip address for verification