LAMP source compilation and installation (Apache, Mysql, PHP, Forum installation details)

Preface

Installation packages required in this article are attached at the end. See the end for details

1. Overview of LAMP

1.LAMP architecture

LAMP architecture is one of the mature application modes of enterprise websites. It refers to a set of systems and related software that work together to provide dynamic Web site services and their application development environment.
LAMP is an abbreviation that includes the Linux operating system, Apache Web site server, MySQL database server, PHP (or Perl, Python) Web page programming language.

2. Key roles of LAMP components

(Platform) Linux: As the basis of the LAMP architecture, provides an operating system to support the Web site, provides better stability and compatibility with the other three components (AMP components also support Windows, UNIX, and other platforms).
(Foreground) Apache: As the front-end of the LAMP architecture, it is a powerful and stable Web server program that directly provides users with access to the Web site, sends Web pages, pictures and other file contents.
(Background) MySQL: As the backend of the LAMP architecture, it is a popular open source relational database system. In the application of enterprise website, business system, etc., all kinds of account information, product information, customer data, business data, etc. 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 Web servers and database systems to work together, and providing an environment for developing and running Web applications. PHP is a widely used open source, multi-purpose scripting language that can be embedded in HTML, especially for Web application development.

When building the LAMP platform, the install order of each component is Linux, Apache, MySQL, PHP in turn. Apache and MySQL are not installed in a strict order. The PHP environment is usually installed last and is responsible for communicating Web servers and database systems to work together.

2. Apache httpd service compilation and installation

1. Close the firewall and transfer the packages needed to install Apache to the / opt directory

systemctl stop firewalld	
systemctl disable firewalld
setenforce 0

httpd-2.4.29.tar.gz
apr-1.6.2.tar.gz
apr-util-1.6.0.tar.gz
#The apr component packages are designed to support cross-platform applications of Apache and provide a base interface library, which can effectively reduce the number of concurrent connections, process and access congestion.

2. Installation Environment Dependency Package

yum -y install \
gcc									#Compiler for C Language
gcc-c++ \							#C++ Compiler
make \								#Source Code Compiler (source code converted to binary file)
pcre \								#pcre is a library of Perl functions, including Perl-compatible regular expression libraries
pcre-devel \						#Interface development package for per1.
expat-devel \						#Used to support Web site parsing of HTML, XML files
perl								#perl Language Compiler
yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl

3. Configure software modules

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

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 installation path for the httpd service program
--enable-so \					#Enable dynamic loading module support to further extend httpd capabilities
--enable-rewrite \				#Enable page address rewriting for site optimization, anti-theft chains and directory migration maintenance
--enable-charset-lite \			#Start character set support to support pages encoded using a variety of character sets
--enable-cgi					#Enable CGI (Common Gateway Interface) scripting support to facilitate external expansion of application access to the site

./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi


4. Compile and Install

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

5. Optimize the configuration file path and place the executable files of the httpd service in the directory of path environment variables 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 services

Method 1:
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd		#For service service service management
chmod +x /etc/init.d/httpd
vi /etc/init.d/httpd
#!/bin/bash												#Insert a new line before the first line to add the three lines
# chkconfig: 35 85 21									#Level 35 Autorun 85th Startup 21st Shutdown
# description: Apache is a World Wide Web server

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

systemctl start httpd.service
 or
service httpd start

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

systemctl start httpd.service
systemctl enable httpd.service

7. Modify the httpd service configuration file

vim /etc/httpd.conf
--52 That's ok--modify
Listen 192.198.80.10:80
--197 That's ok--Uncomment, Modify
ServerName www.kgc.com:80

--221 That's ok--Default Home Page Storage Path
DocumentRoot "/usr/local/httpd/htdocs"
--255 That's ok--Default Home Page File Name Settings
DirectoryIndex index.html

httpd -t  or apachectl -t			#Check the profile for configuration items that are incorrect
cat /usr/local/httpd/htdocs/index.html
systemctl restart httpd.service

8. Browser Access Validation

netstat -anpt | grep 80
echo "192.168.80.10 www.kgc.com" >> /etc/hosts

http://192.168.121.11
http://www.kgc.com


3. Compilation and installation of mysqld service

1. Pass the package needed to install mysql to the / opt directory

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

2. Installation Environment Dependency Package

yum -y install \
gcc \
gcc-c++ \
ncurses \				#Dynamic Library for Graphic Interaction under Character Terminal
ncurses-devel \			#ncurses Development Package
bison \					#Grammar parser
cmake					#mysql needs to be compiled and installed with cmake

yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake

3. Configure 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 \		#Specify the installation path for mysql
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ #Specify the storage path for the mysql process listening socket file (database connection file)
-DSYSCONFDIR=/etc \                             #Specify the storage path for the configuration file
-DSYSTEMD_PID_DIR=/usr/local/mysql \            #Specify the storage path for process files
-DDEFAULT_CHARSET=utf8  \                       #Specifies the character set encoding used by default, such as utf8
-DDEFAULT_COLLATION=utf8_general_ci \			#Specify the default character set proofing rules
-DWITH_EXTRA_CHARSETS=all \						#Specify support for other character set encoding
-DWITH_INNOBASE_STORAGE_ENGINE=1 \              #Install INNOBASE storage engine
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \               #Install ARCHIVE storage engine 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \             #Install BLACKHOLE Storage Engine 
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \            #Install FEDERATED storage engine 
-DMYSQL_DATADIR=/usr/local/mysql/data \         #Specify the storage path of the database file
-DWITH_BOOST=/usr/local/boost \          #Specify the path to boost, if installed using the mysql-boost integration package -DWITH_BOOST=boost
-DWITH_SYSTEMD=1								#Generate files for easy systemctl management

