要求:用nginx1.20.1、php8.0.10
1、下载所需安装包
关闭防火墙和selinux
[root@localhost ~]
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]
[root@localhost ~]
下载并解压nginx、mysql、php安装包
[root@localhost ~]
[root@localhost src]
--2021-10-26 18:44:00-- http://nginx.org/download/nginx-1.20.1.tar.gz
正在解析主机 nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5702::6, ...
正在连接 nginx.org (nginx.org)|3.125.197.172|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1061461 (1.0M) [application/octet-stream]
正在保存至: “nginx-1.20.1.tar.gz”
nginx-1.20.1.tar 100%[=========>] 1.01M 560KB/s 用时 1.9s
2021-10-26 18:44:03 (560 KB/s) - 已保存 “nginx-1.20.1.tar.gz” [1061461/1061461])
[root@localhost src]
debug nginx-1.20.1.tar.gz
kernels php-8.0.10.tar.xz
mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]
[root@localhost src]
[root@localhost src]
[root@localhost src]
[root@localhost local]
bin lib nginx-1.20.1 src
etc lib64 php-8.0.10
games libexec sbin
include mysql-5.7.34-linux-glibc2.12-x86_64 share
2、安装nginx
// 创建系统用户nginx
[root@localhost ~]
// 安装依赖包
[root@localhost ~]
[root@localhost ~]
// 创建日志存放目录
[root@localhost ~]
[root@localhost ~]
// 编译安装
[root@localhost src]
[root@localhost nginx-1.20.1]
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log
[root@localhost nginx-1.20.1]
// 配置环境变量
[root@localhost ~]
[root@localhost ~]
2、安装mysql
// 创建MySQL用户
[root@localhost ~]
// 下载依赖包
[root@localhost ~]
// 创建软连接
[root@localhost ~]
[root@localhost local]
'mysql' -> 'mysql-5.7.34-linux-glibc2.12-x86_64/'
[root@localhost local]
总用量 4
drwxr-xr-x. 2 root root 6 5月 19 2020 bin
drwxr-xr-x. 2 root root 6 5月 19 2020 etc
drwxr-xr-x. 2 root root 6 5月 19 2020 games
drwxr-xr-x. 2 root root 6 5月 19 2020 include
drwxr-xr-x. 2 root root 6 5月 19 2020 lib
drwxr-xr-x. 3 root root 17 9月 30 01:33 lib64
drwxr-xr-x. 2 root root 6 5月 19 2020 libexec
lrwxrwxrwx 1 root root 36 10月 26 18:59 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64/
drwxr-xr-x 9 root root 129 10月 26 18:46 mysql-5.7.34-linux-glibc2.12-x86_64
drwxr-xr-x 6 root root 54 10月 26 18:55 nginx
drwxr-xr-x 9 1001 1001 186 10月 26 18:51 nginx-1.20.1
drwxrwxr-x 16 root root 4096 8月 24 23:40 php-8.0.10
drwxr-xr-x. 2 root root 6 5月 19 2020 sbin
drwxr-xr-x. 5 root root 49 9月 30 01:33 share
drwxr-xr-x. 2 root root 6 5月 19 2020 src
// 修改目录/usr/local/mysql的属主属组
[root@localhost local]
[root@localhost local]
lrwxrwxrwx 1 mysql mysql 36 10月 26 18:59 /usr/local/mysql -> mysql-5.7.34-linux-glibc2.12-x86_64/
// 添加环境变量
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
/usr/local/mysql/bin:/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
// 创建数据存放目录
[root@localhost ~]
[root@localhost ~]
// 初始化数据存放目录
[root@localhost ~]
2021-10-26T11:01:48.559986Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-10-26T11:01:48.695190Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-10-26T11:01:48.726168Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-10-26T11:01:48.781123Z 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: 1dd8e669-364c-11ec-9de0-000c29e9a550.
2021-10-26T11:01:48.781747Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-10-26T11:01:49.167292Z 0 [Warning] CA certificate ca.pem is self signed.
2021-10-26T11:01:49.351122Z 1 [Note] A temporary password is generated for root@localhost: HqwG6gph!>4d // 记住这个密码
[root@localhost ~]
[root@localhost ~]
HqwG6gph!>4d
// 配置mysql
[root@localhost ~]
'/usr/local/include/mysql' -> '/usr/local/mysql/include/'
[root@localhost ~]
[root@localhost ~]
// 生成配置文件
[root@localhost ~]
[root@localhost ~]
[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 ~]
[root@localhost ~]
[root@localhost ~]
// 配置service文件
[root@localhost ~]
[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
[Install]
WantedBy=multi-user.target
// 重新加载
[root@localhost ~]
// 启动
[root@localhost ~]
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
SUCCESS!
// 登录并更改密码
[root@localhost ~]
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34
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> set password = password('wjj');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit
Bye
3、安装php
// 下载依赖包
[root@localhost ~]
[root@localhost ~]
// 编译安装
[root@localhost]
[root@localhost php-8.0.10]
--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.
[root@localhost php-8.0.10]
// 配置环境变量
[root@localhost php-8.0.10]
[root@localhost php-8.0.10]
[root@localhost php-8.0.10]
/usr/local/php8/bin/php
[root@localhost php-8.0.10]
PHP 8.0.10 (cli) (built: Oct 26 2021 19:28:33) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies
// 配置php-fpm
[root@localhost php-8.0.10]
[root@localhost php-8.0.10]
[root@localhost php-8.0.10]
[root@localhost php-8.0.10]
[root@localhost php-8.0.10]
// 配置service文件
[root@localhost ~]
[Unit]
Description=Php-fpm server daemon
After=network.target
[Service]
Type=forking
ExecStart=service php-fpm start
ExecStop=service php-fpm stop
[Install]
WantedBy=multi-user.target
// 重新加载
[root@localhost ~]
// 启动
[root@localhost php-8.0.10]
Starting php-fpm done
[root@localhost php-8.0.10]
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 80 *:3306 *:*
LISTEN 0 128 [::]:22 [::]:*
4、nginx配置
[root@localhost ~]
43 location / {
44 root html;
45 index index.php index.html index.htm;
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
70 include fastcgi_params;
71 }
72
[root@localhost ~]
[root@localhost html]
[root@localhost html]
<?php
phpinfo();
?>
5、php配置
[root@localhost ~]
22 ; will be used.
23 user = nginx
24 group = nginx
6、重启所有服务
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@localhost ~]
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@localhost ~]
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
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 80 *:3306 *:*
LISTEN 0 128 [::]:22 [::]:*
7、访问测试
|