Deploy lamp platform-Linux, Apache, MySQL and PHP-source code compilation and installation


1. LAMP architecture and source code compilation and installation

1 Overview

mark

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

2. Construction sequence

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

3. The main function of each component

Build Function explanation
Linux (platform) As the foundation of the LAMP architecture, it provides an operating system for supporting Web sites, which can provide better stability and compatibility with the other three components (AMP components also support Windows, UNIX and other platforms)
Apache (Foreground) 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
MySQL (Background) 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
PHP/Perl/Python (intermediate connection) As the three programming languages ​​for developing dynamic webpages, 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, especially suitable for Web application development

4. Advantages of source code compilation and installation

  • The advantage of Yum installation software package is that it is convenient and fast, without considering the dependency package, but the "disadvantage" also happens to be this, that is, during the installation process, human cannot intervene, and you can install whatever is in the source, which leads to certain limitations Sex
  • The feature of source installation is that during the process of compiling and installing, you can set parameters, that is, you can install according to your needs, and the installed version can also be selected by yourself, which is more flexible
  • Some of the key software packages in the following experiments are used to compile and install source code. If you need it, I will share a Baidu cloud disk: https://pan.baidu.com/s/1hmwoSlmFKEMJkceIvf5i6w (Extract code: wssg)
    mark

Second, CentOS 7 builds the LAMP platform

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

cd /opt/
httpd-2.4.29.tar.gz
apr-1.6.2.tar.gz
apr-util-1.6.0.tar.gz
#apr组件包用于支持Apache上层应用跨平台,提供底层接口库,能有效的降低并发连接数、降低进程和减少访问堵塞

Just drag it in, the Xshell I use here

mark
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语言编译器           

I installed the dependency package here directly from the local Yum source warehouse

In order to avoid port conflicts, program conflicts, etc., if you have installed the httpd service before, it is recommended to delete the software package first. This is also a pit I have stepped on!

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

yum -y remove httpd
  1. Configuration 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(通用网关接口)脚本程序支持,便于网站的外部扩展应用访问能力
cd /opt/httpd-2.4.29/

./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
  1. Compile and install
##表示同时开2核进行编译,这里可以去看看虚拟机配置,高的建议8核,效率更高
make -j 2
make install

mark

Execute these two commands and wait quietly for processing

Check, if there are the following files in this directory, it means the compilation and installation are successful

mark

  1. 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
cd /etc
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/
  1. Add httpd system service

Method 1: The old method, suitable for CentOS 6, 7 can also be used, relatively speaking, the efficiency will be slower

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 2: High efficiency, cracked wall recommended!

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

mark

  1. Modify httpd service configuration file
vim /etc/httpd.conf
--52行--修改
Listen 192.198.80.10:80
--197行--取消注释,修改
ServerName www.benet.com:80

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

httpd -t  或 apachectl -t			#检查配置文件的配置项是否有误
Syntax OK

cat /usr/local/httpd/htdocs/index.html
<html><body><h1>It works!</h1></body></html>

systemctl restart httpd.service
  1. Browser access verification
netstat -anpt | grep 80

echo "192.168.126.11 www.benet.com" >> /etc/hosts

192.168.126.11
www.benet.com

mark

2. Compile and install mysql service

  1. Transfer the packages required to install mysql to the /opt directory
Xshell ,拖进去即可
mysql-5.7.17.tar.gz
boost_1_59_0.tar.gz		#支持c++的运行库
  1. Installation environment dependent packages
yum -y install \
gcc \
gcc-c++ \
ncurses \				#字符终端下图形互动功能的动态库
ncurses-devel \			#ncurses开发包
bison \					#语法分析器
cmake					#mysql需要用cmake编译安装
   
yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake
  1. Configuration software module
cd /opt
   
tar zxvf mysql-5.7.17.tar.gz
tar zxvf boost_1_59_0.tar.gz
   
   
   
cd /opt
   
#重命名
   
mv boost_1_59_0 /usr/local/boost
cd /opt/mysql-5.7.17/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \		#指定mysql的安装路径
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ #指定mysql进程监听套接字文件(数据库连接文件)的存储路径
-DSYSCONFDIR=/etc \                             #指定配置文件的存储路径
-DSYSTEMD_PID_DIR=/usr/local/mysql \            #指定进程文件的存储路径
-DDEFAULT_CHARSET=utf8  \                       #指定默认使用的字符集编码,如 utf8
-DDEFAULT_COLLATION=utf8_general_ci \			#指定默认使用的字符集校对规则
-DWITH_EXTRA_CHARSETS=all \						#指定支持其他字符集编码
-DWITH_INNOBASE_STORAGE_ENGINE=1 \              #安装INNOBASE存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \               #安装ARCHIVE存储引擎 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \             #安装BLACKHOLE存储引擎 
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \        	#安装FEDERATED存储引擎 
-DMYSQL_DATADIR=/usr/local/mysql/data \     	#指定数据库文件的存储路径
-DWITH_BOOST=/usr/local/boost \          		#指定boost的路径,若使用mysql-boost集成包安装则-DWITH_BOOST=boost
-DWITH_SYSTEMD=1								#生成便于systemctl管理的文件
   
