Manually deploy LAMP schema

Configure environment:

  • Redhat 8.2
  • Apache source code compilation and installation
  • MySQL binary installation
  • PHP source code compilation and installation

1,Apache

1.1 download the required software package

Apache: you need to download HTTP, APR and APR util packages from the official website
http download link: https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/
APR and APR util links: http://https://mirrors.tuna.tsinghua.edu.cn/apache/apr/
After downloading, compile and install the source trilogy in the order of Apache, MySQL and PHP.

1.2 three steps of source code and preparation

  • . / configure define compilation parameters and check whether the compilation environment meets the requirements.
    The configure script generates a makefile file for use by the make tool. When executing the configure script, configure will generate makefile files in combination with the options specified by the user on the command line and each Makefile.in template file
    The common options of the congigure are as follows:
--help: Get the options it supports
	--prefix=/PATH/TO/SOMEWHERE: Specify the default installation location; Default to/usr/local/;
	--sysconfdir=/PATH/TO/SOMEWHERE: Installation location of configuration file;
	--enable-FEATURE[=ARG]: Open the specified feature and installation path; It does not need to be specified when it is enabled by default;
	--disable-FEATURE: Turn off the specified properties; No need to specify when closing by default;
	--with-PACKAGE[=ARG]: Install the specified dependent package and its installation path;
	--without-PACKAGE: Do not install the specified dependent package;
  • Make compilation
    The compilation of the program takes place at this step, but make itself is not a compiler, it is just a project construction tool
    After the make program is executed, the compiled application in the target binary format (including binary program, library file, configuration file and help document) will be created in the current directory

  • The Make install command copies the compiled package to each directory specified by the user

preparation

[root@localhost src]# ll
 Total consumption 658096
-rw-r--r--. 1 root root    872238 9 February 24:23 apr-1.7.0.tar.bz2
-rw-r--r--. 1 root root    428595 9 February 24:23 apr-util-1.6.1.tar.bz2
drwxr-xr-x. 2 root root         6 8 December 2018 debug
-rw-r--r--. 1 root root   7194385 9 February 24:23 httpd-2.4.48.tar.bz2
drwxr-xr-x. 2 root root         6 8 December 2018 kernels
-rw-r--r--. 1 root root 665389778 9 September 15:50 mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# pwd
/usr/src

Clear the cache and install the development kit

[root@localhost apr-1.7.0]# yum clean all
[root@localhost apr-1.7.0]# yum groups mark install 'Development Tools'

Create users and groups for Apache services

[root@localhost apr-1.7.0]# useradd  -r -M -s  /sbin/nologin  apache[root@localhost apr-1.7.0]# id apache
uid=989(apache) gid=985(apache) group=985(apache)

Download rpel source

[root@localhost apr-1.7.0]#yum -y install epel-release
[root@localhost yum.repos.d]# ll
 Total consumption 32
....
-rw-r--r--. 1 root root 1417 6 August 8:29 epel.repo
....

Install dependent packages required for Apache services

[root@localhost apr-1.7.0]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++  make

Unzip the downloaded compressed package

[root@localhost src]# tar xf apr-1.7.0.tar.bz2
[root@localhost src]# tar xf apr-util-1.6.1.tar.bz2
[root@localhost src]# tar xf httpd-2.4.48.tar.bz2 
[root@localhost src]# ll
 Total consumption 8312
drwxr-xr-x. 27 1001 1001    4096 4 February 2019 apr-1.7.0
-rw-r--r--.  1 root root  872238 9 June 23-18:28 apr-1.7.0.tar.bz2
drwxr-xr-x. 20 1001 1001    4096 10 June 18, 2017 apr-util-1.6.1
-rw-r--r--.  1 root root  428595 9 June 23-18:28 apr-util-1.6.1.tar.bz2
drwxr-xr-x.  2 root root       6 8 December 2018 debug
drwxr-xr-x. 12 1000 1000    4096 5 May 18:21 httpd-2.4.48
-rw-r--r--.  1 root root 7194385 9 June 23-18:28 httpd-2.4.48.tar.bz2
drwxr-xr-x.  2 root root       6 8 December 2018 kernels

Go to the configure file in apr-1.7.0 and comment or delete it R M " RM " RM"cfgfile"

[root@localhost apr-1.7.0]# vim configure
    cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    # $RM "$cfgfile"

