Linux installs Apache service and deploys website

  • About the author: A cloud computing network operation and maintenance personnel, sharing network and operation and maintenance technology and useful information every day.​ 

  • Public account: Netdou Cloud Computing School

  •  Motto: Keep your head down and be respectful

  • Personal homepage: Internet Bean’s homepage​​​​​

write in front

Hello everyone, I am a network bean. This chapter will explain to you how to install the Apache service. Learn how to install, configure and use.


Early understanding:

Web website services


1. Apache installation

1. Use compile and install:

Advantages of compiling and installing:
  • Has a greater degree of freedom and the functions can be customized
  • Get the latest software version in a timely manner
  • Generally applicable to mostLinux versions, easy to transplant and use

 Get the source code package of the Apache server:

Reference address:http://httpd.apache.org/download.cgi

 2. Operation steps:

 3. Preparation work

1. Installation package

Apache configuration and operation require the support of apr, pcre and other software packages, so the software and development kit should be pre-installed from the system CD

rpm -ivh apr-1.4.8-3.el7.x86_64.rpm
rpm -ivh apr-devel-1.4.8-3.el7.x86_64.rpm
rpm -ivh cyrus-sasl-devel-2.1.26-20.el7_2.x86_64.rpm
rpm -ivh expat-devel-2.1.0-8.el7.x86_64.rpm
rpm -ivh libdb-devel-5.3.21-19.el7.x86_64.rpm
rpm -ivh openldap-devel-2.4.40-13.el7.x86_64.rpm
rpm -ivh apr-util-devel-1.5.2-6.el7.x86_64.rpm
rpm -ivh apr-util-1.5.2-6.el7.x86_64.rpm
rpm -ivh pcre-devel-8.32-15.el7_2.1.x86_64.rpm
rpm -ivh pcre-8.32-15.el7_2.1.x86_64.rpm

2. Source code package compilation and installation

1) Unpack

Unzip the downloaded source code package and release it to the /usr/src directory

tar zxf httpd-2.4.25.tar.gz -C /usr/src
cd /usr/src/httpd-2.4.25/

2) Configuration

Set different customization options, such as specifying the installation path, enabling character sets, etc.

./configure --prefix=/usr/local/httpd  --enable-so --enable-rewrite --enable-charset-lite --enable-cgi

#./configure是一个常见的脚本,用于为你的系统准备编译环境。
# --prefix=/usr/local/httpd 这个选项指定了软件安装的基础目录。
#--enable-so这个选项通常用于Apache HTTP Server(或其他需要动态加载模块的软件)以启用DSO(动态共享对象)支持
#--enable-rewrite 这个选项启用URL重写功能,通常用于Apache的mod_rewrite模块。URL重写允许你根据规则动态地改变请求的URL,这对于实现搜索引擎友好的URL、重定向、访问控制等非常有用。

#--enable-charset-lite 这个选项启用一个轻量级的字符集转换功能。Apache服务器通常需要知道和处理多种字符集,以确保它可以正确地解析和传输不同语言的网页内容。

#--enable-cgi 这个选项启用CGI(Common Gateway Interface)支持。CGI是一个标准,允许Web服务器运行外部程序来生成动态Web内容。启用CGI支持意味着Apache可以执行在服务器上的CGI脚本,这些脚本可以是Python、Perl、Ruby等语言的程序,从而为Web页面提供动态功能。
3) Compile and install
make && make install

3. Confirm the installation results

View the contents of the specified installation directory

ls /usr/local/httpd

Start the service:

/usr/local/httpd/bin/apachectl  start

Open the browser and visit: http://127.0.0.1

4. Optimize execution path

ln -s /usr/local/httpd/bin/* /usr/local/bin
ls -l /usr/local/bin/httpd /usr/local/bin/apachectl
#ln -s /usr/local/httpd/bin/* /usr/local/bin

此命令的目的是将/usr/local/httpd/bin/中的所有文件和子目录的快捷方式(符号链接)放在/usr/local/bin中,这样您就可以直接在命令行中访问它们,而无需键入完整的路径。

#ls -l /usr/local/bin/httpd /usr/local/bin/apachectl

该命令的目的是显示这两个文件的详细信息,例如它们的权限、所有者、大小等。由于您之前创建了符号链接,这些链接应该会指向它们在/usr/local/httpd/bin/中的原始文件,因此这些详细信息应该反映了原始文件的信息。

5. Add httpd system service

①chkconfig command to add system services

② Manually write the unit (unit) configuration file ending with .servicec under /lib/systemd/system/.

1) Use chkconfig to add system services

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

 Add httpd as a system service

chkconfig --add httpd

2) Create a .service configuration file

vim /lib/systemd/system/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
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=graphical.target

3) Power on and start

systemctl  enable httpd.service  //http服务开机自启
systemctl  is-enabled httpd.service   //查看httpd服务自启动状态

 2. Deployment process of web site

  • Determined station name,IPlocation
  • Configure and starthttpdService
  • Deploy web documents
  • AccessWebSite
  • ViewWebsite access status

1. Configure httpd service

vim /usr/local/httpd/conf/httpd.conf

 Check syntax

apachectl -t

 2) Start httpd service

systemctl start httpd

View port

netstat -anpt | grep httpd

3. Deploy web page files

The website root directory is located at

/usr/local/httpd/htdocs

 View the deployed website

cat /usr/local/httpd/htdocs/index.html

 4. View the website on the client machine


Guess you like

Origin blog.csdn.net/yj11290301/article/details/134750244