LAMP

1 编译安装apache

准备工作,提前安装好依赖包以及make,vim,wget

复制代码
[root@localhost ~]# yum -y groups mark install "Development Tools"
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache  # 创建用户
[root@localhost ~]# id apache
uid=994(apache) gid=991(apache) groups=991(apache)
[root@localhost ~]# yum -y install gcc gcc-c++ make wget vim
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool //安装依赖包
[root@localhost ~]# ls
anaconda-ks.cfg            httpd-2.4.54.tar.gz       apr-util-1.6.1.tar.gz   # 把安装包拉进来
apr-1.7.0.tar.gz           
复制代码

编译安装apache

复制代码
[root@localhost ~]# tar -xf apr-1.7.0.tar.gz   #解压3个包
[root@localhost ~]# tar -xf apr-util-1.6.1.tar.gz 
[root@localhost ~]# tar -xf httpd-2.4.54.tar.gz 
[root@localhost ~]# 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

#编译安装apr
[root@localhost ~]# cd apr-1.7.0 
[root@localhost apr-1.7.0]# vi configure  # 编辑这个文件

     $RM "$cfgfile"   #删除这一行或者添加注释

[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make
[root@localhost apr-1.7.0]# make install
复制代码
编译安装apr-util
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
[root@localhost apr-util-1.6.1]# make
[root@localhost apr-util-1.6.1]# make install
复制代码
编译安装httpd
[root@lch ~]# cd httpd-2.4.54  
[root@localhost 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
[root@localhost httpd-2.4.54]# make 
[root@localhost httpd
-2.4.54]#make install
复制代码

设置环境变量,头文件,man文档

[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh  # 设置环境变量
[root@localhost ~]# source /etc/profile.d/httpd.sh  #读取一下
[root@localhost ~]# which httpd   #此时已经能找到
/usr/local/apache/bin/httpd
[root@localhost ~]# ln -s /usr/local/apache/include /usr/include/apache  #做给软连接
[root@localhost ~]# vim /etc/man_db.conf  #设置man文档
MANDATORY_MANPATH                       /usr/local/apache/man #添加这行

设置开机自

复制代码
[root@localhost ~]# cd /usr/lib/systemd/system #进到这个目录
[root@localhost system]# cp sshd.service httpd.service #复制一份
[root@localhost system]# vim httpd.service  # 编辑
[Unit]
Description=httpd server daemon
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@localhost system]# systemctl daemon-reload  #读一下
[root@localhost system]# systemctl status httpd  # 查看状态
● httpd.service - httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor pre>
   Active: inactive (dead)
[root@localhost system]# cd
[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 ~]# 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@localhost ~]# 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 ~]# vim /etc/selinux/config #永久零时关闭selinux
[root@localhost ~]# setenforce 0
复制代码

 

2.二进制安装mysql

准备工作下载依赖包,创建系统用户,解压。

复制代码
[root@localhost ~]# dnf -y install ncurses-devel openssl-devel openssl cmake mariadb-devel# 安装依赖包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz  # 把包拉进来
[root@localhost src]# useradd -r -M -s /sbin/nologin mysql # 创建一个系统用户
[root@localhost src]# id mysql
uid=991(mysql) gid=988(mysql) 组=988(mysql)
[root@localhost src]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/  # 解压到usr/local/

复制代码

 

复制代码
[root@localhost src]# cd /usr/local/
[root@localhost local]# ls
bin  games    lib    libexec                              sbin   src
etc  include  lib64  mysql-5.7.37-linux-glibc2.12-x86_64  share
[root@localhost local]# mv mysql-5.7.37-linux-glibc2.12-x86_64 mysql
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src
[root@localhost local]# ll
total 0
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 Mar  2 09:28 lib64
drwxr-xr-x. 2 root root   6 May 19  2020 libexec
drwxr-xr-x. 9 root root 129 Jun 28 13:46 mysql
drwxr-xr-x. 2 root root   6 May 19  2020 sbin
drwxr-xr-x. 5 root root  49 Mar  2 09:28 share
drwxr-xr-x. 2 root root   6 May 19  2020 src
[root@localhost local]# chown -R mysql.mysql mysql #修改目录/usr/local/mysql的属主属组
[root@localhost local]# ll
total 0
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 Mar  2 09:28 lib64
drwxr-xr-x. 2 root  root    6 May 19  2020 libexec
drwxr-xr-x. 9 mysql mysql 129 Jun 28 13:46 mysql
drwxr-xr-x. 2 root  root    6 May 19  2020 sbin
drwxr-xr-x. 5 root  root   49 Mar  2 09:28 share
drwxr-xr-x. 2 root  root    6 May 19  2020 src
复制代码

设置环境变量,头文件,man文档等

 

复制代码
设置环境变量,能够找到它
[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]# which mysql  #此时就可以找到它
/usr/local/mysql/bin/mysql
 设置include
[root@localhost mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@localhost mysql]# vi /etc/ld.so.conf.d/mysql.conf

/usr/local/mysql/lib   #  告诉路径
[root@localhost mysql]# ldconfig   #执行一下读取配置文件

man文档
[root@localhost mysql]# vi /etc/man_db.conf   #  加入此行
MANDATORY_MANPATH                       /usr/local/mysql/man
复制代码
建立数据存放目录
[root@localhost ~]# mkdir -p /opt/data  # 创建目录
[root@localhost ~]# chown -R mysql.mysql /opt/data  # 更改属主
[root@localhost ~]# ll /opt/
总用量 0
drwxr-xr-x. 2 mysql mysql 6 6月  29 06:52 data
初始化数据库
复制代码
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data
2022-06-28T22:57:32.403955Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-06-28T22:57:32.793928Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-06-28T22:57:32.866331Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-06-28T22:57:32.929486Z 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: b1c2a913-f735-11ec-af4e-000c29eeb670.
2022-06-28T22:57:32.931258Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-06-28T22:57:34.257280Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-06-28T22:57:34.257337Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-06-28T22:57:34.258247Z 0 [Warning] CA certificate ca.pem is self signed.
2022-06-28T22:57:34.514921Z 1 [Note] A temporary password is generated for root@localhost: ##CPw=<zJ3oN
#  最后出现的一个只能登陆一次的零时密码,不能搞错,可以先写到一个文件里
[root@localhost ~]# echo '##CPw=<zJ3oN' > pass
复制代码
生成配置文件
复制代码
[root@localhost ~]# vi /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  #跳过名称解析,用IP访问,不用域名访问
#sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
复制代码
复制代码
[root@localhost ~]#  cd /usr/local/mysql/   # 有一个支持文件
[root@localhost mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost mysql]# cd support-files/
[root@localhost support-files]# ls   # 有一个脚本
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@localhost support-files]# file mysql.server 
mysql.server: POSIX shell script, ASCII text executable
[root@localhost support-files]# ll   # 这个脚本有执行权限
总用量 24
-rw-r--r--. 1 mysql mysql   773 11月 30 2021 magic
-rwxr-xr-x. 1 mysql mysql  1061 11月 30 2021 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql   894 11月 30 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 11月 30 2021 mysql.server
[root@localhost support-files]# cp mysql.server mysqld  # 复制一个叫mysqld
[root@localhost support-files]# chown -R mysql.mysql mysqld # 更改权限
[root@localhost support-files]# ll
总用量 36
-rw-r--r--. 1 mysql mysql   773 11月 30 2021 magic
-rwxr-xr-x. 1 mysql mysql 10576 6月  29 07:20 mysqld
-rwxr-xr-x. 1 mysql mysql  1061 11月 30 2021 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql   894 11月 30 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 11月 30 2021 mysql.server
[root@localhost support-files]#  vi mysqld  修改
basedir=/usr/local/mysql # 安装的位子
datadir=/opt/data    # 数据存放的位子
复制代码
启动mysql
复制代码
[root@localhost ~]# /usr/local/mysql/support-files/mysqld start # 用脚本启动
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS! 
[root@localhost ~]# ss -antl  # 此时已有3306端口号
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               [::]:22             [::]:*            
LISTEN 0      80                   *:3306              *:*     
     [root@localhost ~]# ps -ef|grep mysqld  # 进程也有
root        1722       1  0 07:28 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
mysql       1910    1722  0 07:28 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root        1944    1555  0 07:30 pts/0    00:00:00 grep --color=automysqld
复制代码
修改密码,使用临时密码登录
复制代码
[root@localhost ~]# dnf -y install ncurses-compat-libs # 提前把这个包装上
[root@localhost ~]# ls
anaconda-ks.cfg  pass
[root@localhost ~]# cat pass
##CPw=<zJ3oN
[root@localhost ~]# mysql -uroot -p'##CPw=<zJ3oN'  #  用之前保存的零时密码登录
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.37

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('runtime123!');  # 设置新的密码
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit  #  退出
Bye
[root@localhost ~]# mysql -uroot -p'runtime123!'  # 用心密码登录一次,验证新密码设置成功
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.37 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.

mysql> 
复制代码
关闭防火墙,selinux,设置开机自启
复制代码
[root@localhost ~]# cp /usr/lib/systemd/system/sshd.service mysqld.service
[root@localhost ~]# vim mysqld.service
[Unit]
Description=mysql server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysqld start
ExecStop=/usr/local/mysql/support-files/mysqld stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@localhost ~]# mv mysqld.service /usr/lib/systemd/system
[root@localhost ~]# systemctl disable --now firewalld  # 关闭防火墙
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.serv
[root@localhost ~]# vim /etc/selinux/config   #永久关闭selinux


# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl daemon-reload  # 读取一下
[root@localhost ~]# systemctl status mysqld 
● mysqld.service - mysql server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; >
   Active: inactive (dead)
lines 1-3/3 (END)
[root@localhost ~]# systemctl start mysqld  # 启动
[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      128               [::]:22             [::]:*            
LISTEN 0      80                   *:3306              *:*         # 3306端口号
[root@localhost ~]# mysql -uroot -p'runtime123!'  #  也可以通过密码连进来
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.37 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.

mysql> 
[root@localhost ~]# systemctl enable mysqld   # 设置开机自启
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@localhost ~]# systemctl status mysqld
● mysqld.service - mysql server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; v>
   Active: active (running) since Wed 2022-06-29 08:44:05 CST; 3min 4>
 Main PID: 11015 (mysqld_safe)
    Tasks: 29 (limit: 11202)
   Memory: 183.9M
   CGroup: /system.slice/mysqld.service
           ├─11015 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir>
           └─11205 /usr/local/mysql/bin/mysqld --basedir=/usr/local/m>

6月 29 08:44:04 localhost.localdomain systemd[1]: Starting mysql serv>
6月 29 08:44:05 localhost.localdomain mysqld[11002]: Starting MySQL. >
6月 29 08:44:05 localhost.localdomain systemd[1]: Started mysql serve>
lines 1-13/13 (END)
复制代码

