Source code compiling and installing LAMP architecture operation command-LAMP installation forum (Apache, Mysql, PHP source code installation and deployment)

LAMP architecture and source code compilation and installation

1. Overview of LAMP

LAMP architecture is the current mature enterprise website application model, 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 includesLinux operating system,Apache web server,MySQL database server,PHP (or Perl, Python) web programming language.

Second, the role of each component of LAMP

Linux (platform) :As the foundation of the LAMP architecture, Provides an operating system to support the Web site, 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, Is a powerful, stable web server program, the server directly and provides users with website access, sending web pages, pictures and other file content.

MySQL (Background) :As the back end of the LAMP architecture, 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 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. 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, responsible for communicating with the Web server and database system to work together.

Three, source code compilation and installation

3.1, compile and install Apache httpd service

3.1.1. Turn off the firewall and upload the software packages needed 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
#apr组件包用于支持Apache.上层应用跨平台,提供底层接口库,能有效的降低并发连接数、降低进程和减少访问堵塞

3.1.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- Yinstall gcc gcc-c++ make pcre pcre-devel expat-devel perl

3.1.3, 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/
mv apr-util-1.6.0 /opt/httpd-2. 4.29/ srcl ib/ 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

3.1.4, compile and install

make             #make -j2表示开2核同时进行编译
make install     #不进行安装/usr/local/httpd这个目录不会生成

