Deploy the LAMP platform, compile and install Apache, MySQL, PHP, and forum

Keywords: PHP MySQL Apache


       Here we will introduce the deployment of LAMP platform and the steps of compiling and installing the source code of each component.

1, Introduction to LAMP

1. LAMP platform overview

         LAMP architecture is one of the mature enterprise website application modes at present, which refers to a whole system and related software working together,

It can provide dynamic web site service and its application development environment; LAMP is an abbreviation, specifically including Linux operating system,

Apache Web server, MySQL database server, PHP (or perl, Python) web programming language.

2. Build LAMP platform sequence

         During construction, the installation sequence of each component is Linux, Apache, MySQL and PHP; among

The installation of Apache and MySQL does not have strict sequence requirements, while the installation of PHP environment is generally the last, responsible for communicating with the web

The server and database system work together.

3. Advantages of compilation and installation

① . it has a large degree of freedom, and the function 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 various components of LAMP platform

◎ Linux (platform): as the basis of LAMP architecture, it provides an operating system for supporting the Web site, which can be connected with the other three components

Provide better stability and compatibility (AMP components also support Windows, UNIX and other platforms).

◎ Apache (foreground): as the front end of LAMP architecture, it is a Web server program with powerful functions and good stability

The device 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 the enterprise website, business

In system 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 this 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 and

Communicate with Web server and database system to work together, and provide the development and running environment of Web application. Where PHP is

A widely used open source multi-purpose scripting language, which can be embedded in HTML, especially suitable for Web applications


2, Apache website service foundation

1. Introduction and installation of Apache

① The origin of Apache

It comes from a patch server, a famous open source Web service software

In 1995, version 1.0 of the Apache service program was released

It is maintained by the Apache Software Foundation (ASF)

The latest name is Apache HTTP Server“

Official website:

② I. main features

● open source, cross platform applications (compatibility)

● support multiple web programming languages

● modular design (realizing proprietary functions through standard modules), stable operation and good safety

③ . software version

● 1.X

At present, the highest version is 1.3, which runs stably

Downward compatibility is good, but it lacks some newer features

The current maximum version is 2.4

More functional features

● the configuration management style of 2.X is quite different from that of 1.X

④ , apache functions

Static page processing and handing dynamic requests to PHP.

⑤ Advantages of compilation and installation

● it has a large degree of freedom and the function can be customized

● the latest software version can be obtained in time (the software version can be selected flexibly, and the software function module can be customized)

● it is generally applicable to most Linux versions and easy to transplant

2. Install httpd server

(1) preparation

① . necessary steps for newly installing virtual machine

