LAMP website structure

LAMP website structure

LAMP

What is LAMP

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 web site 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.

The role of each component

(Platform) Inuz: As the foundation of the LAMP architecture, it 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).
(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.
note! : 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 the database system to work together.

Configuration

Apache httpd installation

Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here
Insert picture description here


Insert picture description here


Insert picture description here
Insert picture description here


Insert picture description here
修改httpd 服务配置文件
vim /etc/httpd.conf
--52行--修改
Listen 192.198.80.10:80
--197行--取消注释,修改
ServerName www.kgc.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

Validation results:

Insert picture description here

mysqld service installation

Insert picture description here


Insert picture description here


Unzip the compressed package

tar zxvf mysql-5.7.17.tar.gz
tar zxvf boost_1_59_0.tar.gz

Rename

Insert picture description here
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管理的文件

Compile 4 cores together

Insert picture description here


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

[mysql]										#服务端设置
port = 3306
socket = /usr/local/mysql/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/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
Insert picture description here


Insert picture description here


Initialize the database

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

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       #查看端口

Modify the login password of mysql

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

Authorize remote login

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

PHP

Transfer the software packages required to install PHP to the /opt directory

php-7.1.10.tar.bz2

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

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压缩格式

Compile and install

make -j 4 && make install

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

Optimized to put PHP executable program files into the directory of the path environment variable for easy system identification

ln -s /usr/local/php7/bin/* /usr/local/bin/

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
Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here


The result is

Insert picture description here

Install forum

Insert picture description here


Insert picture description here


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		#上传站点更新包
ps aux  #查看发现论坛进程的用户名是daemon
Insert picture description here


result

Insert picture description here