3.编译安装php
复制代码
[root@localhost ~]# 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           pass
[root@localhost ~]# rm -rf pass
[root@localhost ~]# tar -xf php-7.4.29.tar.xz  #  解压
[root@localhost ~]# ls
anaconda-ks.cfg   apr-util-1.6.1         httpd-2.4.54.tar.gz
apr-1.7.0         apr-util-1.6.1.tar.gz  php-7.4.29
apr-1.7.0.tar.gz  httpd-2.4.54           php-7.4.29.tar.xz
[root@localhost ~]# cd php-7.4.29  #进到里面去
[root@localhost php-7.4.29]# 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
[root@lch php-7.4.29]# dnf list all|grep mysql|grep php
php-mysqlnd.x86_64                                                  7.2.24-1.module_el8.2.0+313+b04d0a66                          AppStream    
[root@lch php-7.4.29]# dnf -y install php-mysqlnd  # 安装各种依赖包
[root@localhost php-7.4.29]# dnf -y install sqlite-devel
[root@localhost php-7.4.29]# 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
[root@localhost php-7.4.29]# dnf -y install libzip-devel
复制代码

编译安装

复制代码
[root@localhost php-7.4.29]./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
[root@localhost php-7.4.29]# make -j 4   
[root@localhost php-7.4.29]# make install
复制代码

设置环境变量

[root@localhost php-7.4.29]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@localhost php-7.4.29]# source /etc/profile.d/php7.sh  # 读取一下
[root@localhost php-7.4.29]# which php  此时已经可以找到
/usr/local/php7/bin/php

配置php-fpm

复制代码
[root@localhost php-7.4.29]# \cp php.ini-production /etc/php.ini    #复制一个这个文件到etc下,/表示权限也复制
[root@localhost php-7.4.29]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.4.29]# ll /etc/init.d/php-fpm
-rw-r--r-- 1 root root 2402 7月   5 14:33 /etc/init.d/php-fpm
[root@localhost php-7.4.29]# chmod +x /etc/rc.d/init.d/php-fpm   # 添加执行权限
[root@localhost php-7.4.29]# ll /etc/init.d/php-fpm
-rwxr-xr-x 1 root root 2402 7月   5 14:33 /etc/init.d/php-fpm
[root@localhost php-7.4.29]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php-7.4.29]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
复制代码