3.1.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 /ysr/1ocal/httpd/bin/* /usr/local/bin/

3.1.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 /1ib/ systemd/ system/httpd. service
[Unit]
Description=The Apache HTTP Server                           #描述
After=network. target                                        #描述服务类别
[Service]
Type= forking                                                #后台运行方式
P1DFile=/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

3.1.7, modify the httpd service configuration file

修改配置文件之前,最好做个备份
vim /etc/httpd.conf
--52行--修改
Listen 192.198.80.10:80
--197行--取消注释,修改
Serve rName WWw.cxy.com: 80
--221行--默认首页存放路径
DocumentRoot "/usr/local/httpd/htdocs”
--255行--默认首页文件名设置
Di rectoryIndex index. html

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

3.1.8, browser access verification

netstat -anpt| grep 80
echo "192.168.80.10 www. kgc. com" >> /etc/hosts
http: I /192.168.80.10
http: I /www.cxy.com

3.2, install Apache httpd experimental operation

3.2.1. Give the virtual machine a larger memory and cpu, so the installation will be faster

Insert picture description here

3.2.2. First turn off the firewall and security protection, if you do not execute the command later, an error may be reported.

Then pull the software package directly to the /opt directory in the virtual machine

Insert picture description here

3.2.3, build local yum source and installation environment dependency package

Insert picture description here

3.2.4. Decompress the software package (a bit too much, not one by one). Move the location of the software package, you can change the name of the software package for easy operation

Insert picture description here


Insert picture description here


Insert picture description here

3.2.5. Configure the software module –prefix (installation designated directory)=/usr/local/httpd, designated to the /usr/local/httpd directory

Insert picture description here

3.2.6, compile and install

Insert picture description here


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

3.2.8, add httpd system service

First copy and back up the
script execution file, configure the script execution file, insert the configuration in the first three lines,
add the httpd service to the system, and restart the httpd service

Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here

3.2.9, modify httpd service configuration file

Make a backup first,

Insert picture description here


change the listening address

Insert picture description here

Open the access domain name to

Insert picture description here


see if there are any errors in the grammar, and see if an error is reported when the service is restarted

Insert picture description here

3.2.10, and then enter the virtual machine to visit the IP, it works! I told you that it was successful

Insert picture description here


Because what is written in the configuration file is it works!

Insert picture description here


Enter the /etc/hosts configuration file, enter the ip address and domain name to achieve access using domain names

Insert picture description here


Insert picture description here

3.3, compile and install mysqld service

3.3.1. Transfer the software packages required to install mysql to the /opt directory

mysql-5.7.17.tar.gZ
boost_1_59_ 0.tar.gz                         #支持c++的运行库

3.3.2, 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

3.3.3, configuration software module

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/mysq1-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 \                #安装BLACKH0LE存储引擎
-DWITH PERFSCHEMA STORAGE ENGINE=1 \               #安装FEDERATED存储引擎
-DMYSQL_DATADIR=/usr/local/mysql/data \            #指定数据库文件的存储路径
-DWITH_BOOST=/usr/local/boost \ #指定boost的路径,若使用mysql-boost集成包安装则-DWITH_ B0OST=boost
-DWITH_SYSTEMD=1                                   #生成便于systemctl管理的文件

Storage engine options:

MYISAM,MERGE,MEMORY, withCSVThe engine is compiled into the server by default and does not need to be explicitly installed.

Statically compile a storage engine to the server, use-DWITH_engine_STORAGE_ENGINE= 1

The available storage engine values ​​are: ARCHIVE,BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB), PARTITION (partitioning support) ,withPERFSCHEMA (Per formance Schema)

Note: If there is an error in the CMAKE process, after the error is resolved, you need to delete the CMakeCache.txt file in the source directory, and then re-CMAKE, otherwise the error will remain

3.3.4, compile and install

make && make install

3.3.5, create mysq1 user

useradd -M -s /sbin/nologin mysql

3.3.6, modify the mysql configuration file

vim /etc/my.cnf              #删除原配置项,再重新添加下面内容
[client]                     #客户端设置
port = 3306
socket = /usr/local/mysql/mysql.sock


[mysq1]                      #服务端设置
port = 3306
socket = /usr/local/mysq1/mysql.sock
auto-rehash                  #开启自动补全功能


[mysqld]                                    #服务全局设置
user = mysql                                #设置管理用户
basedir=/usr/local/mysql                    #指定数据库的安装目录
datadir=/usr/local/mysql/data               #指定数据库文件的存储路径
port = 3306                                 #指定端口
character-set-server=utf8                   #设置服务器字符集编码格式为utf8
pid-file = /usr/1ocal/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                        #设置mysq1的最大连接数
de fault-storage-engine= INNODB             #指定默认存储引擎
max_ allowed packet=16M                     #设置数据库接收的数据包大小的最大值
server-id = 1                               #指定服务ID号

sql_mode=NO_ENGINE_UBSTITUTION, 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后,不能用双引号来引用字符串,因为它被解释为识别符

3.3.7, change the owner group of the mysql installation directory and configuration file

chown -R mysql:mysql /usr/local/mysq1/
chown mysql:mysql /etc/my.cnf

3.3.8, set the path environment variable

echo ' export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
source /etc/profile

3.3.9, initialize the database

cd /usr/local/mysql/bin/
. /mysqld \
--initialize-insecure \              #生成初始化密码为空
--user=mysq1 \                       #指定管理用户
--basedir=/usr/local/mysql \         #指定数据库的安装目录
--datadir=/usr/local/mysql/data      #指定数据库文件的存储路径

3.3.10, add mysqld system service

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service/usr/lib/systemd/system/
#用于systemct1服务管理
systemctl daemon-reload                 #刷新识别
systemctl start mysqld.service          #开启服务
systemctl enable mysqld                 #开机自启动
netstat -anpt | grep 3306               #查看端口

3.3.11, modify the mysql login password

mysqladmin -u root -p password "abc123"      #给root账号设置密码为abc123,提示输入的是原始密码(为空)

3.3.12, authorized remote login

mysql -u root -p
grant all privileges on *.* to 'root'@'%' identified by 'abc123';
#授予root用户可以在所有终端远程登录,使用的密码是abc123,并对所有数据库和所有表有操作权限
show databases;                 #查看当前已有的数据库

3.4, install mysql experimental operation

3.4.1. Pull the compressed file directly to the opt directory

Insert picture description here

3.4.2, installation environment dependent packages

Insert picture description here

3.4.3, configuration module

Unzip the file package,

Insert picture description here


move the boost file to the /usr/local/boost directory, and

Insert picture description here


enter the mycql directory to execute the compilation operation

Insert picture description here

3.4.4 Compile and install

Insert picture description here


After compiling and installing, there is a mysql directory generated in the /usr/local directory

Insert picture description here

3.4.5, create user

Insert picture description here

3.4.6, modify the mysql configuration file

Enter the /etc/my.cnf configuration file, delete all the original configuration inside, and enter the modified configuration file

Insert picture description here

3.4.7, change the owner group of the mysql installation directory and configuration file

Insert picture description here

3.4.8, set the path environment variable

Enter the /etc/profile configuration file to add a path variable,

Insert picture description here


you can see that these two directories have been added to the variable

Insert picture description here

3.4.9, initialize the database

There is a mysqld file in the bin directory, to execute this file initialization

Insert picture description here

3.4.10, add mysqld system service

Copy mysqldthe file to usr/lib/systemd/system/the directory, refresh it, start the service, set the boot to start automatically, and check whether the port is executed successfully

Insert picture description here

3.4.11, modify the mysql login password

Insert picture description here

3.4.12, authorized remote login

Insert picture description here


show databases;You can use to view the database,

Insert picture description here


authorize all permissions to give all tables in the library to the root user of all groups, and then set the password “abc123”, pay attention to use the ;end

Insert picture description here

3.5, compile and install PHP parsing environment

3.5.1, transfer the software packages required for installing PHP to the /opt directory

php-7.1.10.tar.bz2
yum -y install \
gd \
libjpeg libjpeg-devel \
1 ibpng 1 ibpng-devel \
freetype freetype-devel \
l ibxml2 libxml2 -devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel

3.5.3, configuration software module

cd /opt
tar jxvf php-7.1.10.tar.bz2
cd /opt/php-7.1.10/
. / configure\
--prefix=/usr/1ocal/php7 \                       #指定将PHP 程序的安装路径
--with-apxs2=/usr/local/httpd/bin/apxs \         #指定Apachehttpd服务提供的apxs模块支持程序的文件位置
--with-mysql-sock=/usr/local/mysq1/mysq1.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压缩格式

3.5.4, compile and install

make && make install

3.5.5. Copy the template file as the main configuration file of PHP and modify it

cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini
#在测试环境时使用php.ini-development文件,而在生产环境时使用php.ini-production文件
vim /usr/local/php7/php.ini
--1170行--修改
mysqli.default_socket = /usr/local/mysql/mysql.sock
--939行--取消注释,修改
date.timezone = Asia/Shanghai

3.5.6. Optimize the PHP executable program file to be placed in the directory of the path environment variable to facilitate system identification

ln -s /usr/local/php7/bin/* /usr/local/bin/
php -m                                     #查看PHP加载了哪些模块

3.5.7. Modify the configuration file of 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

3.5.8, verify the PHP test page

rm -rf /usr/local/httpd/htdocs/index.html
vim /usr/1ocal/httpd/htdocs/index.php
<?php
phpinfo();
?>

systemctl restart httpd. service 

浏览器访问
http: //192.168.111.40

3.6, install PHP experiment operation

3.6.1. Install the PHP software package in the opt directory

Insert picture description here

3.6.2. Unzip the software package and install the GD library file

Insert picture description here


Insert picture description here

3.6.3, configuration software module

There is a configure configuration file in the /opt/php directory, execute the file, and enter the configuration file

Insert picture description here

3.6.4, compile and install

Insert picture description here

3.6.5. Copy the template file and modify it

There are 2 template files in the php-7.1.10 directory. Just copy one to the /usr/local/php7/ directory as the main configuration file. The configuration file name is php.ini.

Insert picture description here


Modify the specified mysql database link file.

Insert picture description here


Set the time zone (Asia Shanghai)

Insert picture description here

3.6.6, optimize the path

Insert picture description here

3.6.7, modify httpd service configuration file

Insert two configuration commands under line 393.

Insert picture description here


Check whether the php module is generated. If it is generated, the installation is successful. If not, it needs to be reinstalled.

Insert picture description here


Add another file

Insert picture description here


after the file under line 256. There is in the htdocs directory under the /usr/local/httpd directory. An index.html file, we don’t need it, change its file name, we re-create a file name, and write related programs in it

3.6.8. Log in to the PHP test page

Insert picture description here


Insert picture description here


After the configuration is complete, restart the service

Insert picture description here


and then we go to visit, the php is configured, and there are configuration files inside

Insert picture description here


Insert picture description here

3.7, install the forum

3.7.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;                           #查看数据库

3.7.2, decompress 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               #上传站点更新包

3.7.3, change the owner of the forum directory

ps aux                                    #查看发现论坛进程的用户名是daemon
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

3.7.4, browser access verification

Forum page access

http:/ /192.168.80.10/bbs

Database server: localhost (Use localhost for local setup, if you don’t need to fill in the IP address and port number on this machine)
Database name: bbs
database user name: bbsuser
database password: admin123
administrator account: admin
administrator password: admin123

3.7.5, log in to the administrator page of the forum background

http://192.168.111.40/bbs/admin.php

Forum installation operation command

3.8.1, authorization, create a database

Authorize login

Insert picture description here


Create database

Insert picture description here


Authorize all tables in the bbs library with all permissions to bbsusers (name whatever you want) @给% (representing all hosts), and then set a password "admin123" for it

Insert picture description here


Then refresh the permissions to exit

Insert picture description here

3.8.2. Install the forum installation package and unzip

Insert picture description here


Insert picture description here


Insert picture description here


Copy the upload directory to the /usr/local/httpd/htdocs directory and rename it to bbs

Insert picture description here

3.8.3, enter the browser to access the test

The original IP access is a php page

Insert picture description here


now we add bbs after the IP into the installation interface

Insert picture description here


here looking into the installation click I agree you can see ./config, ./data, ./uc_client, ./uc_serverno rights, we have to give it permission to

Insert picture description here


Insert picture description here


refresh a bit, the next step, select a new installation

Insert picture description here


Install the database, change the database name, set the database user name, set the database password and set the administrator password, the next step is

Insert picture description here


to visit after installation

Insert picture description here


Insert picture description here