存储引擎选项:
MYISAM,MERGE,MEMORY,和CSV引擎是默认编译到服务器中,并不需要明确地安装。
静态编译一个存储引擎到服务器,使用-DWITH_engine_STORAGE_ENGINE= 1
可用的存储引擎值有:ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB), PARTITION (partitioning support), 和PERFSCHEMA (Performance Schema)
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/boost \
-DWITH_SYSTEMD=1
   
注意:如果在CMAKE的过程中有报错,当报错解决后,需要把源码目录中的CMakeCache.txt文件删除,然后再重新CMAKE,否则错误依旧
  1. Compile and install
##注意了!这里建议4核,本人是使用8核就会报错
make -j 4
   
make install
  1. Create mysql user
useradd -M -s /sbin/nologin  mysql
  1. Modify the mysql configuration file
vim /etc/my.cnf								#删除原配置项,再重新添加下面内容
[client]									#客户端设置
port = 3306
socket=/usr/local/mysql/mysql.sock			
   
[mysqld]									#服务全局设置
user = mysql       							#设置管理用户
basedir=/usr/local/mysql					#指定数据库的安装目录
datadir=/usr/local/mysql/data				#指定数据库文件的存储路径
port = 3306									#指定端口
character-set-server=utf8					#设置服务器字符集编码格式为utf8
pid-file = /usr/local/mysql/mysqld.pid		#指定pid 进程文件路径
socket=/usr/local/mysql/mysql.sock			#指定数据库连接文件
bind-address = 0.0.0.0						#设置监听地址,0.0.0.0代表允许所有,如允许多个IP需空格隔开
skip-name-resolve							#禁用DNS解析
max_connections=2048						#设置mysql的最大连接数
default-storage-engine=INNODB				#指定默认存储引擎
max_allowed_packet=16M						#设置数据库接收的数据包大小的最大值
server-id = 1								#指定服务ID号
   
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
sql_mode常用值如下:
NO_ENGINE_SUBSTITUTION
如果需要的存储引擎被禁用或未编译,那么抛出错误。不设置此值时,用默认的存储引擎替代,并抛出一个异常
   
STRICT_TRANS_TABLES
在该模式下,如果一个值不能插入到一个事务表中,则中断当前的操作,对非事务表不做限制
   
NO_AUTO_CREATE_USER
禁止GRANT创建密码为空的用户
   
NO_AUTO_VALUE_ON_ZERO
mysql中的自增长列可以从0开始。默认情况下自增长列是从1开始的,如果你插入值为0的数据会报错
   
NO_ZERO_IN_DATE
不允许日期和月份为零
   
NO_ZERO_DATE
mysql数据库不允许插入零日期,插入零日期会抛出错误而不是警告
   
ERROR_FOR_DIVISION_BY_ZERO
在INSERT或UPDATE过程中,如果数据被零除,则产生错误而非警告。默认情况下数据被零除时MySQL返回NULL
   
PIPES_AS_CONCAT
将"||"视为字符串的连接操作符而非或运算符,这和Oracle数据库是一样的,也和字符串的拼接函数Concat相类似
   
ANSI_QUOTES
启用ANSI_QUOTES后,不能用双引号来引用字符串,因为它被解释为识别符
  1. Change the owner group of the mysql installation directory and configuration file
chown -R mysql.mysql /usr/local/mysql/
chown mysql.mysql /etc/my.cnf
  1. Set path environment variable
echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
source /etc/profile
  1. Initialize the database
cd /usr/local/mysql/bin/
./mysqld \
--initialize-insecure \				#生成初始化密码为空
--user=mysql \                      #指定管理用户
--basedir=/usr/local/mysql \        #指定数据库的安装目录
--datadir=/usr/local/mysql/data		#指定数据库文件的存储路径
./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
  1. Add mysqld system service
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/	#用于systemctl服务管理
systemctl daemon-reload			  #刷新识别     
systemctl start mysqld.service    #开启服务
systemctl enable mysqld           #开机自启动
netstat -anpt | grep 3306         #查看端口

mark

  1. Modify the mysql login password
