Overview of LAMP architecture

Posted by whit555 on Thu, 07 Oct 2021 06:36:58 +0200

catalogue

1, LAMP overview

1. Main functions of relevant components:

2. Precautions

2, Manually compile and install Apache services

1. Turn off firewall

2. Transfer the software packages required to install Apache to the / opt directory

3. Install environment dependent packages

4. Unzip the three compressed packages

5. Configuring software modules

6. Compilation and installation

7. Optimize the configuration file path, and put the executable program file of httpd service into the directory of path environment variable for system identification

8. Add httpd system service

9. Modify the / etc/httpd.conf service configuration file

10. Browser access authentication

3, Manually compile mysql database

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

2. Install environment dependent packages

3. Configuring software modules

4. Compilation and installation

5. Create mysql user

6. Modify mysql configuration file

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

8. Set path environment variable

9. Initialize database

10. Add mysqld system service

11. Modify the login password of mysql and authorize remote login

4, Manually compile and install PHP

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

3. Configuring software modules

4. Compilation and installation

5. Copy the template file as the main configuration file of PHP and modify it

6. Optimization puts PHP executable program files into the directory of path environment variables for system identification

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

8. Validate PHP test page

5, Use LAMP to build a forum

1. Complete the construction of LAMP

2. Create database and authorize

3. Upload and unzip the forum zip

4. Change the owner of the forum directory

5. Browser access authentication

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 static and 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. Main functions of relevant components:

  •   (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: as a programming language 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. Precautions

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

2, Manually compile and install Apache services

1. Turn off firewall

 

2. Transfer the software packages required to install Apache to the / opt directory

 

3. Install environment dependent packages

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

4. Unzip the three compressed packages

tar zxvf apr-1.6.2.tar.gz
tar zxvf apr-util-1.6.0.tar.gz
tar xf httpd-2.4.29.tar.bz2

5. Configuring software modules

mv apr-1.6.2 httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util


cd /opt/httpd-2.4.29/
./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi

6. Compilation and installation

make && make install

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

8. Add httpd system service

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

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

9. Modify the / etc/httpd.conf service configuration file

vi /usr/local/httpd/conf/httpd.conf
#--Line 52 -- modify
#Listen 192.168.200.50:80
--197 that 's ok--Uncomment, modify
ServerName 192.168.10.80: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
--->wq
#Check syntax
httpd -t  or apachectl -t


cat /usr/local/httpd/htdocs/index.html

service httpd restart
netstat -anpt | grep 80

10. Browser access authentication

3, Manually compile mysql database

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 ncurses-devel bison cmake

3. Configuring software modules

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

  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)

  be careful:

  • If an error is reported in the process of CMAKE, after the error is resolved, you need to delete the CMakeCache.txt file in the source directory, and then re CMAKE, otherwise the error will occur

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]									#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/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 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

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_ The common values of mode are as follows:

  • NO_ENGINE_SUBSTITUTION
  • 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
  • STRICT_TRANS_TABLES
  • 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
  • NO_AUTO_CREATE_USER
  • GRANT is not allowed to create a user with a blank password
  • NO_AUTO_VALUE_ON_ZERO
  • 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
  • NO_ZERO_IN_DATE
  • Zero date and month are not allowed
  • NO_ZERO_DATE
  • mysql database does not allow inserting zero date. Inserting zero date will throw an error instead of a warning
  • ERROR_FOR_DIVISION_BY_ZERO
  • 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
  • PIPES_AS_CONCAT
  • 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
  • ANSI_QUOTES
  • Enable ANSI_ After quotes, the string cannot be referenced in double quotes 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 \				#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

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

11. Modify the login password of mysql and authorize remote login

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

mysql -u root -p
grant all privileges on *.* to 'root'@'%' identified by 'abc123';
#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

4, Manually compile and install PHP

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. Configuring software modules

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

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 the php.ini-development file for the test environment and the php.ini-production file for the production environment
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. 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/

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

---Check support php7 Is the module present------
LoadModule php7_module        modules/libphp7.so

8. Validate PHP test page

rm -rf /usr/local/httpd/htdocs/index.html    #Delete default static homepage file
vim /usr/local/httpd/htdocs/index.php        #Write dynamic home page file
<?php
phpinfo();
?>

systemctl restart httpd.service              #Restart service

Browser access
http://192.168.184.80

5, Use LAMP to build a forum

1. Complete the construction of LAMP

2. Create database and authorize

mysql -u root -p 

mysql> CREATE DATABASE bbs;

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

mysql>flush privileges; 

3. Upload and unzip the forum zip

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

cd /opt/dis

cp -r upload/ /usr/local/httpd/htdocs/bbs

4. Change the owner of the forum directory

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

5. Browser access authentication

 

Topics: PHP Database MySQL