Building Discuz forum based on LAMP architecture

Keywords: Python node.js Linux


1. Introduction to lamp architecture

1.1 general

1.2 construction sequence

1.3 main functions of each component

1.4 advantages of source code compilation and installation

2. Architecture construction process

2.1 preparation before installation

2.2 installing apache

2.3 installing mysql

2.4 installing PHP

1. Introduction to lamp architecture

1.1 general

LAMP architecture is one of the mature enterprise website application modes at present. It refers to a complete set of systems and related software working together, which can provide dynamic Web site services and its application development environment
LAMP is an abbreviation, including Linux operating system, Apachche website server, MySQL database server, PHP (or Perl, Python) web programming language

1.2 construction sequence

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

1.3 main functions of each component

1.4 advantages of source code compilation and installation

  The advantage of Yum installing software package is that it is convenient and fast, without considering relying on the package, but the "disadvantage" is just this, that is, in the installation process, people can't intervene, and install what is in the source, resulting in certain limitations

The feature of source code installation is that during the compilation and installation process, 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

2. Architecture construction process

2.1 preparation before installation

systemctl stop firewalld && systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config
echo "nameserver" >> /etc/resolv.conf
reboot	#Restart the host

2.2 installing apache

Download the installation package to the specified directory (the directory is selected by itself)

systemctl stop firewalld && systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config
echo "nameserver" >> /etc/resolv.conf
reboot	#Restart the host

Unzip the installation package to the / opt directory

#apr component package is used to support Apache upper application cross platform and provide lower interface library, which can effectively reduce the number of concurrent connections, processes and access congestion
tar xf /data/apr-1.6.2.tar.gz -C /opt
tar xf /data/apr-util-1.6.0.tar.gz -C /opt 
tar xf /data/httpd-2.4.29.tar.bz2 -C /opt
mv apr-1.6.2 httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util

Installation dependent environment

yum -y install \
gcc \							#C language compiler
gcc-c++ \						#C + + compiler
make \							#Source code compiler (source code to binary)
pcre \							#pcre is a perl function library, including perl compatible regular expression library
pcre-devel \                    #perl interface development package
expat-devel \                   #Used to support website parsing HTML and XML files
perl                            #perl compiler

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

Compile and install

cd /opt/httpd-2.4.29/

./configure \
--prefix=/usr/local/httpd \		#Specify the installation path of the httpd service program
--enable-so \					#Enable dynamic loading core module support to enable httpd to further expand its functions
--enable-rewrite \				#Enable the web address rewriting function for website optimization, anti-theft chain and directory migration maintenance
--enable-charset-lite \			#Start character set support to support pages encoded with various character sets
--enable-cgi					#Enable CGI (general Gateway Interface) script program support to facilitate the external expansion of application access capability of the website

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

make -j 4 && make install

Optimize profile path

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

Modify httpd service profile

vim /etc/httpd.conf

#Line 52 -- change to
#Line 197 -- uncomment, modify
#Line 221 -- default home page storage path
DocumentRoot "/usr/local/httpd/htdocs"
#Line 255 -- default home page file name setting
DirectoryIndex index.html

#Check whether the configuration file syntax is correct
httpd -t or apachectl -t

#httpd service test display content
cat /usr/local/httpd/htdocs/index.html
<html><body><h1>It works!</h1></body></html>

Service management

Method -: applicable to centos6
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
chmod +x /etc/init.d/httpd

vim /etc/init.d/httpd
#!/bin/sh				#Add the following
# chkconfig: 35 85 21   #Level 35 automatic operation, the 85th startup and the 21st shutdown (special method notes can also be executed)
# description: Apache is a World Wide Web server

chkconfig --add httpd	#Add the httpd service to the service manager

Other startup methods:
systemctl start httpd.service
service httpd start
Method 2: applicable to centos7
cat > /usr/lib/systemd/system/httpd.service <<EOF
Description=The Apache HTTP Server                              #describe                                            #Describe service category
Type=forking                                                    #Background operation mode
PIDFile=/usr/local/httpd/logs/                         #PID file location
ExecStart=/usr/local/bin/apachectl $OPTIONS                     #Start service
ExecReload=/bin/kill -HUP $MAINPID                              #According to PID overload configuration

systemctl daemon-reload
systemctl start httpd.service && systemctl enable httpd.service

2.3 installing mysql

Install environment dependent packages


yum -y install \
gcc \
gcc-c++ \
ncurses \				#Dynamic library of graphic interactive function under character terminal
ncurses-devel \			#ncurses development kit
bison \					#Parser
cmake					#mysql needs to be compiled and installed with cmake
yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake

Configuring software modules

cd /opt/mysql-5.7.17/

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \		#Specify the installation path of mysql
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ #Specify the storage path of mysql process listening socket file (database connection file)
-DSYSCONFDIR=/etc \                             #Specify the storage path of the configuration file
-DSYSTEMD_PID_DIR=/usr/local/mysql \            #Specifies the storage path of the process file
-DDEFAULT_CHARSET=utf8  \                       #Specifies the character set encoding used by default, such as utf8
-DDEFAULT_COLLATION=utf8_general_ci \			#Specifies the default character set collation rule to use
-DWITH_EXTRA_CHARSETS=all \						#Specifies that other character set encodings are supported
-DWITH_INNOBASE_STORAGE_ENGINE=1 \              #Install INNOBASE storage engine
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \               #Installing the ARCHIVE storage engine 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \             #Installing the BLACKHOLE storage engine 
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \        	#Install FEDERATED storage engine 
-DMYSQL_DATADIR=/usr/local/mysql/data \     	#Specifies the storage path of the database file
-DWITH_BOOST=/usr/local/boost \          		#Specify the path of boost. If MySQL boost integration package is used for installation, - DWITH_BOOST=boost
-DWITH_SYSTEMD=1								#Generate files for systemctl management

