LAMP+Apache+mysql+php+DISCUZ

Keywords: PHP MySQL Apache

catalogue

1, LAMP introduction and overview

1. LAMP platform overview

2. Build LAMP platform sequence

3. Advantages of compilation and installation

4. Main functions of each component

2, Install Apache (version after httpd 2.4)

1. Close the firewall, subsystem and timing

2. Install and unzip the package last time, and move the accessories to Apache's core function library

3. Environment required to install the service

4. Compile and install

5. Use service or systemctl to manage and optimize the configuration file path

6. Modify profile

7. Start services and view ports

3, Install mysql

1. Install database environment

2. Upload and unzip packets

3. Compile and install

4. Create normal user management mysql and change management master / group

5. Modify the configuration file (# delete the original configuration item and add the following content again)

6. Set environment variables and declare / declare mysql commands for system recognition

7. Initialize database

8. Restart service and set password

4, Install php service

1. Deploy php service environment

2. Compiling php

3. Modify php configuration file

4. Restart the http service and test the web page

  5, Installation Forum

1. Create a database

2. Unzip the forum package and upload the site

3. Change directory permissions

4. Test page

  summary

1, LAMP introduction and overview

1. LAMP platform overview

LAMP architecture is one of the mature enterprise website application modes at present. It refers to a whole system 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, Apache Web server, MySQL database server, PHP (or perl, Python) web programming language

2. Build LAMP platform sequence

When building the LAMP platform, the installation sequence of each component is Linux, Apache, MySQL and PHP in turn. There is no strict sequence requirement for the installation of Apache and MYSQL, while the installation of PHP environment is generally put last, responsible for communicating the web server and database system to work together

3. Advantages of compilation and installation

It has a large degree of freedom and can be customized
The latest software version can be obtained in time
It is generally applicable to most Linux versions and is easy to use all the time

4. Main functions of each component

(platform) Linux: 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).

(front desk) Apache: 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.

(background) MySQL: 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.

(intermediate connection) PHP/Perl/Python: 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

2, Install Apache (version after httpd 2.4)

1. Close the firewall, subsystem and timing

systemctl stop firewalld  Turn off firewall

systemctl disable firewalld  Turn off auto start

systemctl status firewalld    View firewall status

vim /etc/sysconfig/selinux

selinux=disabled  Shut down the security subsystem

ntpdate ntp1.aliyun.com  Calibration time

hostnamectl set-hostname lamp  Change the name for easy memory

2. Install and unzip the package last time, and move the accessories to Apache's core function library

3. Environment required to install the service

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

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

4. Compile and install

cd httpd-2.4.29

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

make && make 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

5. Use service or systemctl to manage and optimize the configuration file path

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

cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
vim /etc/init.d/httpd
# Chkconfig: 35 85 21 / / 35 level automatic operation 85th startup 21st shutdown
# description: Apache is a World Wide Web server

chkconfig --add httpd //Add httpd to system manager

6. Modify profile

vim /usr/local/httpd/conf/httpd.conf
#--Line 52 -- modify
#Listen 192.168.255.150:80
--197 that 's ok--Uncomment, modify
ServerName www.kgc.com:80
--221 that 's ok--Default home page storage path
DocumentRoot "/usr/local/httpd/htdocs"
--255 that 's ok--Default home page file name setting
DirectoryIndex index.html

7. Start services and view ports

service httpd restart
netstat -anpt | grep 80

3, Install mysql

1. Install database environment

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

2. Upload and unzip packets

3. Compile and install

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



make -j 4 && make install   #Multi-core processing

4. Create normal user management mysql and change management master / group

useradd -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf

5. Modify the configuration file (# delete the original configuration item and add the following content again)

[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 all are allowed, such as many 
                                               individual IP Space required
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


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
 Ban Zheng GRANT Create a user with a blank password

NO_AUTO_VALUE_ON_ZERO
mysql The self growing column in can be O Start. 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

6. Set environment variables and declare / declare mysql commands for system recognition

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

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

8. Restart service and set password

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload         #Refresh recognition     
systemctl start mysqld.service  #Open service
systemctl enable mysqld         #Startup self startup
netstat -anpt | grep 3306       #View port


#Set password for root account
mysqladmin -u root -p password "123456" 
-->Direct enter

4, Install php service

1. Deploy php service environment

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
 install GD Library and GD Library Association program, used to process and generate pictures

2. Compiling php

cd /opt
tar zxvf php-7.1.10.tar.gz


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



make  -j 3 && make install

3. Modify php configuration file

cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini
vim /usr/local/php7/php.ini
--1170 that 's ok--modify
mysqli.default_socket = /usr/local/mysql/mysql.sock
--939 that 's ok--Uncomment, modify
date.timezone = Asia/Shanghai

#Optimization puts PHP executable program files into the directory of path environment variables for system identification
ln -s /usr/local/php7/bin/* /usr/local/bin/


#Modify the Apache configuration file 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 something below line 392 so that Apache can support. php web files
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
rm -rf /usr/local/httpd/htdocs/index.html
vim /usr/local/httpd/htdocs/index.php
<?php
phpinfo();
?>

4. Restart the http service and test the web page

systemctl restart httpd.service  #The cache can be restarted multiple times

  5, Installation Forum

1. Create a database

mysql -u root -p 

mysql> CREATE DATABASE bbs;
  
#Grant the permissions of all tables in the bbs database to bbsuser and set the password

mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';

#Refresh database
mysql>flush privileges; 
mysql>show databases;

2. Unzip the forum package and upload the site

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

cd /opt/dis
cd dir_SC_UTF8/
#Upload site update package
cp -r upload/ /usr/local/httpd/htdocs/bbs

3. Change directory permissions

#Switch forum directory
cd /usr/local/httpd/htdocs/bbs

#Change forum directory owner
chown -R daemon ./config
chown -R daemon ./data
chown -R daemon ./uc_client
chown -R daemon ./uc_server/data

4. Test page

http://192.168.255.150/bbs/install/index.php

database server: localhost   #localhost is used for local erection. How to fill in the IP address and port number instead of on the local machine
 Database name: bbs
 Database user name: bbsuser
 Database password: admin123
 administrator account : admin
 Administrator password: admin123


In case of error, the information is as follows:
Fatal error: Uncaught Error: Call to undefined function set_magic_quotes_runtime() in /data/www/install/index.php:12 Stack trace: #0 {main} thrown in /data/www/install/index.php on line 12

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

#Switch directory
cd /usr/local/httpd/htdocs/bbs/install
vim index.php Edit

//hold 
  
@set_magic_quotes_runtime(0); 
  
//Substitute into 
  
@ini_set("magic_quotes_runtime",0); 

The problem has been resolved



The test results are normal and the forum website can be opened normally

 

  summary

In the whole process, each program is responsible for different modules. linux hosts the operating system, Apache handles static requests, MySQL stores data, and php handles dynamic requests. linux is the base of the whole framework, Apache connects with php, and php connects with MySQL

Apache is connected in the form of fpm/fast CGI interface and compatible php module to complete static page processing + forwarding dynamic pages. After php is connected with Apache, it needs to connect to MysQL database. The core is to use mysql.sock communication file as the carrier, and MysQL provides mysql.sock communication file + mysql_modules (mysql.cnf )

Note: we need to understand the overall framework and its docking method. The second is the versions of various services. Some versions are incompatible. If there is a problem, we can use resources to deal with it

Posted by the_ut_tick on Wed, 29 Sep 2021 17:29:51 -0700