LAMP搭建

LAMP搭建

APACHE安装与配置

从apache网站上安装apr-1.7.4.tar.gz,apr-util-1.6.3.tar.gz,httpd-2.4.58.tar.gz

[root@localhost ~]# yum -y install wget
Warning: failed loading '/etc/yum.repos.d/xhx.repo', skipping.
Rocky Linux 9 - BaseOS                              2.7 kB/s | 4.1 kB     00:01    
Rocky Linux 9 - AppStream                           2.9 kB/s | 4.5 kB     00:01    
Rocky Linux 9 - Extras                              1.7 kB/s | 2.9 kB     00:01    
Package wget-1.21.1-7.el9.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.7.4.tar.gz
--2023-12-11 14:27:09--  https://downloads.apache.org/apr/apr-1.7.4.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 135.181.214.104, 2a01:4f8:10a:201a::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1122147 (1.1M) [application/x-gzip]
Saving to: ‘apr-1.7.4.tar.gz’

apr-1.7.4.tar.gz     100%[======================>]   1.07M   484KB/s    in 2.3s    

2023-12-11 14:27:12 (484 KB/s) - ‘apr-1.7.4.tar.gz’ saved [1122147/1122147]
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-util-1.6.3.tar.gz
--2023-12-11 14:28:34--  https://downloads.apache.org/apr/apr-util-1.6.3.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 135.181.214.104, 88.99.95.219, 2a01:4f9:3a:2c57::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|135.181.214.104|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 556623 (544K) [application/x-gzip]
Saving to: ‘apr-util-1.6.3.tar.gz’

apr-util-1.6.3.tar.g 100%[======================>] 543.58K   515KB/s    in 1.1s    

2023-12-11 14:28:36 (515 KB/s) - ‘apr-util-1.6.3.tar.gz’ saved [556623/556623]
[root@localhost ~]# wget https://downloads.apache.org/httpd/httpd-2.4.58.tar.gz
--2023-12-11 14:30:16--  https://downloads.apache.org/httpd/httpd-2.4.58.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 135.181.214.104, 88.99.95.219, 2a01:4f8:10a:201a::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|135.181.214.104|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9825177 (9.4M) [application/x-gzip]
Saving to: ‘httpd-2.4.58.tar.gz’

httpd-2.4.58.tar.gz  100%[======================>]   9.37M  2.43MB/s    in 4.6s    

2023-12-11 14:30:22 (2.04 MB/s) - ‘httpd-2.4.58.tar.gz’ saved [9825177/9825177]

创建apache用户

[root@localhost ~]# useradd -r -M -s /sbin/nologin apache

安装必要软件包

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

解压下载的软件包

[root@localhost ~]# ls
anaconda-ks.cfg        Desktop    httpd-2.4.58.tar.gz  Public
apr-1.7.4.tar.gz       Documents  Music                Templates
apr-util-1.6.3.tar.gz  Downloads  Pictures             Videos
[root@localhost ~]# tar xf apr-1.7.4.tar.gz 
[root@localhost ~]# tar xf apr-util-1.6.3.tar.gz 
[root@localhost ~]# tar xf httpd-2.4.58.tar.gz 

编辑apr文件

[root@localhost ~]# cd apr-1.7.4/
[root@localhost apr-1.7.4]# vim configure
    cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    $RM "$cfgfile"   去掉此行或者注释

配置编译环境,并编译

[root@localhost apr-1.7.4]# ./configure --prefix=/usr/local/apr  //编译apr
[root@localhost apr-1.7.4]# make
[root@localhost apr-1.7.4]# make install
make[1]: Entering directory '/root/apr-1.7.4'
make[1]: Nothing to be done for 'local-all'.
make[1]: Leaving directory '/root/apr-1.7.4'
/root/apr-1.7.4/build/mkdir.sh /usr/local/apr/lib /usr/local/apr/bin /usr/local/apr/build-1 \
             /usr/local/apr/lib/pkgconfig /usr/local/apr/include/apr-1
/usr/bin/install -c -m 644 /root/apr-1.7.4/include/apr.h /usr/local/apr/include/apr-1
for f in /root/apr-1.7.4/include/apr_*.h; do \
    /usr/bin/install -c -m 644 ${f} /usr/local/apr/include/apr-1; \