1.3 compilation and installation

Compile and install according to apr - apr util - http
apr compilation

# Define the compilation and installation location and check whether the compilation environment meets the requirements
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr

#Compilation starts
[root@localhost apr-1.7.0]# make

#Place the compiled file in the specified location
[root@localhost apr-1.7.0]# make install

APR util compilation

#Specify the installation location and indicate where the apr is installed
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

#compile
[root@localhost apr-util-1.6.1]# make

#Place the compiled file in the specified location
[root@localhost apr-util-1.6.1]# make install

http compilation

#Specify the installation location and the location of apr and apr util
./configure --prefix=/usr/local/apache \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork

#make compilation
[root@localhost httpd-2.4.48]# make

#make install
[root@localhost httpd-2.4.48]# make install

1.4 modify configuration

Configure environment variables to find httpd

[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
#Read the new environment variable
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# which httpd
/usr/local/apache/bin/httpd

Create a soft link to the include (header file). By default, the system searches in the / usr/include / directory

[root@localhost include]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost include]# ll httpd
lrwxrwxrwx. 1 root root 26 9 June 23-19:29 httpd -> /usr/local/apache/include/

Configure the location of the document

[root@localhost ~]# vim /etc/man_db.conf
......
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man
......

Modify the httpd configuration file and uncomment it. Host name port is valid

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 
ServerName www.example.com:80

Turn off the firewall and selinux, and set the Apache control file and start self startup

