lamp 1. lamp簡介 lamp,其實就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一組動態網站或者伺服器的開源軟體 LAMP指的是Linux(操作系統)、Apache(HTTP伺服器)、MySQL(也指MariaDB,資料庫軟體)和PHP(有時也 ...
lamp
目錄
1. lamp簡介
lamp,其實就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一組動態網站或者伺服器的開源軟體
LAMP指的是Linux(操作系統)、Apache(HTTP伺服器)、MySQL(也指MariaDB,資料庫軟體)和PHP(有時也是指Perl或Python)的第一個字母,一般用來建立web應用平臺。
2. web伺服器工作流程
web伺服器的資源分為兩種,靜態資源和動態資源
靜態資源:當我們獲取它的時候,它裡面的源的表現形式與原文件相同不會發生什麼改變。
動態資源:程式文件,我們日常執行的命令在不同的主機裡面執行出來的結果是不一樣的
當我們在客戶端訪問web伺服器資源的時候,前端會把這個請求轉發給應用伺服器這裡,然後應用伺服器會到資料庫裡面進行查詢並反饋給前端,前端再反饋給客戶端
3. lamp平臺構建
環境說明:
系統平臺 | IP | 需要安裝的服務 |
---|---|---|
centos8 redhat8 | 192.168.222.250 | httpd-2.4,mysql5.7,php,phpmysql |
lamp平臺軟體安裝次序:
httpd --> mysql --> php
註意:php要求httpd使用prefork MPM
3.1 安裝httpd
yum源的配置:
[root@lnh ~]# cd /etc/yum.repos.d/
[root@lnh yum.repos.d]#rm -rf *
[root@lnh yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
//在阿裡雲網站裡面複製的倉庫鏈接
[root@lnh yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@lnh yum.repos.d]# ls
CentOS-Base.repo
[root@lnh yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@lnh yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@lnh yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
//安裝epel源,也是在阿裡雲網站裡面複製鏈接
[root@lnh yum.repos.d]# ls
CentOS-Base.repo epel.repo epel-testing.repo
epel-modular.repo epel-testing-modular.repo
[root@lnh yum.repos.d]# cat epel.repo //查看裡面地址是否改變
[epel]
name=Extra Packages for Enterprise Linux 8 - $basearch
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
baseurl=https://mirrors.aliyun.com/epel/8/Everything/$basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-8&arch=$basearch&infra=$infra&content=$contentdir
enabled=1
gpgcheck=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 8 - $basearch - Debug
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
baseurl=https://mirrors.aliyun.com/epel/8/Everything/$basearch/debug
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-8&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 8 - $basearch - Source
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place it's address here.
baseurl=https://mirrors.aliyun.com/epel/8/Everything/source/tree/
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-8&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=1
[root@lnh yum.repos.d]# dnf makecache //緩存一下
[root@lnh ~]# dnf groups mark install 'Development Tools'
//安裝開發工具包
Last metadata expiration check: 0:03:41 ago on Tue 02 Aug 2022 09:17:12 PM CST.
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Dependencies resolved.
===================================================================================
Package Architecture Version Repository Size
===================================================================================
Installing Groups:
Development Tools
Transaction Summary
===================================================================================
Is this ok [y/N]: y
Complete!
[root@lnh ~]# useradd -r -M -s /sbin/nologin apache
//創建用戶的時候它會創建一個和用戶名相同名字的組
//創建apache服務的用戶和組
[root@lnh ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ wget vim make
//安裝依賴包
[root@lnh ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz
//在https://downloads.apache.org/官網裡面下載
[root@lnh ~]# ls
anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54.tar.gz
[root@lnh ~]# tar -xf apr-1.7.0.tar.gz
[root@lnh ~]# tar -xf apr-util-1.6.1.tar.gz
[root@lnh ~]# tar -xf httpd-2.4.54.tar.gz
[root@lnh ~]# ls
anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54.tar.gz
apr-1.7.0 apr-util-1.6.1 httpd-2.4.54
[root@lnh ~]# cd apr-1.7.0/
[root@lnh apr-1.7.0]# ls
apr-config.in build-outputs.mk helpers misc strings
apr.dep CHANGES include mmap support
apr.dsp CMakeLists.txt libapr.dep network_io tables
apr.dsw config.layout libapr.dsp NOTICE test
apr.mak configure libapr.mak NWGNUmakefile threadproc
apr.pc.in configure.in libapr.rc passwd time
apr.spec docs LICENSE poll tools
atomic dso locks random user
build emacs-mode Makefile.in README
build.conf encoding Makefile.win README.cmake
buildconf file_io memory shmem
[root@lnh apr-1.7.0]# vim configure
# $RM "$cfgfile" //刪除或者註釋掉這個
[root@lnh apr-1.7.0]# ./configure --prefix=/usr/local/apr
...
config.status: creating test/internal/Makefile
config.status: creating include/arch/unix/apr_private.h
config.status: executing libtool commands
config.status: executing default commands
[root@lnh apr-1.7.0]# make
[root@lnh apr-1.7.0]# make install
[root@lnh apr-1.7.0]# cd ../apr-util-1.6.1/
[root@lnh apr-util-1.6.1]# ls
aprutil.dep CHANGES include NWGNUmakefile
aprutil.dsp CMakeLists.txt ldap README
aprutil.dsw config.layout libaprutil.dep README.cmake
aprutil.mak configure libaprutil.dsp README.FREETDS
apr-util.pc.in configure.in libaprutil.mak redis
apr-util.spec crypto libaprutil.rc renames_pending
apu-config.in dbd LICENSE strmatch
buckets dbm Makefile.in test
build docs Makefile.win uri
build.conf encoding memcache xlate
buildconf export_vars.sh.in misc xml
build-outputs.mk hooks NOTICE
[root@lnh apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@lnh apr-util-1.6.1]# make
[root@lnh apr-util-1.6.1]# make install
[root@lnh ~]# ls /usr/local/
apr apr-util bin etc games include lib lib64 libexec sbin share src
[root@lnh ~]# cd httpd-2.4.54/
[root@lnh httpd-2.4.54]# ls
ABOUT_APACHE CHANGES httpd.mak Makefile.in ROADMAP
acinclude.m4 changes-entries httpd.spec Makefile.win server
Apache-apr2.dsw CMakeLists.txt include modules srclib
Apache.dsw config.layout INSTALL NOTICE support
apache_probes.d configure InstallBin.dsp NWGNUmakefile test
ap.d configure.in LAYOUT os VERSIONING
build docs libhttpd.dep README
BuildAll.dsp emacs-style libhttpd.dsp README.CHANGES
BuildBin.dsp httpd.dep libhttpd.mak README.cmake
buildconf httpd.dsp LICENSE README.platforms
[root@lnh httpd-2.4.54]# ./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
....
Server Version: 2.4.54
Install prefix: /usr/local/apache
C compiler: gcc
CFLAGS: -g -O2 -pthread
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -E
[root@lnh httpd-2.4.54]# make
[root@lnh httpd-2.4.54]# make install
[root@lnh httpd-2.4.54]# cd
[root@lnh ~]# ls
anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54.tar.gz
apr-1.7.0 apr-util-1.6.1 httpd-2.4.54
[root@lnh ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh //配置環境變數
[root@lnh ~]# cat /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
[root@lnh ~]# ls /usr/local/
apache apr-util etc include lib64 sbin src
apr bin games lib libexec share
[root@lnh ~]# source /etc/profile.d/httpd.sh
[root@lnh ~]# which httpd //查看路徑
/usr/local/apache/bin/httpd
[root@lnh ~]# ls /usr/local/apache/
bin cgi-bin error icons logs manual
build conf htdocs include man modules
[root@lnh ~]# ln -s /usr/local/apache/include /usr/include/apache
//做一個頭文件軟鏈接
[root@lnh ~]# ll -d /usr/include/apache
lrwxrwxrwx. 1 root root 25 Aug 2 22:37 /usr/include/apache -> /usr/local/apache/include
[root@lnh ~]# 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//添加這一行
[root@lnh ~]# cd /usr/lib/systemd/system
[root@lnh system]# cp sshd.service httpd.service
[root@lnh system]# vim httpd.service
[Unit]
Description=httpd server daemon
Documentation=man:httpd(5)
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@lnh system]# cd
[root@lnh ~]# systemctl daemon-reload
[root@lnh ~]# systemctl enable --now httpd.service //設置開機自啟
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@lnh ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@lnh ~]# systemctl status httpd.service
● httpd.service - httpd server daemon
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: >
Active: active (running) since Tue 2022-08-02 22:49:17 CST; 30s ago
Docs: man:httpd(5)
Process: 49081 ExecStart=/usr/local/apache/bin/apachectl start (code=exited, sta>
Main PID: 49084 (httpd)
Tasks: 6 (limit: 12221)
Memory: 5.7M
CGroup: /system.slice/httpd.service
├─49084 /usr/local/apache/bin/httpd -k start
├─49085 /usr/local/apache/bin/httpd -k start
├─49086 /usr/local/apache/bin/httpd -k start
├─49087 /usr/local/apache/bin/httpd -k start
├─49088 /usr/local/apache/bin/httpd -k start
└─49089 /usr/local/apache/bin/httpd -k start
Aug 02 22:49:17 lnh systemd[1]: Starting httpd server daemon...
Aug 02 22:49:17 lnh apachectl[49081]: AH00558: httpd: Could not reliably determine>
Aug 02 22:49:17 lnh systemd[1]: Started httpd server daemon.
3.2 安裝mysql
[root@lnh ~]# dnf -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
//安裝依賴包
[root@lnh ~]# useradd -r -M -s /sbin/nologin mysql
//創建用戶和組
[root@lnh ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
//下載二進位格式的mysql軟體包
[root@lnh ~]# ls
anaconda-ks.cfg apr-util-1.6.1.tar.gz
apr-1.7.0 httpd-2.4.54
apr-1.7.0.tar.gz httpd-2.4.54.tar.gz
apr-util-1.6.1 mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@lnh ~]# tar -xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@lnh ~]# cd /usr/local/
[root@lnh local]# ls
apache bin include libexec share
apr etc lib mysql-5.7.38-linux-glibc2.12-x86_64 src
apr-util games lib64 sbin
[root@lnh local]# mv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
//也可以做軟鏈接ln -sv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
[root@lnh local]# ls
apache apr-util etc include lib64 mysql share
apr bin games lib libexec sbin src
[root@lnh local]# chown -R mysql.mysql mysql //修改目錄/usr/local/mysql的屬主屬組
[root@lnh local]# ll
total 0
drwxr-xr-x. 14 root root 164 Aug 2 22:32 apache
drwxr-xr-x. 6 root root 58 Aug 2 22:17 apr
drwxr-xr-x. 5 root root 43 Aug 2 22:20 apr-util
drwxr-xr-x. 2 root root 6 May 19 2020 bin
drwxr-xr-x. 2 root root 6 May 19 2020 etc
drwxr-xr-x. 2 root root 6 May 19 2020 games
drwxr-xr-x. 2 root root 6 May 19 2020 include
drwxr-xr-x. 2 root root 6 May 19 2020 lib
drwxr-xr-x. 3 root root 17 Jul 19 16:13 lib64
drwxr-xr-x. 2 root root 6 May 19 2020 libexec
drwxr-xr-x. 9 mysql mysql 129 Aug 2 23:21 mysql
drwxr-xr-x. 2 root root 6 May 19 2020 sbin
drwxr-xr-x. 5 root root 49 Jul 19 16:13 share
drwxr-xr-x. 2 root root 6 May 19 2020 src
[root@lnh local]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@lnh local]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@lnh local]# 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//添加這一行
[root@lnh local]# cd
[root@lnh ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
//配置環境變數
[root@lnh ~]# source /etc/profile.d/mysql.sh
[root@lnh ~]# which mysql
/usr/local/mysql/bin/mysql
//查找mysql
[root@lnh ~]# mkdir -p /opt/data
[root@lnh ~]# chown -R mysql.mysql /opt/data/
//建立數據存放目錄
[root@lnh ~]# mysqld --initialize --user mysql --datadir /opt/data
//初始化資料庫
2022-08-02T15:38:19.770486Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-08-02T15:38:19.958740Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-02T15:38:19.986757Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-08-02T15:38:19.992972Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 22a4ea73-1279-11ed-a567-000c2905f428.
2022-08-02T15:38:19.995310Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-08-02T15:38:20.416458Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T15:38:20.416497Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T15:38:20.417285Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-02T15:38:20.478216Z 1 [Note] A temporary password is generated for root@localhost: iBUh*ijeb45h
[root@lnh ~]# echo 'iBUh*ijeb45h' > password
[root@lnh ~]# cat password
iBUh*ijeb45h
//將臨時密碼保存到這個文件裡面
[root@lnh ~]# rpm -qa |grep mariadb
mariadb-connector-c-config-3.1.11-2.el8_3.noarch
mariadb-connector-c-3.1.11-2.el8_3.x86_64
mariadb-connector-c-devel-3.1.11-2.el8_3.x86_64
mariadb-devel-10.3.28-1.module_el8.3.0+757+d382997d.x86_64
//查找mariadb的資料庫
[root@lnh ~]# dnf -y remove mariadb*
//要卸載掉mariadb資料庫不然到時候和mysql資料庫發生衝突
[root@lnh ~]# rpm -qa |grep mariadb
[root@lnh ~]# vim /etc/my.cnf
[root@lnh ~]# 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
[root@lnh ~]# cd /usr/local/mysql/
[root@lnh mysql]# ls
bin docs include lib LICENSE man README share support-files
[root@lnh mysql]# cd support-files/
[root@lnh support-files]# ls
magic mysqld_multi.server mysql-log-rotate mysql.server
[root@lnh support-files]# file mysql.server
mysql.server: POSIX shell script, ASCII text executable
//是一個腳本文件
[root@lnh support-files]# cp mysql.server /etc/init.d/mysqld
[root@lnh support-files]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql //資料庫存放位置
datadir=/opt/data //數據存放位置
[root@lnh support-files]# chmod +x /etc/init.d/mysqld
//賦予執行許可權
[root@lnh ~]# service mysqld start //啟動服務
Starting MySQL.Logging to '/opt/data/lnh.err'.
SUCCESS!
[root@lnh ~]# ss -antl //查看埠
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@lnh ~]# chkconfig --add mysqld //設置開機自啟
[root@lnh ~]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
//在2,3,4,5下麵開機自啟了
[root@lnh ~]# systemctl stop firewalld.service
[root@lnh ~]# systemctl disable firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@lnh ~]# vim /etc/selinux/config
SELINUX=disabled
[root@lnh ~]# setenforce 0
//關閉防火牆
[root@lnh ~]# cd /usr/lib/systemd/system
[root@lnh system]# cp sshd.service mysqld.service
[root@lnh system]# vim mysqld.service
[Unit]
Description=mysqld server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.target
Wants=sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@lnh system]# cd
[root@lnh ~]# systemctl daemon-reload //重新載入
[root@lnh ~]# systemctl restart mysqld.service //重啟服務
[root@lnh ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@lnh ~]# cat password
iBUh*ijeb45h
[root@lnh ~]# mysql -uroot -p'iBUh*ijeb45h'
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 2
Server version: 5.7.38
Copyright (c) 2000, 2022, 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> set password=password('lnh123'); //修改密碼
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
[root@lnh ~]# mysql -uroot -p'lnh123'
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 3
Server version: 5.7.38 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, 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.
//密碼修改成功
3.3 安裝php
[root@lnh ~]# wget https://www.php.net/distributions/php-7.4.30.tar.xz
//在網站php.net裡面複製網址
[root@lnh ~]# ls
anaconda-ks.cfg apr-util-1.6.1.tar.gz password
apr-1.7.0 httpd-2.4.54 php-7.4.30.tar.xz
apr-1.7.0.tar.gz httpd-2.4.54.tar.gz
apr-util-1.6.1 mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@lnh ~]# sha256sum php-7.4.30.tar.xz
ea72a34f32c67e79ac2da7dfe96177f3c451c3eefae5810ba13312ed398ba70d php-7.4.30.tar.xz
//查看是否是要下載的包
[root@lnh ~]# dnf list |grep php|grep mysql
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
php-mysqlnd.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 @AppStream
//查看新的安裝包
[root@lnh ~]# dnf -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php-mysqlnd
//安裝依賴包
[root@lnh ~]# ls
anaconda-ks.cfg apr-util-1.6.1.tar.gz password
apr-1.7.0 httpd-2.4.54 php-7.4.30.tar.xz
apr-1.7.0.tar.gz httpd-2.4.54.tar.gz
apr-util-1.6.1 mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@lnh ~]# tar -xf php-7.4.30.tar.xz
//解壓
[root@lnh ~]#cd php-7.4.30/
[root@lnh php-7.4.30]# ./configure --prefix=/usr/local/php7 --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 --enable-gd --with-jpeg --with-zlib-dir --with-freetype --with-gettext --enable-json --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
.....
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
//編譯測試安裝php
[root@lnh php-7.4.30]# make
//編譯
[root@lnh php-7.4.30]# make install
//安裝
[root@lnh php-7.4.30]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
//配置環境變數
[root@lnh php-7.4.30]# source /etc/profile.d/php7.sh
[root@lnh php-7.4.30]# which php //查找php
/usr/local/php7/bin/php
[root@lnh php-7.4.30]# php -v //查看版本號
PHP 7.4.30 (cli) (built: Aug 3 2022 01:17:12) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
[root@lnh php-7.4.30]# ls
appveyor configure.ac Makefile.fragments scripts
azure CONTRIBUTING.md Makefile.objects tests
azure-pipelines.yml docs modules travis
build ext NEWS TSRM
buildconf EXTENSIONS pear UPGRADING
buildconf.bat include php.ini-development UPGRADING.INTERNALS
CODING_STANDARDS.md libs php.ini-production win32
config.log libtool README.md Zend
config.nice LICENSE README.REDIST.BINS
config.status main run-tests.php
configure Makefile sapi
[root@lnh php-7.4.30]# cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
//配置生產環境
[root@lnh php-7.4.30]# ls
appveyor configure.ac Makefile.fragments scripts
azure CONTRIBUTING.md Makefile.objects tests
azure-pipelines.yml docs modules travis
build ext NEWS TSRM
buildconf EXTENSIONS pear UPGRADING
buildconf.bat include php.ini-development UPGRADING.INTERNALS
CODING_STANDARDS.md libs php.ini-production win32
config.log libtool README.md Zend
config.nice LICENSE README.REDIST.BINS
config.status main run-tests.php
configure Makefile sapi
[root@lnh php-7.4.30]# cd sapi/
[root@lnh sapi]# ls
apache2handler cgi cli embed fpm litespeed phpdbg
[root@lnh sapi]# cd fpm/
[root@lnh fpm]# ls
config.m4 LICENSE php-fpm.conf status.html.in
CREDITS Makefile.frag php-fpm.conf.in tests
fpm php-fpm php-fpm.service www.conf
init.d.php-fpm php-fpm.8 php-fpm.service.in www.conf.in
init.d.php-fpm.in php-fpm.8.in status.html
[root@lnh fpm]# file init.d.php-fpm
init.d.php-fpm: POSIX shell script, ASCII text executable
[root@lnh fpm]# cp init.d.php-fpm /etc/init.d/php-fpm //配置php-fpm
[root@lnh fpm]# chmod +x /etc/init.d/php-fpm
//賦予執行許可權
[root@lnh ~]# service php-fpm status
php-fpm is stopped
//此時還沒有正式啟動
[root@lnh ~]# cd /usr/local/php7/
[root@lnh php7]# ls
bin etc include lib php sbin var
[root@lnh php7]# cd etc/
[root@lnh etc]# ls //查看
pear.conf php-fpm.conf.default php-fpm.d
[root@lnh etc]# cp php-fpm.conf.default php-fpm.conf
[root@lnh etc]# ls //查看複製後的文件
pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d
[root@lnh etc]# cd php-fpm.d/
[root@lnh php-fpm.d]# ls
www.conf.default
[root@lnh php-fpm.d]# cp www.conf.default www.conf
[root@lnh php-fpm.d]# ls //查看複製後的文件
www.conf www.conf.default
[root@lnh php-fpm.d]# service php-fpm start
Starting php-fpm done
//開啟服務
[root@lnh php-fpm.d]# ss -antl //查看埠
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@lnh php-fpm.d]# cd
[root@lnh ~]# chkconfig --add php-fpm //設置開機自啟
[root@lnh ~]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
//可以看見2,3,4,5,是開機自啟
[root@lnh ~]# ps -ef|grep php
root 214276 1 0 01:53 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody 214277 214276 0 01:53 ? 00:00:00 php-fpm: pool www
nobody 214278 214276 0 01:53 ? 00:00:00 php-fpm: pool www
root 214325 51892 0 01:56 pts/0 00:00:00 grep --color=auto php
//查看進程
報錯解決
報錯1:
[root@lnh ~]# mysql -uroot -p'iBUh*ijeb45h'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
解決:
[root@lnh ~]# dnf provides libncurses.so.5
Last metadata expiration check: 0:14:32 ago on Tue 02 Aug 2022 11:53:43 PM CST.
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
Repo : base
Matched from:
Provide : libncurses.so.5
[root@lnh ~]# dnf -y install ncurses-compat-libs
報錯2:
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
Package 'sqlite3', required by 'virtual:world', not found
解決:
root@lnh php-7.4.30]# dnf list |grep sqlite3
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
libsqlite3x.x86_64 20071018-26.el8 epel
libsqlite3x-devel.x86_64 20071018-26.el8 epel
preludedb-sqlite3.x86_64 5.2.0-1.el8 epel
rubygem-sqlite3.x86_64 1.4.2-2.el8 epel
rubygem-sqlite3-doc.noarch 1.4.2-2.el8 epel
soci-sqlite3.x86_64 4.0.0-2.el8 epel
soci-sqlite3-devel.x86_64 4.0.0-2.el8 epel
uwsgi-plugin-sqlite3.x86_64 2.0.20-1.el8 epel
zabbix-dbfiles-sqlite3.noarch 6.0.2-1.module_el8+14182+e1fc92db epel-modular
zabbix-proxy-sqlite3.x86_64 6.0.2-1.module_el8+14182+e1fc92db epel-modular
zabbix40-dbfiles-sqlite3.noarch 4.0.39-1.el8 epel
zabbix40-proxy-sqlite3.x86_64 4.0.39-1.el8 epel
//查找系統中的安裝包,選擇第二個
[root@lnh php-7.4.30]# dnf -y install libsqlite3x-devel
報錯3:
configure: error: Package requirements (oniguruma) were not met:
Package 'oniguruma', required by 'virtual:world', not found
解決:
[root@lnh php-7.4.30]# dnf list all|grep oniguruma
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
oniguruma.i686 6.8.2-2.el8 AppStream
oniguruma.x86_64 6.8.2-2.el8 AppStream
//在系統中查找的不是這個安裝包
https://pkgs.org/ 在這個網站裡面查找
oniguruma-devel
[root@lnh php-7.4.30]# dnf -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
報錯4:
configure: WARNING: unrecognized options: --with-gd, --with-jpeg-dir, --with-png-dir, --with-freetype-dir, --enable-zip
解決:
[root@lnh php-7.4.30]# ./configure --help|grep gd
--with-gdbm[=DIR] DBA: GDBM support
--enable-gd (新的) Include GD support
--with-external-gd Use external libgd
--with-webp GD: Enable WEBP support (only for bundled libgd)
--with-jpeg GD: Enable JPEG support (only for bundled libgd)
--with-xpm GD: Enable XPM support (only for bundled libgd)
libgd)
--enable-gd-jis-conv GD: Enable JIS-mapped Japanese font support (only
for bundled libgd)
[root@lnh php-7.4.30]# ./configure --help|grep jpeg
--with-jpeg GD: Enable JPEG support (only for bundled libgd)
[root@lnh php-7.4.30]# ./configure --help|grep png
[root@lnh php-7.4.30]#
[root@lnh php-7.4.30]# ./configure --help|grep freetype
--with-freetype GD: Enable FreeType 2 support (only for bundled
[root@lnh php-7.4.30]# ./configure --help|grep zip
--with-zip Include Zip read/write support
報錯5:
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
Package 'libzip', required by 'virtual:world', not found
Package 'libzip', required by 'virtual:world', not found
Package 'libzip', required by 'virtual:world', not found
解決:
[root@lnh ~]# dnf list all|grep zip|grep lib //在系統中查找
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
bzip2-libs.i686 1.0.6-26.el8 @base
bzip2-libs.x86_64 1.0.6-26.el8 @anaconda
libzip.x86_64 1.5.1-2.module_el8.2.0+313+b04d0a66 AppStream
libzip-devel.x86_64 1.5.1-2.module_el8.2.0+313+b04d0a66 AppStream
libzip-tools.x86_64 1.5.1-2.module_el8.2.0+313+b04d0a66 AppStream
zziplib.i686 0.13.68-9.el8 AppStream
zziplib.x86_64 0.13.68-9.el8 AppStream
zziplib-utils.x86_64 0.13.68-9.el8 AppStream
[root@lnh ~]# dnf -y install libzip-devel