LAMP source code compilation and installation of Apache

LAMP source code compilation and installation of Apache

1. Overview of the basic architecture of LAMP

1.LAMP architecture

It 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 web site services and application development environments. LAMP is an acronym that specifically includes Linux operating system, Apache web server, MySOL database server, PHP (or erl, Python) web programming language.

2. The main functions of each component are as follows

(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).

(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.

(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.

(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 to work together, 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.

When building the LAMP platform, the order of installation of each component is Linux, Apache, MySQL, PHP. There is no strict order for the installation of Apache and MysOL. The installation of the PHP environment is usually placed at the end, responsible for communicating with the web server and database system to work together.

2. Compile and install Apache httpd service

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

2. Installation environment dependent packages

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 

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

4. Compile and install

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

5. Optimize the configuration file path

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/

6. Add httpd system service

method one:

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
Description=The Apache HTTP Server				#描述								        	#描述服务类别
Type=forking										            	#后台运行方式
PIDFile=/usr/local/httpd/logs/				#PID文件位置
ExecStart=/usr/local/bin/apachectl $OPTIONS			#启动服务
ExecReload=/bin/kill -HUP $MAINPID						#根据PID重载配置

systemctl start httpd.service
systemctl enable httpd.service

7. Modify the httpd service configuration file

vim /etc/httpd.conf

DocumentRoot "/usr/local/httpd/htdocs"
DirectoryIndex index.html

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

8. Browser access verification

netstat -anpt | grep 80
echo "" >> /etc/hosts
Insert picture description here

Insert picture description here