LAMP-compile and install Apache service (4-1)

1. Overview of LAMP

1 Introduction

The LAMP architecture is one of the current mature enterprise website application modes. It refers to a set of systems and related software that work together to provide dynamic website services and application development environments. LAMP is an acronym that specifically includes Linux operating system, Apache web server, MySQL database server, PHP (or Perl, Python) web programming language.

2. The role of each component

L: (Platform) Linux: As the foundation of the LAMP architecture, it provides an operating system to support Web sites, which can provide better stability and compatibility with the other three components (AMP components also support Windows, UNIX and other platforms).
A: (Foreground) Apache: As the front end of the LAMP architecture, it is a powerful and stable web server program that directly provides users with website access, sending web pages, pictures and other file content.
M: (Background) MySQL: As the back end of the LAMP architecture, it is a popular open source relational database system. In applications such as corporate websites and business systems, various account information, product information, customer information, business data, etc. can be stored in the MySQL database, and other programs can query and change this information through SQL statements.
P: (Intermediate connection) PHP/Perl/Python: As three programming languages ​​for developing dynamic web pages, it is responsible for interpreting dynamic webpage files, communicating with web servers and database systems for collaborative work, and providing a development and operating environment for web applications. Among them, PHP is a widely used open source multi-purpose scripting language, which can be embedded in HTML, and is especially suitable for Web application development.

3. Installation sequence of each component

When building the LAMP platform, the order of installation of each component is Linux, Apache, MySQL, PHP. Among them, there is no strict order for the installation of Apache and MySQL. The installation of the PHP environment is generally placed at the end of the installation, responsible for communicating with the Web server and the database system to work together.

4. Related software packages

Link: LAMP software package
Extraction code: 59mp

Second, build the structure

1. Turn off the firewall, and upload the software packages required to install Apache to the /opt directory

systemctl stop firewalld
systemctl disable firewalld
setenforce 0

httpd-2.4.29.tar.gz
apr-1.6.2.tar.gz
apr-util-1.6.0.tar.gz

The apr component package is used to support cross-platform Apache upper-level applications and provide the underlying interface library, which can effectively reduce the number of concurrent connections, reduce processes, and reduce access congestion.
Insert picture description here
Insert picture description here

2. The installation environment depends on the package

yum -y install \
gcc \							#C语言的编译器
gcc-c++ \						#C++的编译器
make \							#源代码编译器(源代码转换成二进制文件)
pcre \							#pcre是一个Perl函数库,包括perl 兼容的正则表达式库
pcre-devel \                    #perl的接口开发包
expat-devel \                   #用于支持网站解析HTML、XML文件
perl                            #perl语言编译器

yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl       

Insert picture description here

3. Configure the software module

cd /opt/
tar zxvf apr-1.6.2.tar.gz
tar zxvf apr-util-1.6.0.tar.gz
tar jxvf httpd-2.4.29.tar.bz2

mv apr-1.6.2 /opt/httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util

cd /opt/httpd-2.4.29/
./configure \
--prefix=/usr/local/httpd \		#指定将 httpd 服务程序的安装路径
--enable-so \					#启用动态加载模块支持,使 httpd 具备进一步扩展功能的能力
--enable-rewrite \				#启用网页地址重写功能,用于网站优化、防盗链及目录迁移维护
--enable-charset-lite \			#启动字符集支持,以便支持使用各种字符集编码的页面
--enable-cgi					#启用CGI(通用网关接口)脚本程序支持,便于网站的外部扩展应用访问能力

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

Insert picture description here
Insert picture description here
Insert picture description here

4. Compile and install

make							#make -j 2  表示开2核同时进行编译
make install
make && make install

Insert picture description here

5. Optimize the configuration file path, and put the executable program file of the httpd service into the directory of the path environment variable for easy system identification

ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/

Insert picture description here

6. Add httpd system service

方法一:
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd		#用于service服务管理
chmod +x /etc/init.d/httpd
vi /etc/init.d/httpd
#!/bin/bash												#在第一行前插入新行,添加此三行内容
#chkconfig: 35 85 21									#35级别自动运行  第85个启动 第21个关闭
#description: Apache is a World Wide Web server
chkconfig --add httpd     		                        #将httpd服务加入到service管理器
systemctl start httpd.service 
或
service httpd start

Method Two:

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					#PID文件位置
ExecStart=/usr/local/bin/apachectl $OPTIONS				#启动服务
ExecReload=/bin/kill -HUP $MAINPID						#根据PID重载配置
[Install]
WantedBy=multi-user.target

systemctl start httpd.service
systemctl enable httpd.service

vim /lib/systemd/system/httpd.service interface
Insert picture description here
Insert picture description here

7. Modify the httpd service configuration file

vim /etc/httpd.conf
--52行--修改
Listen 192.198.221.20:80
--197行--取消注释,修改
ServerName www.srs.com:80

--221行--默认首页存放路径
DocumentRoot "/usr/local/httpd/htdocs"
--255行--默认首页文件名设置
DirectoryIndex index.html

httpd -t  或 apachectl -t			#检查配置文件的配置项是否有误
cat /usr/local/httpd/htdocs/index.html
systemctl restart httpd.service

Insert picture description here
Insert picture description here

8. Browser access verification

netstat -anpt | grep 80
echo "192.168.80.10 www.srs.com" >> /etc/hosts

http://192.168.221.20
http://www.srs.com

Insert picture description here

Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/s15212790607/article/details/115133246