Build Discuz forum based on LAMP Architecture -- Linux, Apache, Mysql, PHP, Discuz

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

Set upFunction interpretation
Linux (platform)As the basis of 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)
Apache (front desk)As the front end of LAMP architecture, it is a powerful and stable Web server program. The server directly provides users with website access, sending Web pages, pictures and other file contents
MySQL (background)As the back end of LAMP architecture, it is a popular open source relational database system. In enterprise websites, business systems and other applications, various account information, product information, customer information and business data can be stored in MySQL database. Other programs can query and change these information through SQL statements
PHP/Perl/Python (intermediate connection)As three programming languages for developing dynamic Web pages, it is responsible for interpreting dynamic Web page files, communicating the Web server and database system to work together, and providing the development and running environment of Web applications. PHP is a widely used open source multi-purpose scripting language, which can be embedded in HTML, especially suitable for Web application development

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

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

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 114.114.114.114" >> /etc/resolv.conf
ntpdate ntp1.aliyun.com
reboot	#Restart the host

2.2 installing apache

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

[root@c7-1 /data]#ls
apr-1.6.2.tar.gz  apr-util-1.6.0.tar.gz  httpd-2.4.29.tar.bz2

Unzip the installation package to the / opt directory (the apr plug-in is required for versions after httpd 2.4)

#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 the configuration file path, and put the executable program file of httpd service into the directory of path environment variable for system identification

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
Listen 192.168.10.20:80
#Line 197 -- uncomment, modify
ServerName www.test.com:80
#Line 221 -- default home page storage path
DocumentRoot "/usr/local/httpd/htdocs"
#Line 255 -- default home page file name setting
DirectoryIndex index.html
//preservation

#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
//preservation

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

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

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

Service validation

#View port
netstat -anpt | grep 80

#Browser authentication
echo "192.168.10.20 www.test.com" >> /etc/hosts
 Browser access
192.168.10.20
 or
www.test.com	//windows hosts file parsing needs to be set

2.3 installing mysql

Unzip the installation package required for mysql to the specified directory

#Here we use two subcontracts. In fact, we can also use MySQL boost*
tar zxvf mysql-5.7.17.tar.gz -C /opt
tar zxvf boost_1_59_0.tar.gz -C /usr/local	#Runtime supporting c + +
mv /usr/local/boost_1_59_0 /usr/local/boost

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

Create application user management

useradd -s /sbin/nologin mysql

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 The engine is compiled into the server by default and does 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 CMAKE There are errors in the process of. When the errors are solved, you need to put the errors in the source directory CMakeCache.txt Delete the file and then try again CMAKE,Otherwise, the error remains

Compilation and installation

make -j 4 && make install

Modify mysql configuration file

vim /etc/my.cnf								
[client]									#Client settings
port = 3306
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock			

[mysql]									
port = 3306
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
auto-rehash

