LAMP source code installation (platform Linux, foreground Apache, background MySQL, intermediate connection PHP/Perl/Python)

Source code compilation and installation of web Services LAMP

1, LAMP Architecture Overview
1. Introduction to lamp

  • LAMP is the acronym of Linux operating system + Apache Web server + MySQL database server + PHP (or Perl, Python) web programming language.
  • They are independent programs, but they can be used to build open source software for dynamic websites or servers
    2. Main functions of each component
    (1) Linux ------ platform
  • Linux is the basis of LAMP architecture. It provides an operating system to support the Web site, and can provide better stability and compatibility with the other three components (AMP components also support Windows, UNIX and other platforms).

(2) Apache - front desk

  • As the front end of LAMP architecture, Apache is a powerful and stable Web server program. The server directly provides users with website access, sending Web pages, pictures and other file contents.

(3) MySQL - background

  • MySQL, as the back end of LAMP architecture, 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.
    (4) PHP/Perl/Python ------ 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. (this chapter is written in PHP language)

3. Sequence of building LAMP platform

  • When building the LAMP platform, the installation sequence of each component is Linux → Apache → MySQL → PHP. Apache and MySQL are not installed in strict order. PHP environment is generally installed last, which is responsible for communicating the Web server and database system to work together.

2, Compile and install Apache httpd service
1. Close the firewall and transfer the software package required for installing Apache to the / opt directory

systemctl stop firewalld
systemctl disable firewalld
setenforce 0

httpd-2.4.46.tar.gz
apr-1.7.0.tar.gz
apr-util-1.6.1.tar.gz
#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.

2. Install environment dependent packages

#Install Yum source before using yum
yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl
#------Explain---------
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

3. Configuring software modules

cd /opt/
tar zxvf apr-1.7.0.tar.gz
tar zxvf apr-util-1.6.1.tar.gz
tar zxvf httpd-2.4.46.tar.gz 

mv apr-1.7.0 /opt/httpd-2.4.46/srclib/apr
mv apr-util-1.6.1 /opt/httpd-2.4.46/srclib/apr-util

cd /opt/httpd-2.4.46/

./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
#--------Explain--------
--prefix=/usr/local/httpd #Specify the installation path of the httpd service program
--enable-so  			  #Enable dynamic loading 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




  • If the output of. / configure command is too long, no screenshot will be taken

4. Compilation and installation

#make -j 2 means to open 2 cores and compile at the same time
make
make install

Very long, no screenshot

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

6. Add httpd system service

Method 1:
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd		#Used for service management
chmod +x /etc/init.d/httpd
vim /etc/init.d/httpd
#Insert a new line before the first line and add these three lines (except comments)
#!/bin/bash
#Level 35 automatic operation, 85th startup, 21st shutdown
# chkconfig: 35 85 21
# description: Apache is a World Wide Web server

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

systemctl start httpd.service

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

systemctl start httpd.service
systemctl enable httpd.service

  • Here, I use method 2 to set (relatively fast), and method 1 is also OK, but I have to wait a while after setting, and the startup is slow. I won't demonstrate here.


7. Modify httpd service profile

vim /etc/httpd.conf
#Line 52; modify
Listen 192.168.163.10:80
#Line 199; Uncomment, modify
ServerName www.lisi.com:80

#Line 223; Default home page storage path
DocumentRoot "/usr/local/httpd/htdocs"
#Line 257; Default home page file name setting
DirectoryIndex index.html

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






8. Browser access authentication

netstat -anpt | grep 80
echo "192.168.163.10 www.lisi.com" >> /etc/hosts

http://192.168.163.10
http://www.lisi.com




3, Compile and install mysqld service

1. Transfer the software package required to install mysql to the / opt directory

mysql-5.7.17.tar.gz
#Runtime supporting c + +
boost_1_59_0.tar.gz

2. Install environment dependent packages

yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake
#------Explain-----
gcc 				#C language compiler
gcc-c++ 			#C + + compiler
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