启动服务,查看端口号,进程。

复制代码
[root@localhost php-7.4.29]# service php-fpm start # 启动
Starting php-fpm  done
[root@localhost php-7.4.29]# ss -antl  #此时已经有9000端口号
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            127.0.0.1:9000          0.0.0.0:*
LISTEN  0        128                    *:80                  *:*
LISTEN  0        128                 [::]:22               [::]:*
LISTEN  0        80                     *:3306                *:*
[root@localhost php-7.4.29]# cd
[root@localhost ~]# ps -ef |grep php  #查看进程
root      135176       1  0 14:36 ?        00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody    135177  135176  0 14:36 ?        00:00:00 php-fpm: pool www
nobody    135178  135176  0 14:36 ?        00:00:00 php-fpm: pool www
root      135186    1766  0 14:37 pts/0    00:00:00 grep --color=auto php
复制代码

设置开机自启

复制代码
[root@localhost ~]# cd /usr/lib/systemd/system  #进到此目录
[root@localhost system]# cp sshd.service php.service #复制一个service文件叫php.service
[root@localhost system]# vim php.service # 编辑
[Unit]
Description=php-fpm server daemon
After=network.target sshd-keygen.target

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

[Install]
WantedBy=multi-user.target     # 编写如上
[root@localhost system]# systemctl daemon-reload  #读取一下
[root@localhost ~]# systemctl status php  #查看状态
● php.service - php-fpm server daemon
   Loaded: loaded (/usr/lib/systemd/system/php.service; disabled; ve>
   Active: inactive (dead)

[root@localhost ~]# systemctl enable --now php#设置开启自启
[root@localhost ~]# systemctl status php
● php.service - php-fpm server daemon
   Loaded: loaded (/usr/lib/systemd/system/php.service; enabled; ven>
   Active: active (running) since Wed 2022-07-06 19:57:22 CST; 43s a>
  Process: 1781 ExecStart=/etc/init.d/php-fpm start (code=exited, st>
 Main PID: 1783 (php-fpm)
    Tasks: 3 (limit: 11202)
   Memory: 29.5M
   CGroup: /system.slice/php.service
           ├─1783 php-fpm: master process (/usr/local/php7/etc/php-f>
           ├─1784 php-fpm: pool www
           └─1785 php-fpm: pool www
[root@localhost ~]# reboot
[root@localhost ~]# 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             [::]:*
复制代码

 

 

配置apache

复制代码
[root@localhost ~]# cd /usr/local/apache/htdocs/ #进到此目录
[root@localhost htdocs]# mkdir sym   #创建sym目录
[root@localhost htdocs]# chown -R apache.apache /usr/local/apache/ # 更改属组属主
[root@localhost htdocs]# cd sym 
[root@localhost sym]# vi index.php   #编写一个index.php的测试文件


<?php
   phpinfo();
?>
[root@localhost htdocs]# ll  # 查看两个文件
总用量 4
-rw-r--r--. 1 apache apache 45 6月  12 2007 index.html
drwxr-xr-x  2 apache apache 23 7月   5 14:40 sym
复制代码

启动代理模块

复制代码
[root@localhost htdocs]# cd /usr/local/apache/conf/
[root@localhost conf]# vi httpd.conf
#ServerName www.example.com:80 # 取消这一行注释,等下重启apache的时候就不会报错 LoadModule proxy_module modules
/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so # 这两行取消注释,启动这两个模块 AddType application/x-compress .Z AddType application/x-gzip .gz .tgz#找到这两行在下面加上下面两行 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps <IfModule dir_module> DirectoryIndex index.php index.html //在前面添加index.php 让网站能够访问到php类型 </IfModule> #文件的最后加上以下内容 </IfModule> <VirtualHost *:80> DocumentRoot "/usr/local/apache/htdocs/sym" ServerName sym.example.com ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/sym/$1 <Directory "/usr/local/apache/htdocs/sym"> Options none AllowOverride none Require all granted </Directory> </VirtualHost>
复制代码

在真机的hosts文件里做ip和域名的映射

 

 

 重启服务

复制代码
[root@localhost conf]# apachectl stop
[root@localhost conf]# apachectl start
[root@localhost conf]# ss -antl
State  Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
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           [::]:*
复制代码

访问网站

 

 

 

 

posted @   孙一鸣  阅读(268)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示