[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/resolv.conf
[root@localhost ~]# ping
[root@localhost ~]# ntpdate #time synchronization 
25 Sep 08:46:52 ntpdate[62240]: adjust time server offset 0.007301 sec
[root@localhost ~]# hostnamectl set-hostname kang
[root@localhost ~]# su

② . obtain the source code package of Apache server: reference address:

③ . uninstall httpd and related dependent packages installed in other ways

rpm -e httpd --nodeps    # Ignore package dependencies

④ Download the compressed software package to / usr/local /

Unzip the package
[root@kang local]# tar zvxf apr-1.6.2.tar.gz
[root@kang local]# tar zvxf apr-util-1.6.0.tar.gz
[root@kang local]# tar jxf httpd-2.4.29.tar.bz2

  (2) unpacking and installation

① . install necessary supported compilers, etc

         Solve the dependent environment of source code installation

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

② Next, install the httpd package

[root@kang local]# cd httpd-2.4.29/
@kang 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
[root@kang httpd-2.4.29]# make && make install   #Compilation and installation
#Here, the command make -j 3 can be used for multi-core installation

(3) optimize the path of httpd configuration file

         Purpose: put the executable program file of httpd service into the directory of path variable for system identification and operation.

[root@kang local]# ln -s /usr/local/httpd/conf/httpd.conf  /etc 
#Link the configuration file to / etc /
[root@kang local]# ln -s /usr/local/httpd/bin/* /usr/local/bin/ 
#Link the executable file of httpd to / / usr/local/bin under / usr/local/bin 
/usr/local/snin For external commands,/bin /sbin Is an internal command

(4) files generated by installing httpd package and configuration files

         Modifying the configuration file allows httpd to run according to our requirements to meet our requirements. hhtpd configuration document

File path: / usr/local/httpd/conf/httpd.conf

[root@kang local]# cd httpd
[root@kang httpd]# ls    #Generate the following files
bin    cgi-bin  error   icons    lib   man     modules
build  conf     htdocs  include  logs  manual
[root@kang httpd]#
The meaning of each document is as follows: bin Command file; cgi-bin Universal gateway interface, api Interface; error Store some error information or record files;
icons Various picture format files; lib Is a function library; man Manual; modules Some functional modules; build Underlying environment, including libtool
 and Script files, etc; conf Configuration files, including httpd.conf Master profile and extra Extended profile; htdocs Site directory,
Specially store some web documents; logs Log file; manual. 

Modify the main modification items of the main configuration file:

① . listening address

② . access policy deny

③ . directory location of some important files (using relative path) / usr/local/httpd/documentroot -- storage / identifiable location of website files

Error logs - location of error logs

④ . core functions

[root@kang local]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd 
 #Let the service manage the httpd service, that is, add the service to the service manager
[root@kang local]# vim /etc/init.d/httpd  #Configure httpd master profile

# Chkconfig: 35 85 21 / / 35 level automatic operation 85th startup 21st shutdown
# description: Apache is a World Wide Web server
[root@kang httpd]# chkconfig --add httpd   #Add httpd to system manager
root@kang ~]# vim /usr/local/httpd/conf/httpd.conf
DocumentRoot "/usr/local/httpd/htdocs"   #Default home page storage path
<IfModule dir_module>
     DirectoryIndex index.html    #Default home page file name setting
: wq   
root@kang ~]# httpd -t  or apachectl -t    #Check syntax
root@kang ~]# Service httpd start starts the service
root@kang ~]# curl  #Specify IP address access

(5) introduction to main configuration file

<Directory />                  ## apache access control (equivalent to black and white list)
     AllowOverride none
     Require all denied
Options Indexes FollowSymLinks     ##Index file
AllowOverride None      ##access control 
<IfModule dir_module>          
     DirectoryIndex index.html     #Specify first page
ErrorLog "logs/error_log"        #Error log
LogLevel warn          #Logging level
Include conf/extra/proxy-html.conf     #Match other sub profiles

3, Install MySQL

1. Introduction

       MySQL is a real multi-threaded, multi-user SQL database service, with its high performance, high reliability and easy to use

Has become the most popular open source database system in the server field. Before 2008, MySQL project was implemented by mysql

AB company developed, released and supported it. After that, Sun company acquired MySQL AB company and Oracle company acquired Sun company

At present, Oracle is responsible for the operation and maintenance of MySQL project.

2. MySQL source code compilation and installation

(1) preliminary preparation

       Prepare the compilation and installation environment, as well as the mysql installation package and other dependent packages.

[root@kang ~]# 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

[root@kang ~]# yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake

Prepare the installation package:

(2) source code compilation and installation

[root@kang opt]# useradd -s /sbin/nologin mysql   #Create application user management
[root@kang opt]# tar xvzf mysql-5.7.17.tar.gz
[root@kang opt]# tar xvzf boost_1_59_0.tar.gz -C /usr/local/
[root@kang opt]# mv /usr/local/boost_1_59_0 /usr/local/boost
#Set the default character to utf8 and add support for other character sets
[root@kang opt]# 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
[root@kang opt]# make -j 4 && make install   #Compilation and installation

         ◆ storage engine options: MYISAM, MERGE, MEMORY and cSv engines are compiled into the server by default and do not need to be stored

To be clearly installed. Statically compile a storage engine to the server, using - DWITH engine STORAGE ENGINE= 1.

         ◆ available storage engine values include: ARCHIVE, BLACKHOLE, expand, FBDERATBD,

Innobasb (InnoDB), partton (partitioning support), and PERFSCHEMA(Performance


Note: if an error is reported in the process of CMAKE, after the error is resolved, the CMakeCache.txt file in the source directory needs to be deleted

Delete and then re CMAKE, otherwise the error remains

(3) modify the configuration file

Posted by phpuser1985 on Sun, 24 Oct 2021 20:09:24 -0700