LLinux deploys LAMP service to build Discuz forum

Introduction to LAMP

LAMP architecture is one of the current mature enterprise website application modes. It refers to a set of systems and related operations that work together to provide dynamic website services and application development environments.
LAMP: Linux operating system, Apache web server, MySQL database server, PHP web programming language.

Component role

Linux: The foundation of the LAMP architecture, and the operating system that provides the support site.
Apache: The front end of LAMP is a powerful and stable web server program that directly provides users with website access, sending web pages, pictures and other file content.
MySQL: The back end of LAMP is a popular open source relational database system. In applications such as enterprises and business systems, various account information can be stored in the MySQL database.
PHP/Perl/Pythom: As three programming languages ​​for developing dynamic web pages. Responsible for interpreting dynamic web files, and for communicating with web servers and database systems to work together.

Install Apache service

1. Turn off the firewall, and upload the required software packages to install Apache to the /opt directory
systemctl stop firewalld
systemctl disable firewalld
setenforce 0

#apr component package is used to support cross-platform Apache upper-level applications, provide the underlying interface library, can be effective Reduce the number of concurrent connections, reduce processes and reduce access congestion.

2. The installation environment depends on the package
yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl

3. Configure the 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

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

4. Compile and install
make -j2 && make install ##Turn on 2 cores to compile and install

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 the system to recognize
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr /local/httpd/bin/* /usr/local/bin/

6. Add httpd system service
Method one:
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd #for service service management
chmod +x /etc/init.d/httpd
vi /etc/init .d/httpd
#!/bin/bash #Insert a new line before the first line and add these three lines
#chkconfig: 35 85 21 #35 level automatically runs the 85th start and the 21st close
#description: Apache is a World Wide Web server

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

systemctl start httpd.service

7. Modify the httpd service configuration file
vim /etc/httpd.conf-Line
197-Uncomment, modify
ServerName www.jmi.com:80

–Line 221 – The default home page storage path
DocumentRoot "/usr/local/httpd/htdocs"
– Line 255 – The default home page file name setting
DirectoryIndex index.html

httpd -t or apachectl -t #Check whether the configuration items of the configuration file are wrong
cat /usr/local/httpd/htdocs/index.html
systemctl restart httpd.service

8. Browser access verification
netstat -anpt | grep 80
echo " www.jmi.com" >> /etc/hosts
Note: The modification of the configuration file requires a certain amount of time to compile.
The content in the homepage file appears on the visited webpage and it is installed.

Insert picture description here

MySQL installation

1. Transfer the software packages required to install mysql to the /opt directory
boost_1_59_0.tar.gz #support c++ runtime

2. The installation environment depends on the package
yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake

3. Configure the 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 #Rename

cd /opt/mysql-5.7.17/

Note: If there is an error 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 will remain

4. Compile and install
make && make install

5. Create mysql user
useradd -M -s /sbin/nologin mysql

6. Modify the mysql configuration file
vim /etc/my.cnf #Delete the original configuration item and re-add the following content
port = 3306

port = 3306
socket = /usr/local/mysql/mysql.sock

user = mysql
port = 3306
pid-file = /usr/local/mysql/mysqld.pid
bind-address =
server-id = 1


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

8. Set the path environment variable
echo'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
source /etc/profile

9. Initialize the database./mysqld
-insecure --user

10. 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
#Refresh recognition systemctl start mysqld .service #Open the service
systemctl enable mysqld
#start automatically netstat -anpt | grep 3306 #View port

11. Modify the mysql login password
mysqladmin -u root -p password "abc123" #Set the password for the root account to abc123, and the original password is prompted (empty)

12. Authorizes Telnet
MySQL -u root -p
Grant All privileges ON . To 'root' @ '%' IDENTIFIED by 'abc123';
# root user can grant all terminals in remote login, password is abc123, and all Database and all tables have operation permissions

show databases;

Install PHP

1. Transfer the software packages needed to install PHP to the /opt directory

2. Install GD library and GD library related programs to process and generate pictures
yum -y install
libjpeg libjpeg-devel
libpng libpng-devel
freetype freetype-devel
libxml2 libxml2-devel
zlib zlib-devel
curl curl-devel

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

4. Compile and install
make && make install

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 #Use php.ini-
in the test environment development file, and use the php.ini-production file in the production environment
vim /usr/local/php7/php.ini
– line 1170 – modify
mysqli.default_socket = /usr/local/mysql/mysql.sock
– line 939 – cancel Note, modify
date.timezone = Asia/Shanghai

6. Optimize to put the PHP executable program file into the directory of the path environment variable for the system to recognize
ln -s /usr/local/php7/bin/* /usr/local/bin/
php -m #View which PHP has loaded Module

7. Modify the httpd service configuration file, let apache support PHP
vim /etc/httpd.conf
-393 line - insert the following
AddType the Application / the X-PHP-httpd-.php
AddType the Application / the X-PHP-Source-httpd-. Phps
- Line 255-Modify the file name of the home page to set
DirectoryIndex index.html index.php

—Check if the module that supports php7 exists —
LoadModule php7_module modules/libphp7.so

8. Verify PHP test page
rm -rf /usr/local/httpd/htdocs/index.html
vim /usr/local/httpd/htdocs/index.php

<?php phpinfo(); ?>

systemctl restart httpd.service

Browser visit

Install forum

1. Create a database and authorize
mysql -u root -p

a database

GRANT all ON bbs.* ​​TO'bbsuser'@'%' IDENTIFIED BY'admin123'; #Grant
permissions for all tables in the bbs database to bbsuser, and set the password admin123

flush privileges;
#Refresh the database

show databases;

2. 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 #Upload site update package

3. Change the owner of the forum directory
ps aux #Check that the user name of the forum process is 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

4. Browser access verification Visit the
forum page

Database server: localhost ###Use localhost for local setup. How to fill in the IP address and port number instead of on this machine
Database name: bbs
database username: bbsuser
database password: admin123
administrator account: admin
administrator password: admin123

Forum backend administrator page

Insert picture description here

Insert picture description here

Note: If the content of the home page does not change after changing the home page file, first clear the browser cache and check the firewall. If it doesn’t work, check after the change. Is there a problem with the configuration file? Pay attention to the command to restart the httpd service. Is httpd really restarted? If everything is correct, check the log file. If you can't find the error, rebuild it in time. If you enter the wrong password when installing the forum, delete the uploaded site update package and reinstall it.

Installation package extraction

Link: https://pan.baidu.com/s/1mQgX0OAOhCqcPdoSWi_Exw
Extraction code: jmik
copy this content and open the Baidu Netdisk mobile phone App, the operation is more convenient