Source code compilation and installation LAMP


The lamp architecture based on apache is one of the mature enterprise website application modes and one of the highest market share in the market. Learning to deploy a basic lamp architecture can be the start of our in-depth study and understanding of the more complex architecture.

1, LAMP overview

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, Apache Web server, MySQL database server, PHP (or Perl, Python) web programming language.

(1) Function of each component

50: (platform) L inux: as the basis of LAMP architecture, it provides the operating system used 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).

A: (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.

M: (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.

P: (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) Installation sequence of components

When building the LAMP platform, the installation sequence of each component is Linux, Apache, MySQL and PHP. Apache and MySQL are not installed in strict order. 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.

(3) Data flow direction

2, Compile and install apache httpd service

(1) Close the firewall and upload the required software packages for installing apache to the / OPT directory

[root@youzi bbs]# systemctl stop firewalld
[root@youzi bbs]# systemctl disable firewalld
[root@youzi bbs]# setenforce 0

#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

[root@youzi opt]# yum install gcc gcc-c++ make pcre pcre-devel expat-devel perl -y

(3) Configuration software module

[root@youzi opt]# tar xf apr-1.6.2.tar.gz
[root@youzi opt]# tar xf apr-util-1.6.0.tar.gz
[root@youzi opt]# tar xf httpd-2.4.29.tar.bz2

[root@youzi opt]# mv apr-1.6.2 httpd-2.4.29/srclib/apr
[root@youzi opt]# mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util

[root@youzi httpd-2.4.29]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi

(4) Compilation and installation

make							#make -j n means that n cores are compiled at the same time (n is a number)
make install

(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

[root@youzi httpd-2.4.29]# ln -s /usr/local/httpd/conf/httpd.conf /etc/
[root@youzi httpd-2.4.29]# ln -s /usr/local/httpd/bin/* /usr/local/bin/

(6) Add httpd system service

vim /lib/systemd/system/httpd.service
Description=The Apache HTTP Server						#describe									#Describe service category
Type=forking											#Background operation mode
PIDFile=/usr/local/httpd/logs/					#PID file location
ExecStart=/usr/local/bin/apachectl $OPTIONS				#Start service
ExecReload=/bin/kill -HUP $MAINPID						#According to PID overload configuration

[root@youzi httpd-2.4.29]# systemctl start httpd.service
[root@youzi httpd-2.4.29]# systemctl enable httpd.service

(7) Modify httpd service configuration file

vim /etc/httpd.conf
--52 that 's ok--modify
--197 that 's ok--Uncomment, modify

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

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

(8) Access browser authentication

echo "" >> /etc/hosts   #Append the ip and domain name to the / etc/hosts file
/etc/hosts The file is a host mapping file that will IP File corresponding to the host

3, Compile and install mysqld service

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

(2) 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

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

(3) Configuration software module

[root@youzi opt]# tar zxf mysql-5.7.17.tar.gz
[root@youzi opt]# tar zxf boost_1_59_0.tar.gz

[root@youzi opt]# mv boost_1_59_0 /usr/local/boost
[root@youzi opt]# cd /opt/mysql-5.7.17/
[root@youzi 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_COLLATION=utf8_general_ci \
\> -DMYSQL_DATADIR=/usr/local/mysql/data \
\> -DWITH_BOOST=/usr/local/boost \

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)

Note: if an error is reported in the process of CMAKE, after the error is solved, you need to put cmakecache in the source directory Txt file is deleted, and then CMAKE is again. Otherwise, the error remains the same

(4) Compilation and installation

[root@youzi mysql-5.7.17]# make -j 3 && make install

(5) Create mysql user

[root@youzi mysql-5.7.17]# useradd -M -s /sbin/nologin mysql

(6) Modify profile

[root@youzi mysql-5.7.17]# vim /etc/my.cnf								#Delete the original configuration item and add the following content again
[client]									#Client settings
port = 3306

[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				#Specify the storage path of the database file
port = 3306									#Specify port
character-set-server=utf8					#Set the encoding format of the server character set to utf8
pid-file = /usr/local/mysql/		#Specify pid process file path
socket=/usr/local/mysql/mysql.sock			#Specify database connection file
bind-address =						#Set the listening address. 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						#Set the maximum packet size received by the database
server-id = 1								#Specify service ID number

sql_ The common values of mode are as follows:
If the required storage engine is disabled or not compiled, an error is thrown. When this value is not set, the default storage engine is used instead and an exception is thrown

In this mode, if a value cannot be inserted into a transaction table, the current operation will be interrupted and the non transaction table will not be restricted

GRANT is prohibited from creating users with blank passwords

The self growing column in mysql can start from 0. By default, the self growth column starts from 1. If you insert data with a value of 0, an error will be reported

Zero date and month are not allowed

mysql database is not allowed to insert zero date. Inserting zero date will throw an error instead of a warning

During INSERT or UPDATE, if the data is divided by zero, an error is generated instead of a warning. By default, MySQL returns NULL when the data is divided by zero

Treating "|" as a concatenation operator of a string rather than an or operator is the same as in Oracle database and is similar to the Concat function of a string

Enable ANSI_ After quotes, the string cannot be referenced in double quotation marks because it is interpreted as an identifier

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

[root@youzi bin]# chown -R mysql:mysql /usr/local/mysql/
[root@youzi bin]# chown mysql:mysql /etc/my.cnf

(8) Environment variable setting

[root@youzi mysql-5.7.17]# echo 'export PATH=/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@youzi mysql-5.7.17]# source /etc/profile
[root@youzi mysql-5.7.17]# echo $PATH

(9) Initialize database

[root@youzi mysql-5.7.17]# cd /usr/local/mysql/bin/
./mysqld \
--initialize-insecure \				#Generation initialization password is null
--user=mysql \                      #Specify administrative users
--basedir=/usr/local/mysql \        #Specify the installation directory of the database
--datadir=/usr/local/mysql/data		#Specify the storage path of the database file

./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \

(10) Add mysqld system service

[root@youzi bin]# cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/		#For systemctl service management
[root@youzi bin]# systemctl daemon-reload         #Refresh recognition     
[root@youzi bin]# systemctl start mysqld.service  #Open service
[root@youzi bin]# systemctl enable mysqld         #Power on self start
[root@youzi bin]# netstat -anpt | grep 3306       #View port

(11) Modify the login password of mysql

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

(12) Authorize remote login

mysql -u root -p
grant all privileges on *.* to 'root'@'%' identified by 'abc123';
#The root user is authorized to log in remotely at all terminals with the password abc123, and has operation authority on all databases and tables

show databases;			#View existing databases

4, Compile and install PHP parsing environment

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

(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) Configuration software module

[root@youzi bin]# cd /opt/
[root@youzi opt]# tar zxvf php-7.1.24.tar.gz
[root@youzi opt]# cd /opt/php-7.1.24/

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

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

(4) Compilation and installation

[root@youzi php-7.1.24]# make && make install

(5) Copy the template file as the main configuration file for PHP

[root@youzi php-7.1.24]# 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 in the production environment Ini production file

[root@youzi php-7.1.24]# 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

(6) Put the executable program file of PHP into the directory of path environment variable for system identification

[root@youzi php-7.1.24]# ln -s /usr/local/php7/bin/* /usr/local/bin/
[root@youzi php-7.1.24]# php -m 			#See which modules PHP loads

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

[root@youzi php-7.1.24]# vim /etc/httpd.conf 
--393 that 's ok--Insert the following
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
--256 that 's ok--Modify home page file name settings
DirectoryIndex index.html index.php

---Check 156 line support php7 Does the module exist------
LoadModule php7_module        modules/

(8) Validate PHP test page

[root@youzi php-7.1.24]# vim /etc/httpd.conf
[root@youzi php-7.1.24]# rm -rf /usr/local/httpd/htdocs/index.html
[root@youzi php-7.1.24]# vim /usr/local/httpd/htdocs/index.php

[root@youzi php-7.1.24]# systemctl restart httpd.service
 Test access

5, Installation Forum

(1) Create a database

[root@youzi php-7.1.24]# mysql -u root -p 123456
#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> exit

(2) Unzip the forum zip

[root@youzi php-7.1.24]# cd /opt/
[root@youzi opt]# ls
#Unzip the forum zip
[root@youzi opt]# unzip

(3) Upload site update package

[root@youzi opt]# cd dir_SC_UTF8/
#Upload site update package
[root@youzi dir_SC_UTF8]# cp -r upload/ /usr/local/httpd/htdocs/bbs

(4) Change home directory Forum

[root@youzi dir_SC_UTF8]# cd /usr/local/httpd/htdocs/bbs
[root@youzi bbs]# chown -R daemon ./config
[root@youzi bbs]# chown -R daemon ./data
[root@youzi bbs]# chown -R daemon ./uc_client
[root@youzi bbs]# chown -R daemon ./uc_server/data

(5) Install and verify

Database server: localhost  #Use the local IP number and the host address if not
 Database name: bbs
 Database user name: bbuser
 Database password: self input
 Administrator account: admin
 Administrator password: enter by yourself


  • Apache compilation and installation method
  • Types of virtual machine hosts supported by httpd service
  • Mysql database compilation and installation method
  • Method of constructing PHP running environment
  • Method of deploying and using phpMyAdmin system

Tags: PHP MySQL Apache

Posted by ShimmyShine on Fri, 20 May 2022 01:48:27 +0300