Apache service-detailed installation

Install Apache service

【Introduction】

Apache (Apache HTTP Server) Apache web server, also known as "httpd". It is an open source software that provides web browsing services based on the standard HTTP network protocol. It can run on Linux, UNIX, Windows and other operating system platforms. It is the software formed after the integration and improvement of several web service programs that appeared before.

【main feature】

1. Open source code
2. Cross-platform application: It can run on various operating system platforms such as Linux, UNIX, Windows.
3. Support various web programming languages: The web programming languages ​​supported by the Apache server include Perl, PHP, Python, Java, etc., and even Microsoft's ASP technology can also be used in the Apache server.
4. Modular design: Apache does not concentrate all the functions in a single service program, but as much as possible to achieve proprietary functions through standard modules, which brings good scalability to the Apache server. Other software developers can write standard module programs to add other functions that Apache does not have.
5. Very stable operation: Apache server can be used to build Web sites with heavy traffic.
6. Good security

[Installation prerequisites]

  • Build yum warehouse (source)

    [root@localhost ~]# mount /dev/cdrom /mnt  	(#:挂载光盘)
    [root@localhost ~]# cd /etc/yum.repos.d/        (#:切换至该目录下)
    [root@localhost yum.repos.d]# mkdir backup      (#:创建一个目录用来存放数据)
    [root@localhost yum.repos.d]# mv C* backup/     (#:将以C*开头的所有文件移动到创建的这个目录下)
    [root@localhost yum.repos.d]# cp backup/CentOS-Base.repo local.repo     (#:复制 backup 目录下这个文件至新建的local.repo空文件中)
    [root@localhost yum.repos.d]# vi local.repo     (#:编辑这个文件,文件中只有如下内容)
    [centos]
    name=centos               ####名称
    baseurl=file:///mnt         #####来源、文件寻找路径
    gpgcheck=0                  ##### “0”为不检测 ,“1”为检测
    enabled=1                    ##### “1”为开机自启 , “0”为关闭
    #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7          ###检测内容:因前面不检测所以 “#” 号注释掉
    [root@localhost yum.repos.d]# yum clean all     (#:加载所有 yum 插件)
    [root@localhost yum.repos.d]# yum makecache      (#:清理 yum 软件源)
    ————————————
    结束
    

[Start to install Apache service]

  • [Required software (installation package)]
    apr-1.6.2.tar.gz
    apr-util-1.6.0.tar.gz
    httpd-2.4.29.tar.gz
    upload 3 packages to the /opt directory

    1、 步骤:
    [root@localhost ~]# cd /opt
    [root@localhost opt]# ll
    总用量 8020
    -rw-r--r--  1 root root 1071074 8月   4 17:33 apr-1.6.2.tar.gz
    -rw-r--r--  1 root root  565507 8月   4 17:33 apr-util-1.6.0.tar.gz
    -rw-r--r--  1 root root 6567926 8月   4 17:33 httpd-2.4.29.tar.bz2
    2、 解压包:
    [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
    3、  将第一、二个包移至第三个包下的新目录下:
    [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      (#:安装语言插件)
    [root@localhost opt]# cd /opt/httpd-2.4.29/
    [root@localhost httpd-2.4.29]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi      (#:安装路径及启用各种程序功能)
    
  • [Compile and install]

    [root@localhost httpd-2.4.29]# make -j3     (#:-j3是你核心数,最大不要超过真机的核心数,加载速度会小幅度提升)
    [root@localhost httpd-2.4.29]# make install     (#:make 安装)
    
  • [Optimize the execution path]

    [root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/conf/httpd.conf /etc/
    [root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
    
  • [Create a new configuration file: add system to service]

    [root@localhost ~]# cd /lib/systemd/system/
    [root@localhost system]# vi httpd.service      (编辑文件,直接添加下面内容)
    [Unit]                     (#:这些数据是用于控制由 systemd 管理 或者 监控 httpd 服务的)
    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
    [root@localhost system]# systemctl is-enabled httpd.service    (检验httpd是否是开机自启,如果是,会显示 enabled )
    
  • [Modify httpd.conf configuration file]

    [root@localhost system]# vi /usr/local/httpd/conf/httpd.conf
    ServerName www.51xit.top:80     (#:找到这行,去掉 “#” 号 ,并修改想设的网址)
    [root@localhost system]# systemctl restart httpd
    
  • 【verification】

    [root@localhost system]# netstat -anpt | grep 80
    

Insert picture description here
Just find a webpage and enter your own ip address. The webpage will show the default "It works"
, that is, the Apache service is successfully started.

[Problems encountered]

1. There will be an error when opening httpd.service.
Reason: Which step is to be done less and forgotten, or the parameter in the configuration file is modified incorrectly.
Solution: Re-enter the command after optimizing the path, or reinstall the environment after installing to compiling and installing

2. The httpd.service service fails to start after booting or displays disable status when viewing httpd status.
Cause: The firewall is not turned off.
Solution: Turn off the firewall and turn off the core protection.

=============================================================

That's it, thanks for watching

Guess you like

Origin blog.csdn.net/XCsuperman/article/details/108353121