[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# cp /usr/lib/systemd/system/sshd.service   /usr/lib/systemd/system/httpd.service
[root@localhost ~]# vim  /usr/lib/systemd/system/httpd.service
[Unit]
Description=httpd server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl  stop
ExecReload=/bin/kil tHUP $MAINPID

[Install]
WantedBy=multi-user.target

#Load profile from New
[root@localhost ~]# systemctl daemon-reload

#Set startup and self startup
[root@localhost ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

2,MySQL

2.1 preparation

Install the dependency package and put the prepared MySQL binary installation package under / usr/src

#Install environment dependent packages
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

#MySQL commands can only be used after installing the software package
[root@localhost ]# yum -y install ncurses-compat-libs

[root@localhost src]# ll
 Total consumption 658108
drwxr-xr-x. 28 1001 1001      4096 9 June 23-18:54 apr-1.7.0
-rw-r--r--.  1 root root    872238 9 June 23-18:28 apr-1.7.0.tar.bz2
drwxr-xr-x. 21 1001 1001      4096 9 June 23-19:10 apr-util-1.6.1
-rw-r--r--.  1 root root    428595 9 June 23-18:28 apr-util-1.6.1.tar.bz2
drwxr-xr-x.  2 root root         6 8 December 2018 debug
drwxr-xr-x. 13 1000 1000      4096 9 June 23-19:16 httpd-2.4.48
-rw-r--r--.  1 root root   7194385 9 June 23-18:28 httpd-2.4.48.tar.bz2
drwxr-xr-x.  2 root root         6 8 December 2018 kernels
-rw-r--r--.  1 root root 665389778 9 April 24:23 mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz

Create users and groups

[root@localhost src]# useradd -r -M -s /sbin/nologin mysql
[root@localhost src]# id mysql 
uid=988(mysql) gid=984(mysql) group=984(mysql)

Decompress & & Rename & & modify owner

[root@localhost src]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost local]# mv mysql-5.7.34-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ls
apache  apr-util  etc    include  lib64    mysql  share
apr     bin       games  lib      libexec  sbin   src
[root@localhost local]# chown mysql.mysql mysql/
[root@localhost local]# ll
......
drwxr-xr-x.  9 mysql mysql 129 9 April 24:27 mysql

Configure environment variables

[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
#Read new environment variables
[root@localhost ~]# source /etc/profile.d/mysql.sh 
#Find mysql commands
[root@localhost ~]# which mysql
/usr/local/mysql/bin/mysql

Configure the header include link and man document location

[root@localhost mysql]# ln -s /usr/local/mysql/include/ /usr/include/mysql/

[root@localhost ~]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man
MANDATORY_MANPATH                       /usr/local/mysql/man

Configure the MySQL lib library file. The Lib file is not in the default / usr/lib /. Write a configuration file so that the system can find the Lib library file

[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
#Make the configuration file effective
[root@localhost ~]# ldconfig

Create a database directory and modify the owner and group

[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown  -R mysql.mysql /opt/data
[root@localhost ~]# ll /opt/
Total consumption 0
drwxr-xr-x. 2 mysql mysql 6 9 April 24:58 data

2.2 initializing the configuration database

Initialize database

[root@localhost ~]# mysqld --initialize-insecure --user mysql --datadir /opt/data   
//-Secure: do not use a password when initializing the database. After initialization, enter the database and set it yourself

Generate data profile

[root@localhost ~]# cat > /etc/my.cnf <<EOF
> [mysqld]
> basedir = /usr/local/mysql
> datadir = /opt/data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /opt/data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF

[root@localhost ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve

Configure startup script and startup self startup

#Change the configuration file installation location and data storage location in the support file
[root@localhost ~]# vim /usr/local/mysql/support-files/mysql.server
basedir=/usr/local/mysql
datadir=/opt/data

#Generate service control file
[root@localhost system]# vim mysql.service 
[root@localhost system]# pwd
/usr/lib/systemd/system

[Unit]
Description=mysql server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kil tHUP $MAINPID

[Install]
WantedBy=multi-user.target


#Reload profile
[root@localhost system]# systemctl daemon-reload 
#Start MySQL and set startup self startup
[root@localhost system]# systemctl enable --now mysql.service 
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /usr/lib/systemd/system/mysql.service.
[root@localhost system]# ss -antl
State   Recv-Q  Send-Q     Local Address:Port     Peer Address:Port  
LISTEN  0       128              0.0.0.0:22            0.0.0.0:*     
LISTEN  0       80                     *:3306                *:*     
LISTEN  0       128                    *:80                  *:*     
LISTEN  0       128                 [::]:22               [::]:*     

Configure database password

[root@localhost system]# mysql
#Set password to wjmwjm
mysql> set password = password('wjmwjm');
Query OK, 0 rows affected, 1 warning (0.00 sec)

#Test whether the database password is set successfully
[root@localhost system]# mysql -uroot -pwjmwjm
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

3,PHP

3.1 preparation

Install the dependent packages required for PHP

yum -y install  php*

Download PHP source package
Go to PHP's official website: https://www.php.net/downloads.php#v8.0.11 , select php-8.0.11.tar.xz and click auto download;

[root@localhost src]# ll
 Total consumption 668660
drwxr-xr-x. 28 1001 1001      4096 9 June 23-18:54 apr-1.7.0
-rw-r--r--.  1 root root    872238 9 June 23-18:28 apr-1.7.0.tar.bz2
drwxr-xr-x. 21 1001 1001      4096 9 June 23-19:10 apr-util-1.6.1
-rw-r--r--.  1 root root    428595 9 June 23-18:28 apr-util-1.6.1.tar.bz2
drwxr-xr-x.  2 root root         6 8 December 2018 debug
drwxr-xr-x. 13 1000 1000      4096 9 June 23-19:16 httpd-2.4.48
-rw-r--r--.  1 root root   7194385 9 June 23-18:28 httpd-2.4.48.tar.bz2
drwxr-xr-x.  2 root root         6 8 December 2018 kernels
-rw-r--r--.  1 root root 665389778 9 April 24:23 mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
-rw-r--r--.  1 root root  10804388 9 September 24:47 php-8.0.11.tar.xz

3.2 extract, compile and install

#decompression
[root@localhost src]# tar xf php-8.0.11.tar.xz
[root@localhost src]# cd php-8.0.11/

#First execute the following command package. The system will automatically check the dependent package. If it does not meet the requirements, it will prompt the required dependencies, and then find the corresponding dependent package in rpm
./configure --prefix=/usr/local/php8  \
--with-config-file-path=/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif  \
--enable-ftp \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--with-gettext \
--enable-json \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix

#Error prompt
1,If present“ Package 'sqlite3', required by 'virtual:world', not found",Can use yum list all | grep Filter or remove pkgs.org Website search download
yum -y install https://download-ib01.fedoraproject.org
/pub/epel/8/Everything/x86_64/Packages/l/libsqlite3x-devel-20071018-26.el8.x86_64.rpm

2,lack oniguruma I'll go if I can pkgs.org Website search download
yum -y install http://mirror.centos.org/centos/8-
stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm

[root@node4 src]# pwd
/usr/src
[root@node4 src]# ls | grep -w php-8.0.10
php-8.0.10
php-8.0.10.tar.xz
[root@node4 src]# tar xf php-8.0.10.tar.xz
./configure --prefix=/usr/local/php8  --with-config-file-path=/etc --enable-fpm --disable-debug --disable-rpath --enable-shared --enable-soap --with-openssl --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --enable-exif  --enable-ftp --enable-gd --with-jpeg --with-zlib-dir --with-freetype --with-gettext --enable-mbstring --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline --enable-shmop --enable-simplexml --enable-sockets --with-zip --enable-mysqlnd-compression-support --with-pear --enable-pcntl --enable-posix
[root@node4 php-8.0.10]# make && make install

3.3 configuring PHP

Configure environment variables

[root@node4 php-8.0.10]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh
[root@node4 php-8.0.10]# source /etc/profile.d/php.sh

Configuration PHP FPM file

[root@node4 php-8.0.10]# cp php.ini-production /etc/php.ini
cp: Overwrite'/etc/php.ini'? y
[root@node4 php-8.0.10]# pwd
/usr/src/php-8.0.10

[root@node4 sapi]# cp fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@node4 sapi]# pwd
/usr/src/php-8.0.10/sapi

[root@node4 sapi]# ll /etc/init.d/php-fpm 
-rw-r--r-- 1 root root 2402 9 March 23:48 /etc/init.d/php-fpm
[root@node4 sapi]# chmod +x /etc/init.d/php-fpm

[root@node4 etc]# cp php-fpm.conf.default php-fpm.conf
[root@node4 etc]# pwd
/usr/local/php8/etc

[root@node4 php-fpm.d]# cp www.conf.default www.conf
[root@node4 php-fpm.d]# pwd
/usr/local/php8/etc/php-fpm.d

Configure system service control PHP, and set startup and self startup

[root@node4 bin]# cp /usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/php-fpm.service
[root@node4 bin]# vim /usr/lib/systemd/system/php-fpm.service

[root@node4 bin]# cat /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=php server daemon
After=network.target

[Service]
Type=forking
ExecStart=/etc/init.d/php-fpm start
ExecStop=/etc/init.d/php-fpm stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

#Reload the configuration file and set the boot auto start
[root@node4 bin]# systemctl daemon-reload 
[root@node4 bin]# systemctl enable --now php-fpm
[root@node4 bin]# systemctl status php-fpm.service 
● php-fpm.service - php server daemon
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vend>
   Active: active (running) since Fri 2021-09-24 00:14:02 CST; 20s ago

3.4 configure Apache and start the agent

Start agent module

[root@node4 php-fpm.d]# vim /usr/local/apache/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
121 #LoadModule proxy_connect_module modules/mod_proxy_connect.so
122 #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
123 #LoadModule proxy_http_module modules/mod_proxy_http.so
124 LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

Create a virtual host directory and configure the php test page

[root@node4 htdocs]# pwd
/usr/local/apache/htdocs
[root@node4 htdocs]# ls
index.html
[root@node4 htdocs]# mkdir test
[root@node4 htdocs]# pwd
/usr/local/apache/htdocs
[root@node4 htdocs]# cd test/
root@node4 test]# vim index.php
[root@node4 test]# cat index.php 
<?php
    phpinfo();
?>
[root@node4 test]# chown -R apache.apache /usr/local/apache/htdocs/
Change owner and group

Add content to configuration file

[root@node4 conf]# pwd
/usr/local/apache/conf
[root@node4 conf]# vim httpd.conf 

<VirtualHost *:80>
517     DocumentRoot "/usr/local/apache/htdocs/test"
518     ServerName www.test.com
519     ProxyRequests Off
520     ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache    /htdocs/test/$1
521     <Directory "/usr/local/apache/htdocs/test">
522         Options none
523         AllowOverride none
524         Require all granted
525     </Directory>
526 </VirtualHost>
In order to access php The page also needs to add the following content
399     AddType application/x-httpd-php .php
400     AddType application/x-httpd-php-source .phps
261     DirectoryIndex index.html index.php
 Last restart httpd Service is enough

test

Tags: PHP MySQL

Posted on Fri, 24 Sep 2021 11:36:14 -0400 by aspguy