mysqladmin -u root -p password "123123" 	
#给root账号设置密码为abc123,之后提示输入的是原始密码(默认为空)
  1. Grant remote login
mysql -u root -p
    
grant all privileges on *.* to 'root'@'%' identified by '123123';
#授予root用户可以在所有终端远程登录,使用的密码是123123,并对所有数据库和所有表有操作权限
    
show databases;
#查看当前已有的数据库

mark


3. Compile and install PHP parsing environment

  1. Transfer the packages required for installing PHP to the /opt directory
php-7.1.10.tar.bz2

mark

  1. Install GD library and GD library related programs to process and generate pictures
yum -y install \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
  1. Configuration software module
cd /opt
tar jxvf php-7.1.10.tar.bz2
   
cd /opt/php-7.1.10/
./configure \
--prefix=/usr/local/php7 \							#指定将 PHP 程序的安装路径
--with-apxs2=/usr/local/httpd/bin/apxs \			#指定Apache httpd服务提供的apxs 模块支持程序的文件位置
--with-mysql-sock=/usr/local/mysql/mysql.sock \		#指定mysql 数据库连接文件的存储路径
--with-config-file-path=/usr/local/php7				#设置 PHP 的配置文件 php.ini 将要存放的位置
--with-mysqli \										#添加 MySQL 扩展支持 #mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定
--with-zlib \										#支持zlib功能,提供数据压缩
--with-curl \										#开启curl扩展功能,实现HTTP的Get下载和Post请求的方法
--with-gd \											#激活gd 库的支持
--with-jpeg-dir \									#激活jpeg 的支持
--with-png-dir \									#激活png 的支持
--with-freetype-dir \
--with-openssl \
--enable-mbstring \									#启用多字节字符串功能,以便支持中文等代码
--enable-xml \										#开启扩展性标记语言模块
--enable-session \									#会话
--enable-ftp \										#文本传输协议
--enable-pdo \										#函数库
--enable-tokenizer \								#令牌解释器
--enable-zip										#ZIP压缩格式
./configure \
--prefix=/usr/local/php7 \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-config-file-path=/usr/local/php7 \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip
  1. Compile and install
make -j 4

make install
  1. Copy the template file as the main configuration file of PHP and modify it
#在测试环境时使用php.ini-development文件,而在生产环境时是使用php.ini-production文件
cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini	
   
   
vim /usr/local/php7/php.ini
#第 1170 行修改
mysqli.default_socket = /usr/local/mysql/mysql.sock
#第 939行 取消注释,并进行修改
date.timezone = Asia/Shanghai

mark

mark

  1. Optimized to put PHP executable program files into the directory of the path environment variable for easy system identification
ln -s /usr/local/php/bin/* /usr/local/bin/

#查看PHP 加载了哪些模块
php -m 
  1. Modify the configuration file of the httpd service to allow Apache to support PHP
vim /etc/httpd.conf 
第393行插入以下内容
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
   
第255行,修改首页文件名设置
DirectoryIndex index.html index.php
   
#检查支持php7的模块是否存在
LoadModule php7_module        modules/libphp7.so

mark

mark

  1. Verify PHP test page
cd /usr/local/httpd/htdocs/
   
mv index.html index.html.bak
   
vim /usr/local/httpd/htdocs/index.php
<?php
phpinfo();
?>
   
systemctl restart httpd.service
  1. Browser access

http://192.168.126.11

mark


4. Install DIscuz Forum

  1. Create a database and authorize
mysql -u root -p
   
CREATE DATABASE bbs;
#创建一个数据库
   
GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
#把bbs数据库里面所有表的权限授予给bbsuser,并设置密码admin123
   
flush privileges;
#刷新数据库
   
show databases;

mark

  1. Unzip the forum compressed package
unzip /opt/Discuz_X3.4_SC_UTF8.zip -d /opt/dis
cd /opt/dis/dir_SC_UTF8/
   
#上传站点更新包
cp -r upload/ /usr/local/httpd/htdocs/bbs		
  1. Change the owner of the forum directory
cd /usr/local/httpd/htdocs/bbs

chown -R daemon ./config
chown -R daemon ./data
chown -R daemon ./uc_client
chown -R daemon ./uc_server/data
  1. Browser access verification
#论坛页面访问
http://192.168.126.11/bbs

数据库服务器:localhost
###本地架设就用localhost,如何不是在在本机上就要填写IP地址和端口号
数据库名字:bbs
数据库用户名:bbsuser
数据库密码:admin123
管理员账号:admin
管理员密码:admin123
   
论坛后台管理员页面
http://192.168.126.11/bbs/admin.php

mark

mark

mark

mark

mark

Guess you like

Origin blog.csdn.net/weixin_51486343/article/details/112297409