Storage engine options:
MYISAM, MERGE, MEMORY, and CSV engines are compiled into the server by default and do not need to be explicitly installed.
Statically compile a storage engine to the server, using - DWITH_engine_STORAGE_ENGINE= 1
Available storage engine values are: ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB), PARTITION (partitioning support), and PERFSCHEMA (Performance Schema)

Note: if an error is reported in the process of CMAKE, after the error is resolved, you need to delete the CMakeCache.txt file in the source directory, and then re CMAKE, otherwise the error remains

Modify mysql configuration file

vim /etc/my.cnf								
[client]									#Client settings
port = 3306

port = 3306

[mysqld]									#Service global settings
user = mysql       							#Set management user
basedir=/usr/local/mysql					#Specify the installation directory of the database
datadir=/usr/local/mysql/data				#Specifies the storage path of the database file
port = 3306									#Specify port
character-set-server=utf8					#Set the server character set encoding format to utf8
pid-file = /usr/local/mysql/		#Specify pid process file path
socket=/usr/local/mysql/mysql.sock			#Specify database connection file
bind-address =						#Set the listening address. means that all IP addresses are allowed. If multiple IP addresses are allowed, they should be separated by spaces
skip-name-resolve							#Disable DNS resolution
max_connections=2048						#Set the maximum number of mysql connections
default-storage-engine=INNODB				#Specify the default storage engine
max_allowed_packet=16M						#Sets the maximum packet size received by the database
server-id = 1								#Specify the service ID number

sql_mode Common values are as follows:
 If the required storage engine is disabled or not compiled,Then throw an error. When this value is not set,Replace with the default storage engine,And throw an exception
 In this mode,If a value cannot be inserted into a transaction table,The current operation is interrupted,No restrictions on non transaction tables
 prohibit GRANT Create a user with a blank password
mysql The self growing column in can start at 0. By default, the self growth column starts from 1. If you insert data with a value of 0, an error will be reported
 Zero date and month are not allowed
mysql Zero date insertion is not allowed in the database,Inserting a zero date throws an error instead of a warning
 stay INSERT or UPDATE In the process, if the data is divided by zero, an error is generated instead of a warning. By default, when the data is divided by zero MySQL return NULL
 take"||"Treat as a concatenation operator of a string rather than an or operator, which is similar to Oracle The database is the same as the string splicing function Concat Similar
 Enable ANSI_QUOTES You cannot use double quotation marks to refer to a string after, because it is interpreted as an identifier

2.4 installing PHP

Install GD library and Gd library associated programs

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

Configuring PHP software modules

cd /opt/php-7.1.10/

./configure \
--prefix=/usr/local/php7 \							#Specify the path where the PHP program will be installed
--with-apxs2=/usr/local/httpd/bin/apxs \			#Specifies the file location of the apxs module support program provided by the Apache httpd service
--with-mysql-sock=/usr/local/mysql/mysql.sock \		#Specify the storage path of mysql database connection file
--with-config-file-path=/usr/local/php7	\			#Set the location where the PHP configuration file php.ini will be stored
--with-mysqli \										#add to MySQL Extended support #mysqli extension technology can not only call MySQL stored procedures and process MySQL transactions, but also make accessing the database more stable
--with-zlib \										#Support zlib function and provide data compression
--with-curl \										#Enable curl extension function to realize HTTP Get download and Post request
--with-gd \											#Activate gd library support
--with-jpeg-dir \									#Activate jpeg support
--with-png-dir \									#Activate png support
--with-freetype-dir \
--with-openssl \
--enable-mbstring \									#Enable multi byte string function to support Chinese and other codes
--enable-xml \										#Open extensible markup language module
--enable-session \									#conversation
--enable-ftp \										#Text transfer protocol
--enable-pdo \										#function library
--enable-tokenizer \								#Token interpreter
--enable-zip										#ZIP compression format

Copy the template file as the main configuration file for PHP

#Use the php.ini-development file for the test environment and the php.ini-production file for the production environment
cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini

vim /usr/local/php7/php.ini
#Line 939 uncomment, modify
date.timezone = Asia/Shanghai
#Modify line 1170
mysqli.default_socket = /usr/local/mysql/mysql.sock

Modify the configuration file of httpd service to make apache support PHP

vim /etc/httpd.conf

#Add index.php
255 <IfModule dir_module>
256     DirectoryIndex index.html index.php
257 </IfModule>

#Insert the following below line 392 so that apache can support web page files in. php format
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

##Check whether the module supporting php7 by default exists in line 156
LoadModule php7_module   modules/

Create and edit php page files

cd /usr/local/httpd/htdocs/ && mv index.html index.html.bak
cat > /usr/local/httpd/htdocs/index.php<<EOF
systemctl restart httpd.service

Posted by timbach2 on Wed, 06 Oct 2021 12:48:02 -0700