Storage Engine Options:
MYISAM, MERGE, MEMORY, and CSV engines are compiled to 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 there are errors in the CMAKE process, you need to put CMakeCache in the source directory after the error is resolved. Delete the txt file and CMAKE again, otherwise the error will remain

4. Compile and Install

make -j  4  && 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 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 auto-completion

[mysqld]									#Service Global Settings
user = mysql       							#Set up administrative users
basedir=/usr/local/mysql					#Specify the installation directory for 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 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 the database connection file
bind-address = 0.0.0.0						#Set the listening address, 0.0.0.0 means allow all, such as allowing multiple IP s to be separated by spaces
skip-name-resolve							#Disable DNS Resolution
max_connections=2048						#Set the maximum number of connections for mysql
default-storage-engine=INNODB				#Specify the default storage engine
max_allowed_packet=16M						#Set maximum packet size received by database
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_ Common values for model 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, replace it 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 without restrictions on non-transaction tables
NO_AUTO_CREATE_USER
Prevent GRANT from creating users with empty passwords
NO_AUTO_VALUE_ON_ZERO
The self-growing column in mysql can start at 0. By default, growth columns start at 1, and you will get an error if you insert data with a value of 0
NO_ZERO_IN_DATE
Zero dates and months are not allowed
NO_ZERO_DATE
The mysql database does not allow zero date insertion, which throws an error instead of a warning
ERROR_FOR_DIVISION_BY_ZERO
In INSERT or UPDATE, if the data is divided by zero, an error instead of a warning is generated. MySQL returns NULL by default when data is divided by zero
PIPES_AS_CONCAT
Treat'|'as a string's connection operator instead of an or operator, similar to Oracle databases and Concat, the splicing function of strings
ANSI_QUOTES
Enable ANSI_ After QUOTES, you cannot quote a string in double quotes because it is interpreted as an identifier

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

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

8. Setting path environment variables

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

9. Initialize the database

cd /usr/local/mysql/bin/
./mysqld \
--initialize-insecure \				#Generate initialization password is empty
--user=mysql \                      #Specify administrative users
--basedir=/usr/local/mysql \        #Specify the installation directory for the database
--datadir=/usr/local/mysql/data		#Specify 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 Identify     
systemctl start mysqld.service  #Open Service
systemctl enable mysqld         #Start-up self-start
netstat -anpt | grep 3306       #View Port

11. Modify mysql's login password

mysqladmin -u root -p password "666" 	#Set the password to 666 for the root account, prompting for the original password (empty)

12. Authorize remote login

mysql -u root -p
grant all privileges on *.* to 'root'@'%' identified by '666';
#Grant root user remote login at all terminals with a password of 666 and operational privileges on all databases and all tables


show databases;			#View existing databases

4. Compile and Install PHP Resolution Environment

1. Pass the package needed to install PHP to / opt directory

php-7.1.10.tar.bz2

2. Install GD Library and GD Library Associators 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. Configure 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 installation path for the PHP program
--with-apxs2=/usr/local/httpd/bin/apxs \			#Specify 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 for the mysql database connection file
--with-config-file-path=/usr/local/php7				#Set PHP profile php. Location where ini will be stored
--with-mysqli \										#Add to MySQL Extended support #The mysqli extension technology not only calls MySQL stored procedures and handles MySQL transactions, but also makes accessing the database more stable
--with-zlib \										#Supports zlib functionality, providing data compression
--with-curl \										#Turn on curl extensions to implement Get download and Post request methods for HTTP
--with-gd \											#Activate support for the gd Library
--with-jpeg-dir \									#Activate support for jpeg
--with-png-dir \									#Activate png support
--with-freetype-dir \
--with-openssl \
--enable-mbstring \									#Enable multi-byte string functionality to support code like Chinese
--enable-xml \										#Open Extensibility 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. Compile and Install

make -j  4 && make install

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

cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini	
#Use PHP when testing the environment. Ini-development file, while PHP is used in production environments. 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

6. Optimize placing PHP executable files in directories of path environment variables for system identification

ln -s /usr/local/php7/bin/* /usr/local/bin/
php -m 			#See which modules PHP loads

7. Modify the configuration file of the httpd service so that apache supports 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
--256 That's ok--Modify Home Page File Name Settings
DirectoryIndex index.html index.php

---Check support php7 Does the module exist------
LoadModule php7_module        modules/libphp7.so

8. Verify the 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.80.10


5. Installation Forum

1. Create a database and authorize it

mysql -u root -p

CREATE DATABASE bbs;
#Create a database

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

flush privileges;					
#Refresh Database

show databases;

2. Unzip Forum Compressed Pack

unzip /opt/Discuz_X3.4_SC_UTF8.zip -d /opt/dis
cd /opt/dis/dir_SC_UTF8/
cp -r upload/ /usr/local/httpd/htdocs/bbs		#Upload Site Update Package


3. Change the owner of the forum directory

ps aux							#View that the username of the discovery 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

4. Browser Access Validation

Forum Page Access
http://192.168.121.11/bbs
----------------------------------------------------------------------------------------------------------
Database Server: localhost     ###localhost for local setup, how to fill in IP address and port number instead of local setup
 Database name: bbs
 Database user name: bbsuser
 Database password: 666
 administrator account:root
 Administrator password:666
----------------------------------------------------------------------------------------------------------
Forum Background Administrator Page
http://192.168.80.10/bbs/admin.php







Installation package

Links: Installation package address
Extraction Code: 1122

Keywords: lamp

Added by jswash on Wed, 02 Feb 2022 05:47:19 +0200