[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/mysqld.pid		#Specify pid process file path
socket=/usr/local/mysql/mysql.sock			#Specify database connection file
bind-address = 0.0.0.0						#Set the listening address. 0.0.0.0 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=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 Common values are as follows:
NO_ENGINE_SUBSTITUTION
 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
   
STRICT_TRANS_TABLES
 In this mode,If a value cannot be inserted into a transaction table,The current operation is interrupted,No restrictions on non transaction tables
   
NO_AUTO_CREATE_USER
 prohibit GRANT Create a user with a blank password
   
NO_AUTO_VALUE_ON_ZERO
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
   
NO_ZERO_IN_DATE
 Zero date and month are not allowed
   
NO_ZERO_DATE
mysql Zero date insertion is not allowed in the database,Inserting a zero date throws an error instead of a warning
   
ERROR_FOR_DIVISION_BY_ZERO
 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
   
PIPES_AS_CONCAT
 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
   
ANSI_QUOTES
 Enable ANSI_QUOTES You cannot use double quotation marks to refer to a string after, because it is interpreted as an identifier

Change the primary group of mysql installation directory and configuration file

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

Set path environment variable

echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile

Initialize database

cd /usr/local/mysql/bin/
./mysqld \
--initialize-insecure \				#The generation initialization password is empty
--user=mysql \                      #Specify administrative users
--basedir=/usr/local/mysql \        #Specify the installation directory of the database
--datadir=/usr/local/mysql/data		#Specifies the storage path of the database file

Add mysqld system service

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/	#For systemctl service management
systemctl daemon-reload			 
systemctl start mysqld && systemctl enable mysqld
netstat -anpt | grep 3306    

Set password for root account

mysqladmin -u root -p password "123456" 	
#Set the password to 123456 for the root account, and then prompt for the original password (blank by default). Just press enter

#Forgot password reference
https://database.51cto.com/art/202012/635431.htm?pc

2.4 installing PHP

Install GD library and Gd library associated 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

Unzip the PHP package to the specified directory

tar jxvf php-7.1.10.tar.bz2 -C /opt/

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

Compile and install

make -j 4 && make install 

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

#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

Optimization, put PHP executable program files into the directory of path environment variables for system identification

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

#See which modules PHP loads
php -m 

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/libphp7.so

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
<?php
phpinfo();
?>
EOF
   
systemctl restart httpd.service

Web test

Browser access
http://192.168.10.20/index.php

3. Discuz forum construction

Create database and authorize

mysql -u root -p		#Login to mysql
> CREATE DATABASE bbs;	#Create a database
> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';	#Grant the permissions of all tables in the bbs database to bbsuser and set the password
> flush privileges;		#Refresh database
> show databases;		#view the database

Upload and unzip the forum compressed package to the specified location

unzip /data/Discuz_X3.4_SC_UTF8.zip -d /opt/dis

Upload site update package

cp -r /opt/dis/dir_SC_UTF8/upload/ /usr/local/httpd/htdocs/bbs

Change forum directory owner

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

Browser access authentication

#Forum page access
http://192.168.10.20/bbs

Database server: localhost
#localhost is used for local erection. If it is not on the local machine, the IP address and port number should be filled in
 Database name: bbs
 Database user name: bbsuser
 Database password: admin123
 administrator account :admin
 Administrator password:admin123
   
Forum background administrator page
http://192.168.10.20/bbs/admin.php

If an error is reported, the information is as follows

Fatal error: Uncaught Error: Call to undefined function set_magic_quotes_runtime() in /usr/local/httpd/htdocs/bbs/install/index.php:12 Stack trace: #0 {main} thrown in /usr/local/httpd/htdocs/bbs/install/index.php on line 12

#Fatal error: uncapped error: call set for undefined function_ magic_ quotes_ Runtime (), on line 12 of this file, find the index.php file under this path. Open this file and look for set_magic_quotes_runtime
cd /usr/local/httpd/htdocs/bbs/install && vim index.php
 Put the of line 12 @set_magic_quotes_runtime(0); replace with  @ini_set("magic_quotes_runtime",0);

#The browser logs in again http://192.168.10.20/bbs/install/  normal

Test whether the database works normally

mysql -u root -p
> CREATE DATABASE sky;
> GRANT all ON sky.* TO 'skyuser'@'%' IDENTIFIED BY 'admin123';
> flush privileges; 
> exit

vim /usr/local/httpd/htdocs/index.php
<?php
$link=mysql_connect('192.168.10.20','skyuser','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
mysql_close();
?>

Discuz configuration steps
Compilation and installation of LAMP and various components

4. Simple installation process

###Installation package preparation
 Upload installation package to /data catalogue


###Preparation before installation
systemctl stop firewalld && systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config
echo "nameserver 114.114.114.114" >> /etc/resolv.conf
ntpdate ntp1.aliyun.com
reboot


###Install apache
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 /opt/apr-1.6.2 /opt/httpd-2.4.29/srclib/apr
mv /opt/apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util
yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl
cd /opt/httpd-2.4.29/
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
cd /opt/httpd-2.4.29/
make -j 4 && make install
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/

vim /etc/httpd.conf
#Line 52 -- change to
Listen <Yours IP>:80
#Line 197 -- uncomment
ServerName www.example.com:80
#Line 221 -- default home page storage path
DocumentRoot "/usr/local/httpd/htdocs"
#Line 255 -- default home page file name setting
DirectoryIndex index.html
#preservation

cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/httpd/logs/httpd.pid
ExecStart=/usr/local/bin/apachectl $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload && systemctl start httpd.service && systemctl enable httpd.service
echo "<Yours IP> www.example.com" >> /etc/hosts


###Install mysql
tar zxvf /data/mysql-5.7.17.tar.gz -C /opt
tar zxvf /data/boost_1_59_0.tar.gz -C /usr/local
mv /usr/local/boost_1_59_0 /usr/local/boost
yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake
useradd -s /sbin/nologin mysql
cd /opt/mysql-5.7.17/

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

cd /opt/mysql-5.7.17/
make -j 4 && make install
echo > /etc/my.cnf

cat > /etc/my.cnf<<EOF
[client]
port = 3306
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
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
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1

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
EOF

chown -R mysql.mysql /usr/local/mysql/
chown mysql.mysql /etc/my.cnf
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile

cd /usr/local/mysql/bin/
./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload && systemctl start mysqld && systemctl enable mysqld


###Install PHP
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

tar jxvf /data/php-7.1.10.tar.bz2 -C /opt/
cd /opt/php-7.1.10/

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

cd /opt/php-7.1.10/
make -j 4 && make install 

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
#preservation

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

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/libphp7.so
#preservation

rm -rf /usr/local/httpd/htdocs/index.html

cat > /usr/local/httpd/htdocs/index.php<<EOF
<?php
phpinfo();
?>
EOF

systemctl restart httpd.service


### Installing Discuz
mysql
> CREATE DATABASE bbs;
> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
> flush privileges;
> show databases;
> exit

unzip /data/Discuz_X3.4_SC_UTF8.zip -d /opt/dis
cp -r /opt/dis/dir_SC_UTF8/upload/ /usr/local/httpd/htdocs/bbs
chown -R daemon /usr/local/httpd/htdocs/bbs/config
chown -R daemon /usr/local/httpd/htdocs/bbs/data
chown -R daemon /usr/local/httpd/htdocs/bbs/uc_client
chown -R daemon /usr/local/httpd/htdocs/bbs/uc_server/data

5. One click deployment script

5.1 description

  • This script can be executed with one click, but the installation package is placed on my Alibaba cloud host. The download speed is slow. You can download it in advance and store it in the local / data directory
  • sed -i when editing a linked file, the linked file will become an ordinary file, so you can't directly change the linked file. You need to edit the original file

5.2 script content

#!/bin/bash
#---------------------------
#One click installation of LAMP and Discuz
#---------------------------

#Required installation package
#Httpd package: apr-1.6.2.tar.gz, apr-util-1.6.0.tar.gz, httpd-2.4.29.tar.bz2
#MySQL package: mysql-5.7.17.tar.gz, boost_1_59_0.tar.gz
#PHP package: php-7.1.10.tar.bz2
#Discuz package: Discuz_X3.4_SC_UTF8.zip

###Installation package preparation
mkdir /data
yum -y install wget
wget http://47.117.130.238/LAMP/apr-1.6.2.tar.gz -P /data
wget http://47.117.130.238/LAMP/apr-util-1.6.0.tar.gz -P /data
wget http://47.117.130.238/LAMP/httpd-2.4.29.tar.bz2 -P /data
wget http://47.117.130.238/LAMP/mysql-5.7.17.tar.gz -P /data
wget http://47.117.130.238/LAMP/boost_1_59_0.tar.gz -P /data 
wget http://47.117.130.238/LAMP/php-7.1.10.tar.bz2 -P /data 
wget http://47.117.130.238/LAMP/Discuz_X3.4_SC_UTF8.zip -P /data


###Preparation before installation
systemctl stop firewalld && systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
echo "nameserver 114.114.114.114" >> /etc/resolv.conf
ntpdate ntp1.aliyun.com
IP=`ifconfig ens33 | grep netmask | tr -s ' ' @ | cut -d@ -f3`

###Install apache
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 /opt/apr-1.6.2 /opt/httpd-2.4.29/srclib/apr
mv /opt/apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util
yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl
cd /opt/httpd-2.4.29/
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
cd /opt/httpd-2.4.29/
make -j 4 && make install
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/

#Note that the new version of sed cannot directly modify the linked file, which will become an ordinary file, so we need to modify the original file
sed -i "52s/Listen 80/Listen $IP:80/" /usr/local/httpd/conf/httpd.conf
sed -i "197s/#ServerName www.example.com:80/ServerName www.example.com:80/" /usr/local/httpd/conf/httpd.conf

cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/httpd/logs/httpd.pid
ExecStart=/usr/local/bin/apachectl $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
EOF

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


###Install mysql
tar zxvf /data/mysql-5.7.17.tar.gz -C /opt
tar zxvf /data/boost_1_59_0.tar.gz -C /usr/local
mv /usr/local/boost_1_59_0 /usr/local/boost
yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake
useradd -s /sbin/nologin mysql
cd /opt/mysql-5.7.17/

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

cd /opt/mysql-5.7.17/
make -j 4 && make install
echo > /etc/my.cnf

cat > /etc/my.cnf<<EOF
[client]
port = 3306
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
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
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1

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
EOF

chown -R mysql.mysql /usr/local/mysql/
chown mysql.mysql /etc/my.cnf
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile

cd /usr/local/mysql/bin/
./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload && systemctl start mysqld && systemctl enable mysqld


###Install PHP
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

tar jxvf /data/php-7.1.10.tar.bz2 -C /opt/
cd /opt/php-7.1.10/

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

cd /opt/php-7.1.10/
make -j 4 && make install

cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini

sed -i "939s/\;date.timezone =/date.timezone = Asia\/Shanghai/" /usr/local/php7/php.ini
sed -i "1170s/mysqli.default_socket =/mysqli.default_socket = \/usr\/local\/mysql\/mysql.sock/" /usr/local/php7/php.ini

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

sed -i "s/    DirectoryIndex index.html/    DirectoryIndex index.html index.php/g" /usr/local/httpd/conf/httpd.conf
sed -i "392a AddType application/x-httpd-php .php \n AddType application/x-httpd-php-source .phps" /usr/local/httpd/conf/httpd.conf

rm -rf /usr/local/httpd/htdocs/index.html

cat > /usr/local/httpd/htdocs/index.php<<EOF
<?php
phpinfo();
?>
EOF

systemctl restart httpd.service


### Installing Discuz
echo "CREATE DATABASE bbs;" | mysql
echo "GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';" | mysql
echo "flush privileges;" | mysql

unzip /data/Discuz_X3.4_SC_UTF8.zip -d /opt/dis
cp -r /opt/dis/dir_SC_UTF8/upload/ /usr/local/httpd/htdocs/bbs
chown -R daemon /usr/local/httpd/htdocs/bbs/config
chown -R daemon /usr/local/httpd/htdocs/bbs/data
chown -R daemon /usr/local/httpd/htdocs/bbs/uc_client
chown -R daemon /usr/local/httpd/htdocs/bbs/uc_server/data

### Service status judgment
echo " "
echo -e "\033[31m I am the dividing line-------------------------------\033[0m"
sleep 3
echo -e "\033[33mLAMP Component status\033[0m"

pgrep "httpd" &> /dev/null
if [ $? -eq 0 ];then
        echo -e "\033[32mhttpd The service is running normally\033[0m"
else
        echo -e "\033[31mhttpd The service is running abnormally. Please check\033[0m"
fi

pgrep "mysqld" &> /dev/null
if [ $? -eq 0 ];then
        echo -e "\033[32mmysqld The service is running normally\033[0m"
else
        echo -e "\033[31mmysqld The service is running abnormally. Please check\033[0m"
fi

### Prompt information
echo " "
sleep 2
echo -e "\033[33m If all components are working normally, please log in Discuz Forum, account login information:\033[0m"
echo -e "\033[32m Access address http://< your IP > / BBS / Admin. PHP \ 033[0m“
echo -e "\033[32m database server localhost\033[0m"
echo -e "\033[32m Database name bbs\033[0m"
echo -e "\033[32m Database user name bbsuser\033[0m"
echo -e "\033[32m Database password admin123\033[0m"
echo -e "\033[32m administrator account  admin\033[0m"
echo -e "\033[32m Administrator password admin123\033[0m"

Tags: PHP Linux MySQL

Posted on Tue, 05 Oct 2021 14:28:14 -0400 by psychotomus