3. Configuring software modules

cd /opt
tar zxvf mysql-5.7.17.tar.gz
tar zxvf boost_1_59_0.tar.gz
#rename
mv boost_1_59_0 /usr/local/boost

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

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

-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)
#Two common storage engines are MYISAM and INNOBASE(InnoDB)



4. Compilation and installation

make && make install

5. Create mysql user

useradd -M -s /sbin/nologin  mysql

6. Modify mysql configuration file

vim /etc/my.cnf
#Delete the original configuration item and add the following content again
#Client settings
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock			

#Service global settings
[mysqld]
#Set management user
user = mysql
#Specify the installation directory of the database
basedir=/usr/local/mysql
#Specifies the storage path of the database file
datadir=/usr/local/mysql/data
#Specify port
port = 3306
#Set the server character set encoding format to utf8
character-set-server=utf8
#Specify pid process file path
pid-file = /usr/local/mysql/mysqld.pid
#Specify database connection file
socket=/usr/local/mysql/mysql.sock
#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
bind-address = 0.0.0.0
#Disable DNS resolution
skip-name-resolve
#Set the maximum number of mysql connections
max_connections=2048
#Specify the default storage engine
default-storage-engine=INNODB
#Sets the maximum packet size received by the database
max_allowed_packet=16M
#Specify the service ID number
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

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

7. Change the primary group of mysql installation directory and configuration file

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

8. Set path environment variable

echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile	
source /etc/profile

9. Initialize database

cd /usr/local/mysql/bin/

./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
#Explanations:
--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


10. Add mysqld system service

#For systemctl service management
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
#Refresh recognition
systemctl daemon-reload
#Turn on the service and set the startup self startup
systemctl start mysqld.service
systemctl enable mysqld
#View port
netstat -anpt | grep 3306

11. Modify the login password of mysql

#Set the password to 123456 for the root account, and the prompt is the original password (empty)
mysqladmin -u root -p password "123456"

12. Authorize remote login

mysql -u root -p
#The root user is authorized to log in remotely at all terminals with the password of 123456
grant all privileges on *.* to 'root'@'%' identified by '123456';
#View the existing database and pay attention to ";"
show databases;
Supplement:
#Have operation permissions on all databases and all tables
with grant option
#Add after the authorization command
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;

4, Compile and install PHP parsing environment

1. Transfer the software package required to install PHP to the / opt directory

php-7.1.10.tar.bz2

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

3. Configuring software modules

cd /opt
tar jxvf php-7.1.10.tar.bz2
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

Relevant explanations:
--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 configuration file for PHP Where 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



4. Compilation and installation

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. PHP when testing the environment Ini development file, while using PHP. Net in the production environment Ini production file
vim /usr/local/php7/php.ini
#Line 939; Uncomment, modify
date.timezone = Asia/Shanghai
#1170 lines; modify
mysqli.default_socket = /usr/local/mysql/mysql.sock



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

#See which modules PHP loads
php -m

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

vim /etc/httpd.conf
#158 lines; Check whether the module supporting php7 exists
LoadModule php7_module        modules/libphp7.so
#Line 258; Modify home page file name settings
DirectoryIndex index.html index.php
#Line 393; Insert the following
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps




8. Validate 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 access
http://192.168.163.10



5, Supplement ----- installation Forum

mysql -u root -p
#Create a database
CREATE DATABASE bbs;

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

#Refresh database
flush privileges;

show databases;

  • After editing, exit exits

2. Unzip the forum zip

unzip /opt/Discuz_X3.4_SC_UTF8.zip -d /opt/dis
#Upload site update package
cd /opt/dis/dir_SC_UTF8/
cp -r upload/ /usr/local/httpd/htdocs/bbs


3. Change the owner of the forum directory

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


  • If you don't have permission


4. Browser access authentication





Keywords: Operation & Maintenance

Added by shehroz on Sun, 09 Jan 2022 13:16:47 +0200