done
/bin/sh /root/apr-1.7.4/libtool --mode=install /usr/bin/install -c -m 755 libapr-1.la /usr/local/apr/lib
libtool: install: /usr/bin/install -c -m 755 .libs/libapr-1.so.0.7.4 /usr/local/apr/lib/libapr-1.so.0.7.4
libtool: install: (cd /usr/local/apr/lib && { ln -s -f libapr-1.so.0.7.4 libapr-1.so.0 || { rm -f libapr-1.so.0 && ln -s libapr-1.so.0.7.4 libapr-1.so.0; }; })
libtool: install: (cd /usr/local/apr/lib && { ln -s -f libapr-1.so.0.7.4 libapr-1.so || { rm -f libapr-1.so && ln -s libapr-1.so.0.7.4 libapr-1.so; }; })
libtool: install: /usr/bin/install -c -m 755 .libs/libapr-1.lai /usr/local/apr/lib/libapr-1.la
libtool: install: /usr/bin/install -c -m 755 .libs/libapr-1.a /usr/local/apr/lib/libapr-1.a
libtool: install: chmod 644 /usr/local/apr/lib/libapr-1.a
libtool: install: ranlib /usr/local/apr/lib/libapr-1.a
libtool: finish: PATH="/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin" ldconfig -n /usr/local/apr/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/apr/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the 'LD_RUN_PATH' environment variable
     during linking
   - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/install -c -m 644 apr.exp /usr/local/apr/lib/apr.exp
/usr/bin/install -c -m 644 apr.pc /usr/local/apr/lib/pkgconfig/apr-1.pc
for f in libtool shlibtool; do \
    if test -f ${f}; then /usr/bin/install -c -m 755 ${f} /usr/local/apr/build-1; fi; \
done
/usr/bin/install -c -m 755 /root/apr-1.7.4/build/mkdir.sh /usr/local/apr/build-1
for f in make_exports.awk make_var_export.awk; do \
    /usr/bin/install -c -m 644 /root/apr-1.7.4/build/${f} /usr/local/apr/build-1; \
done
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config

