Build the LAMP architecture (LAMP website application mode), including the installation of Apache, Mysql and PHP

Posted by timj on Thu, 06 Jan 2022 10:56:16 +0100

LAMP Architecture 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, MysSQL database server, PHP (or Perl, Python) web programming language.

The main functions of each component are as follows:

(platform) Linux: as the basis of L.AMP architecture, it provides an operating system for supporting web sites, which can provide better stability and compatibility with other three components (AMP components also support windows, UNIX and other platforms).

(foreground) 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 LAMAP 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. It can be embedded in HTML, especially suitable for web application development.

When building the L.AMP 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 installed last, which is responsible for communicating the web server and database system to work together.

matters needing attention

  • 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. PHP environment is generally installed last, which is responsible for communicating the Web server and database system to work together.

Apache installation

Close the firewall and transfer the software packages required by apache

Install environment dependent packages

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

Configuring software modules

#Unzip file
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

#move file
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

cd /opt/httpd-2.4.29/
./configure \
--prefix=/usr/local/httpd \		#Specify the path where the httpd service program will be installed
--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

Compile and install

make -j 4 && make install

Optimize profile path

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/

Add httpd system service

cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
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    #Level 35 automatic operation, 85th startup, 21st shutdown
# description: Apache is a World Wide Web server

#Add service to service manager
chkconfig --add httpd
#Open service
systemctl start httpd.service

Modify httpd service profile

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

View status

Browser access authentication

echo "" >> /etc/hosts

Web page input native IP(The server IP)

Mysql installation

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

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

Configuring software modules

#Unzip package
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/
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

Compilation and installation

make -j 4 && make install

Create mysql user Modify mysql configuration file

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

[mysql]										#Server settings
port = 3306
socket = /usr/local/mysql/mysql.sock
auto-rehash									#Turn on the automatic completion function

[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/		#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						#Sets the maximum packet size received by the database
server-id = 1								#Specify the service ID number


Change the primary group of mysql installation directory and configuration file

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

Set path environment variable

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

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

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 service
systemctl enable mysqld         #Startup self startup
netstat -anpt | grep 3306       #View port

Modify the login password of mysql

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

show databases;			#View existing databases

PHP installation

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

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

Configuring software modules

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

Compilation and installation

make && make install

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
--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/
php -m 			#See which modules PHP loads

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

vim /etc/httpd.conf 
--393 that 's ok--Insert the following
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
--255 that 's ok--Modify home page file name settings
DirectoryIndex index.html index.php

Validate PHP test page

rm -rf /usr/local/httpd/htdocs/index.html
vim /usr/local/httpd/htdocs/index.php

systemctl restart httpd.service

Browser access

Installation Forum

mysql -u root -p  #Create database and authorize

#Create a database

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

flush privileges;
#Refresh database

show databases;

Unzip the forum zip

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

Change the owner of the forum directory

ps aux # viewing found 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

Browser access authentication

Forum page access

Topics: PHP MySQL Apache