[root@localhost apr-util-1.6.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr       //编译apr-util
[root@localhost apr-util-1.6.3]# make
[root@localhost apr-util-1.6.3]# make install
make[1]: Entering directory '/root/apr-util-1.6.3'
make[1]: Nothing to be done for 'local-all'.
make[1]: Leaving directory '/root/apr-util-1.6.3'
/usr/local/apr/build-1/mkdir.sh /usr/local/apr-util/include/apr-1 /usr/local/apr-util/lib/pkgconfig \
             /usr/local/apr-util/lib /usr/local/apr-util/bin
for f in /root/apr-util-1.6.3/include/*.h /root/apr-util-1.6.3/include/*.h; do \
        /usr/bin/install -c -m 644 ${f} /usr/local/apr-util/include/apr-1; \
done
/usr/bin/install -c -m 644 apr-util.pc /usr/local/apr-util/lib/pkgconfig/apr-util-1.pc
list=''; for i in $list; do \
        ( cd $i ; make DESTDIR= install ); \
done
/bin/sh /usr/local/apr/build-1/libtool --mode=install /usr/bin/install -c -m 755 libaprutil-1.la /usr/local/apr-util/lib
libtool: install: /usr/bin/install -c -m 755 .libs/libaprutil-1.so.0.6.3 /usr/local/apr-util/lib/libaprutil-1.so.0.6.3
libtool: install: (cd /usr/local/apr-util/lib && { ln -s -f libaprutil-1.so.0.6.3 libaprutil-1.so.0 || { rm -f libaprutil-1.so.0 && ln -s libaprutil-1.so.0.6.3 libaprutil-1.so.0; }; })
libtool: install: (cd /usr/local/apr-util/lib && { ln -s -f libaprutil-1.so.0.6.3 libaprutil-1.so || { rm -f libaprutil-1.so && ln -s libaprutil-1.so.0.6.3 libaprutil-1.so; }; })
libtool: install: /usr/bin/install -c -m 755 .libs/libaprutil-1.lai /usr/local/apr-util/lib/libaprutil-1.la
libtool: install: /usr/bin/install -c -m 755 .libs/libaprutil-1.a /usr/local/apr-util/lib/libaprutil-1.a
libtool: install: chmod 644 /usr/local/apr-util/lib/libaprutil-1.a
libtool: install: ranlib /usr/local/apr-util/lib/libaprutil-1.a
libtool: finish: PATH="/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin" ldconfig -n /usr/local/apr-util/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/apr-util/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the 'LD_RUN_PATH' environment variable
     during linking
   - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config
[root@localhost httpd-2.4.58]# ./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                          //编译apache
[root@localhost httpd-2.4.58]# make
[root@localhost httpd-2.4.58]# make install
[root@localhost httpd-2.4.58]# ls /usr/local
apache  apr-util  etc    include  lib64    sbin   src
apr     bin       games  lib      libexec  share     //显示有apache,apr,apr-util就是成功了

配置环境变量

[root@localhost httpd-2.4.58]# ls /usr/local/apache/
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules
[root@localhost httpd-2.4.58]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh    //配置环境变量
[root@localhost httpd-2.4.58]# ln -s /usr/local/apache/include /usr/include/httpd  //将include文件做软连接
[root@localhost httpd-2.4.58]# vim /etc/man_db.conf    //编写帮助文档,让系统找到apache在哪
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man
[root@localhost httpd-2.4.58]# source /etc/profile.d/httpd.sh   //使文件生效

启动apache

[root@localhost httpd-2.4.58]# apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[root@localhost httpd-2.4.58]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port       Peer Address:Port   Process   
LISTEN   0        4096           127.0.0.1:631             0.0.0.0:*                
LISTEN   0        128              0.0.0.0:22              0.0.0.0:*                
LISTEN   0        511                    *:80                    *:*                
LISTEN   0        128                 [::]:22                 [::]:*                
LISTEN   0        4096               [::1]:631                [::]:*                

关闭防火墙与selinux

[root@localhost httpd-2.4.58]# systemctl disable --now firewalld
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".
[root@localhost httpd-2.4.58]# setenforce 0
[root@localhost httpd-2.4.58]# vim /etc/selinux/config 
SELINUX=disabled

设置开机自启

[root@localhost httpd-2.4.58]# apachectl stop
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[root@localhost httpd-2.4.58]# vim /usr/local/apache/conf/httpd.conf 
ServerName www.example.com:80  //去掉此行注释符
[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/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

[root@localhost ~]# systemctl daemon-reload    //新加载
[root@localhost ~]# systemctl enable --now httpd  //设置开机自启动并立刻启动
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl status httpd  //查看httpd状态
● httpd.service - httpd server daemon
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: disabl>
     Active: active (running) since Mon 2023-12-11 15:49:52 CST; 20s ago
    Process: 51234 ExecStart=/usr/local/apache/bin/apachectl start (code=exited, st>
   Main PID: 51237 (httpd)
      Tasks: 6 (limit: 11913)
     Memory: 5.3M
        CPU: 93ms
     CGroup: /system.slice/httpd.service
             ├─51237 /usr/local/apache/bin/httpd -k start
             ├─51238 /usr/local/apache/bin/httpd -k start
             ├─51239 /usr/local/apache/bin/httpd -k start
             ├─51240 /usr/local/apache/bin/httpd -k start
             ├─51241 /usr/local/apache/bin/httpd -k start
             └─51242 /usr/local/apache/bin/httpd -k start

Dec 11 15:49:52 localhost.localdomain systemd[1]: Starting httpd server daemon...
Dec 11 15:49:52 localhost.localdomain systemd[1]: Started httpd server daemon.
lines 1-18/18 (END)
安装MYSQL
[root@localhost ~]# yum -y install epel-release  //安装一个通用的源
[root@localhost ~]# yum -y install https://mirror.stream.centos.org/9-stream/CRB/x86_64/os/Packages/mariadb-devel-10.5.16-2.el9.x86_64.rpm  //从网上下载的软件包
Warning: failed loading '/etc/yum.repos.d/xhx.repo', skipping.
Extra Packages for Enterprise Linux 9 - x86_64      5.3 MB/s |  20 MB     00:03    
Extra Packages for Enterprise Linux 9 openh264 (Fro 877  B/s | 2.5 kB     00:02    
mariadb-devel-10.5.16-2.el9.x86_64.rpm              192 kB/s | 1.1 MB     00:05    
Dependencies resolved.
====================================================================================
 Package                       Arch      Version              Repository       Size
====================================================================================
Installing:
 mariadb-devel                 x86_64    3:10.5.16-2.el9      @commandline    1.1 M
Installing dependencies:
 mariadb-connector-c           x86_64    3.2.6-1.el9_0        appstream       195 k
 mariadb-connector-c-config    noarch    3.2.6-1.el9_0        appstream       9.8 k
 mariadb-connector-c-devel     x86_64    3.2.6-1.el9_0        appstream        55 k

Transaction Summary
====================================================================================
Install  4 Packages

Total size: 1.3 M
Total download size: 260 k
Installed size: 6.0 M
Downloading Packages:
(1/3): mariadb-connector-c-config-3.2.6-1.el9_0.noa  93 kB/s | 9.8 kB     00:00    
(2/3): mariadb-connector-c-devel-3.2.6-1.el9_0.x86_ 274 kB/s |  55 kB     00:00    
(3/3): mariadb-connector-c-3.2.6-1.el9_0.x86_64.rpm 767 kB/s | 195 kB     00:00    
------------------------------------------------------------------------------------
Total                                               157 kB/s | 260 kB     00:01     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                            1/1 
  Installing       : mariadb-connector-c-config-3.2.6-1.el9_0.noarch            1/4 
  Installing       : mariadb-connector-c-3.2.6-1.el9_0.x86_64                   2/4 
  Installing       : mariadb-connector-c-devel-3.2.6-1.el9_0.x86_64             3/4 
  Installing       : mariadb-devel-3:10.5.16-2.el9.x86_64                       4/4 
  Running scriptlet: mariadb-devel-3:10.5.16-2.el9.x86_64                       4/4 
  Verifying        : mariadb-connector-c-devel-3.2.6-1.el9_0.x86_64             1/4 
  Verifying        : mariadb-connector-c-3.2.6-1.el9_0.x86_64                   2/4 
  Verifying        : mariadb-connector-c-config-3.2.6-1.el9_0.noarch            3/4 
  Verifying        : mariadb-devel-3:10.5.16-2.el9.x86_64                       4/4 

Installed:
  mariadb-connector-c-3.2.6-1.el9_0.x86_64                                          
  mariadb-connector-c-config-3.2.6-1.el9_0.noarch                                   
  mariadb-connector-c-devel-3.2.6-1.el9_0.x86_64                                    
  mariadb-devel-3:10.5.16-2.el9.x86_64                                              

Complete!
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake 继续下载所需的软件包

解压软件包

[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql   //创建mysql系统用户
[root@localhost ~]# tar xf mysql-8.0.35-linux-glibc2.28-x86_64.tar.xz -C /usr/local //解压软件包
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mv mysql-8.0.35-linux-glibc2.28-x86_64/ mysql  //更改名字
[root@localhost local]# chown -R mysql.mysql mysql   //设置mysql的所属组与所属者
[root@localhost local]# ll
total 0
drwxr-xr-x. 14 root  root  164 Dec 11 15:25 apache
drwxr-xr-x.  6 root  root   58 Dec 11 15:06 apr
drwxr-xr-x.  5 root  root   43 Dec 11 15:13 apr-util
drwxr-xr-x.  2 root  root    6 May 16  2022 bin
drwxr-xr-x.  2 root  root    6 May 16  2022 etc
drwxr-xr-x.  2 root  root    6 May 16  2022 games
drwxr-xr-x.  2 root  root    6 May 16  2022 include
drwxr-xr-x.  2 root  root    6 May 16  2022 lib
drwxr-xr-x.  3 root  root   17 Dec  4 18:09 lib64
drwxr-xr-x.  2 root  root    6 May 16  2022 libexec
drwxr-xr-x.  9 mysql mysql 129 Dec 11 16:29 mysql
drwxr-xr-x.  2 root  root    6 May 16  2022 sbin
drwxr-xr-x.  5 root  root   49 Dec  4 18:09 share
drwxr-xr-x.  2 root  root    6 May 16  2022 src

配置环境变量

[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh   //配置环境变量
[root@localhost local]# source /etc/profile.d/mysql.sh   //使配置生效
[root@localhost local]# mkdir /opt/data   //创建mysql数据目录
[root@localhost local]# chown -R mysql.mysql /opt/data   //更改data的所属组与所属者

初始化

[root@localhost local]# mysqld --initialize --user mysql --datadir /opt/data
2023-12-11T08:39:18.653499Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.35) initializing of server in progress as process 55107
2023-12-11T08:39:18.720906Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-12-11T08:39:19.416218Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-12-11T08:39:25.518004Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: jSiaD.OIV1rh     //jSiaD.OIV1rh 为mysql一次性密码 需保存

编辑配置文件

[root@localhost local]# vim /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@localhost local]# ls /usr/local/mysql/
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost local]# ln -s /usr/local/mysql/include/ /usr/include/mysql  //做软连接
[root@localhost local]# vim /etc/ld.so.conf.d/mysql.conf   //让系统找到库文件
/usr/local/mysql/lib
[root@localhost local]# ldconfig -v   //测试能不能找到库文件
/usr/local/mysql/lib: (from /etc/ld.so.conf.d/mysql.conf:1)
        libmysqlclient.so.21 -> libmysqlclient.so.21.2.35  //能找到就可以了

编写帮助文档

[root@localhost local]# ls /usr/local/mysql/
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost 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@localhost local]# vim /usr/local/mysql/support-files/mysql.server  //编写脚本文件
basedir=/usr/local/mysql
datadir=/opt/data
[root@localhost local]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
.. SUCCESS! 

编写mysql配置文件

[root@localhost local]# cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/mysqld.service  //复制配置文件
[root@localhost local]# vim /usr/lib/systemd/system/mysqld.service  /修改配置文件
[Unit]
Description=mysqld 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/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl daemon-reload  //刷新配置文件
[root@localhost ~]# systemctl enable --now mysqld  //设置开机自启并立刻启动服务
[root@localhost ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disable>
     Active: active (running) since Mon 2023-12-11 17:08:42 CST; 1min 18s ago
    Process: 958 ExecStart=/usr/local/mysql/support-files/mysql.server start (code=ex>
   Main PID: 1007 (mysqld_safe)
      Tasks: 38 (limit: 11913)
     Memory: 446.2M
        CPU: 3.214s
     CGroup: /system.slice/mysqld.service
             ├─1007 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pi>
             └─1292 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=>

Dec 11 17:08:37 localhost.localdomain systemd[1]: Starting mysqld server daemon...
Dec 11 17:08:42 localhost.localdomain mysql.server[958]: Starting MySQL.... SUCCESS!
Dec 11 17:08:42 localhost.localdomain systemd[1]: Started mysqld server daemon.

更改mysql密码

[root@localhost ~]# mysql -uroot -p'jSiaD.OIV1rh'   //使用一次性密码进入
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 8
Server version: 8.0.35

Copyright (c) 2000, 2023, 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> alter user root@'localhost' identified with mysql_native_password by 'Passw0rd@_'; //更改密码
Query OK, 0 rows affected (0.01 sec)       

mysql> quit
Bye
安装PHP
[root@localhost ~]# wget https://www.php.net/distributions/php-8.3.0.tar.xz //下载php软件包
--2023-12-11 17:21:59--  https://www.php.net/distributions/php-8.3.0.tar.xz
Resolving www.php.net (www.php.net)... 185.85.0.29, 2a02:cb40:200::1ad
Connecting to www.php.net (www.php.net)|185.85.0.29|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12431612 (12M) [application/octet-stream]
Saving to: ‘php-8.3.0.tar.xz’

php-8.3.0.tar.xz      100%[=======================>]  11.86M  1.21MB/s    in 12s     

2023-12-11 17:22:12 (1.02 MB/s) - ‘php-8.3.0.tar.xz’ saved [12431612/12431612]

[root@localhost ~]# tar xf php-8.3.0.tar.xz   //解压
[root@localhost ~]# cd php-8.3.0/  切换到php目录

安装必要软件包

[root@localhost php-8.3.0]# yum -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@localhost php-8.3.0]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
epel-cisco-openh264.repo  epel-testing.repo  rocky-devel.repo   rocky.repo
epel.repo                 rocky-addons.repo  rocky-extras.repo
[root@localhost yum.repos.d]# vim rocky-devel.repo
# rocky-devel.repo
#
# devel and no-package-left-behind

[devel]
name=Rocky Linux $releasever - Devel WARNING! FOR BUILDROOT ONLY DO NOT LEAVE ENABLED
mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=devel-$releasever$rltype
#baseurl=http://dl.rockylinux.org/$contentdir/$releasever/devel/$basearch/os/
gpgcheck=1
enabled=1    //把0修改为1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
[root@localhost php-8.3.0]# yum -y install libsqlite3x-devel oniguruma-devel libzip-devel oniguruma-devel
 //安装必要软件包

配置编译文件 .configure

[root@localhost php-8.3.0]# 
./configure --prefix=/usr/local/php7  \
--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

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

报错解决

./configure --help | grep 报错的软件包名

编译PHP

[root@localhost php-8.3.0]# make -j2
[root@localhost php-8.3.0]# make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-non-zts-20230831/
Installing PHP CLI binary:        /usr/local/php7/bin/
Installing PHP CLI man page:      /usr/local/php7/php/man/man1/
Installing PHP FPM binary:        /usr/local/php7/sbin/
Installing PHP FPM defconfig:     /usr/local/php7/etc/
Installing PHP FPM man page:      /usr/local/php7/php/man/man8/
Installing PHP FPM status page:   /usr/local/php7/php/php/fpm/
Installing phpdbg binary:         /usr/local/php7/bin/
Installing phpdbg man page:       /usr/local/php7/php/man/man1/
Installing PHP CGI binary:        /usr/local/php7/bin/
Installing PHP CGI man page:      /usr/local/php7/php/man/man1/
Installing build environment:     /usr/local/php7/lib/php/build/
Installing header files:          /usr/local/php7/include/php/
Installing helper programs:       /usr/local/php7/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php7/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php7/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.14
[PEAR] Console_Getopt - installed: 1.4.3
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.5
warning: pear/PEAR dependency package "pear/Archive_Tar" installed version 1.4.14 is not the recommended version 1.4.4
[PEAR] PEAR           - installed: 1.10.13
Wrote PEAR system config file at: /usr/local/php7/etc/pear.conf
You may want to add: /usr/local/php7/lib/php to your php.ini include_path
Installing PDO headers:           /usr/local/php7/include/php/ext/pdo/

配置环境变量

[root@localhost php-8.3.0]# ls /usr/local/php7/
bin etc include lib php sbin var
[root@localhost php-8.3.0]# echo 'export
PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH' > /etc/profile.d/php.sh
[root@localhost php-8.3.0]# source /etc/profile.d/php.sh
[root@localhost php-8.3.0]# ln -s /usr/local/php7/include/ /usr/include/php
[root@localhost php-8.3.0]# vim /etc/ld.so.conf.d/php.conf
/usr/localphp8/lib
[root@localhost php-8.3.0]# ldconfig -v
[root@localhost php-8.3.0]# which php
/usr/local/php7/bin/php
[root@localhost php-8.3.0]# php -v
PHP 8.3.0 (cli) (built: Dec 11 2023 04:11:34) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.0, Copyright (c) Zend Technologies
[root@localhost php-8.3.0]#

配置php-fpm

[root@localhost php-8.3.0]# cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
[root@localhost php-8.3.0]# mkdir /etc/init.d
[root@localhost php-8.3.0]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-8.3.0]# chmod +x /etc/init.d/php-fpm
[root@localhost php-8.3.0]# mv /usr/local/php7 /usr/local/php8
[root@localhost php-8.3.0]# cd /usr/local/php8/etc/
[root@localhost etc]# ls
pear.conf php-fpm.conf.default php-fpm.d
[root@localhost etc]#
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# ls
www.conf.default
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# ls
www.conf www.conf.default
[root@localhost php-fpm.d]# cd

启动php-fpm
[root@localhost ~]# service php-fpm start
Starting php-fpm  done
[root@localhost ~]# 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               4096                         127.0.0.1:9000                         0.0.0.0:*                            
LISTEN         0               4096                         127.0.0.1:631                          0.0.0.0:*                            
LISTEN         0               128                          127.0.0.1:6011                         0.0.0.0:*                            
LISTEN         0               151                                  *:3306                               *:*                            
LISTEN         0               511                                  *:80                                 *:*                            
LISTEN         0               128                               [::]:22                              [::]:*                            
LISTEN         0               70                                   *:33060                              *:*                            
LISTEN         0               128                              [::1]:6011                            [::]:*                            
LISTEN         0               4096                             [::1]:631                             [::]:*                            

开机自启

[root@localhost ~]# cp /usr/lib/systemd/system/sshd.service  /usr/lib/systemd/system/php-fpm.service
[root@localhost ~]# vim /usr/lib/systemd/system/php-fpm.service 

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

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

[Install]
WantedBy=multi-user.target


[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl status php-fpm
○ php-fpm.service - php server daemon
     Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; preset: disabled)
     Active: inactive (dead)

Dec 11 05:00:12 localhost.localdomain systemd[1]: php-fpm.service: Service has more than one ExecStart= setting, which is only allowed >

[root@localhost ~]# systemctl enable --now php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@localhost ~]# 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               4096                         127.0.0.1:9000                         0.0.0.0:*                            
LISTEN         0               4096                         127.0.0.1:631                          0.0.0.0:*                            
LISTEN         0               128                          127.0.0.1:6011                         0.0.0.0:*                            
LISTEN         0               151                                  *:3306                               *:*                            
LISTEN         0               511                                  *:80                                 *:*                            
LISTEN         0               128                               [::]:22                              [::]:*                            
LISTEN         0               70                                   *:33060                              *:*                            
LISTEN         0               128                              [::1]:6011                            [::]:*                            
LISTEN         0               4096                             [::1]:631                             [::]:*                            
[root@localhost ~]# systemctl status php-fpm
● php-fpm.service - php server daemon
     Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; preset: disabled)
     Active: active (running) since Mon 2023-12-11 05:01:43 EST; 18s ago
    Process: 237282 ExecStart=service php-fpm start (code=exited, status=0/SUCCESS)
   Main PID: 237288 (php-fpm)
      Tasks: 3 (limit: 48510)
     Memory: 7.2M
        CPU: 43ms
     CGroup: /system.slice/php-fpm.service
             ├─237288 "php-fpm: master process (/usr/local/php8/etc/php-fpm.conf)"
             ├─237289 "php-fpm: pool www"
             └─237290 "php-fpm: pool www"

Dec 11 05:01:43 localhost.localdomain systemd[1]: Starting php server daemon...
Dec 11 05:01:43 localhost.localdomain service[237286]: Starting php-fpm  done
Dec 11 05:01:43 localhost.localdomain systemd[1]: Started php server daemon.

编辑httpd.conf文件 取消LoadModule proxy_module modules/mod_proxy.so和modules/mod_proxy_fcgi.so的 注释

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 
#LoadModule remoteip_module modules/mod_remoteip.so
LoadModule proxy_module modules/mod_proxy.so 
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
#LoadModule proxy_scgi_module modules/mod_proxy_scgi.so

测试页面

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 
[root@localhost ~]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# mkdir test
[root@localhost htdocs]# cd test
[root@localhost test]# vim index.php
<?php
   phpinfo();
?>

配置虚拟主机

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
Include conf/extra/vhosts.conf   //在此添加
# Local access to the Apache HTTP Server Manual


[root@localhost ~]# cd /usr/local/apache/conf/extra/
[root@localhost extra]# vim vhosts.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/test"
    ServerName www.ysy.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test/$1
    <Directory "/usr/local/apache/htdocs/test">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost> 

编辑httpd.conf文件

[root@localhost extra]# cd ..
[root@localhost conf]# vim httpd.conf 
[root@localhost conf]# pwd
/usr/local/apache/conf
[root@localhost conf]# 

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps   
//添加index.php 
index.php放在index.html后面需要加php后缀才可以访问
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

重启服务

[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart php-fpm
[root@localhost ~]# 

[root@localhost ~]# 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               4096                         127.0.0.1:9000                         0.0.0.0:*                            
LISTEN         0               4096                         127.0.0.1:631                          0.0.0.0:*                            
LISTEN         0               128                          127.0.0.1:6011                         0.0.0.0:*                            
LISTEN         0               128                          127.0.0.1:6010                         0.0.0.0:*                            
LISTEN         0               151                                  *:3306                               *:*                            
LISTEN         0               511                                  *:80                                 *:*                            
LISTEN         0               128                               [::]:22                              [::]:*                            
LISTEN         0               70                                   *:33060                              *:*                            
LISTEN         0               128                              [::1]:6011                            [::]:*                            
LISTEN         0               128                              [::1]:6010                            [::]:*                            
LISTEN         0               4096                             [::1]:631                             [::]:*                            

用IP/index.php地址访问网页

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值