lnmp部署(nginx编译+MySQL2进制+PHP编译)

编译安装nginx

软件包下载地址
在这里插入图片描述

[root@localhost ~]# wget http://nginx.org/download/nginx-1.22.0.tar.gz
--2022-09-01 23:22:29--  http://nginx.org/download/nginx-1.20.2.tar.gz
正在解析主机 nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5704::6, ...
正在连接 nginx.org (nginx.org)|3.125.197.172|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1062124 (1.0M) [application/octet-stream]
正在保存至: “nginx-1.20.2.tar.gz”

nginx-1.22.2.tar.g  77%[===========>    ] 805.13K  12.6KB/s  剩余 10s     
//创建系统用户nginx
[root@localhost ~]# useradd -r -M -s /sbin/nologin nginx

//安装依赖环境
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
安装过程略....
[root@localhost ~]# yum -y groups mark install 'Development Tools'
[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx
[root@localhost ~]# ll -d /var/log/nginx/
drwxr-xr-x. 2 nginx nginx 6 91 23:29 /var/log/nginx/
//编译
[root@localhost ~]# tar -xf nginx-1.22.0.tar.gz 
[root@localhost ~]# cd nginx-1.22.0/
[root@localhost nginx-1.12.0]# ./configure \
--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.2]# make
//省略过程
[root@localhost nginx-1.20.2]# make install
//省略过程
//设置环境变量
[root@localhost ~]# ls /usr/local/nginx/
conf  html  logs  sbin
[root@localhost ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
//服务控制方式,使用nginx命令
    -t  //检查配置文件语法
    -v  //输出nginx的版本
    -V  //可以看到编译参数
    -c  //指定配置文件的路径
    -s  //发送服务控制信号,可选值有{stop|quit|reopen|reload}

[root@localhost ~]# source /etc/profile.d/nginx.sh
//关闭防火墙和seliunx
[root@localhost ~]# systemctl disable --now firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config 
[root@localhost ~]# nginx
[root@localhost ~]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port       Peer Address:Port   
LISTEN   0        128               0.0.0.0:111             0.0.0.0:*      
LISTEN   0        128               0.0.0.0:80              0.0.0.0:*    
  //设置开机自启
[root@localhost html]# cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/nginx.service
[root@localhost html]# vim /usr/lib/systemd/system/nginx.service
[root@localhost ~]# cat /usr/lib/systemd/system/nginx.service
Description=web server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/usr/local/nginx/sbin/nginx -s reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target
//重启配置文件
[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port       Peer Address:Port   
LISTEN   0        128               0.0.0.0:111             0.0.0.0:*      
LISTEN   0        128               0.0.0.0:80              0.0.0.0:*      
LISTEN   0        32          192.168.122.1:53              0.0.0.0:*      
LISTEN   0        128               0.0.0.0:22              0.0.0.0:*      
LISTEN   0        5               127.0.0.1:631             0.0.0.0:*      
LISTEN   0        128                  [::]:111                [::]:*      
LISTEN   0        128                  [::]:22                 [::]:*      
LISTEN   0        5                   [::1]:631                [::]:*      
[root@localhost ~]# systemctl stop nginx
[root@localhost ~]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port       Peer Address:Port   
LISTEN   0        128               0.0.0.0:111             0.0.0.0:*      
LISTEN   0        32          192.168.122.1:53              0.0.0.0:*      
LISTEN   0        128               0.0.0.0:22              0.0.0.0:*      
LISTEN   0        5               127.0.0.1:631             0.0.0.0:*      
LISTEN   0        128                  [::]:111                [::]:*      
LISTEN   0        128                  [::]:22                 [::]:*      
LISTEN   0        5                   [::1]:631                [::]:*    

二进制安装MySQL

软件包下载地址
在这里插入图片描述

//创建系统用户
[root@localhost src]# useradd -r -M -s /sbin/nologin mysql
[root@localhost src]# id mysql
uid=975(myaql) gid=973(myaql)=973(myaql)
[root@localhost src]# ls /usr/local/
bin  etc  games  include  lib  lib64  libexec  sbin  share  src
[root@localhost ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# tar -xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
bin  games    lib    libexec                              nginx  share
etc  include  lib64  mysql-5.7.38-linux-glibc2.12-x86_64  sbin   src
[root@localhost local]# mv mysql-5.7.38-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ls
bin  games    lib    libexec  nginx  share
etc  include  lib64  mysql    sbin   src
//修改目录账户属主属组
[root@localhost local]# chown -R mysql.mysql mysql
[root@localhost local]# ll -d mysql/
drwxr-xr-x. 9 mysql mysql 129 628 15:41 mysql/
//添加环境变量,叫他在那个目录找MySQL
[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
//有特定的目录的时候,要修改
//include(头文件)
//man(帮助文档)
//lib(库)
//bin(主程序)

//设置软链接,里面有多个文件,以后好直接删除目录
[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
//告诉他头文件库在那个地方
[root@localhost mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]# cat /etc/ld.so.conf.d/mysql.conf 
/usr/local/mysql/lib
//读取配置文件
[root@localhost mysql]# ldconfig
//告诉他man文档在那个地方
[root@localhost mysql]# vim /etc/man_db.conf 
#MANDATORY_MANPATH                      /usr/src/pvm3/man
#
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
//加上这一行
MANDATORY_MANPATH                       /usr/local/mysql/man
#---------------------------------------------------------
# set up PATH to MANPATH mapping
# ie. what man tree holds man pages for what binary directory.
//建立数据存放目录
在企业,设置数据存放目录要放在存储空间大的目录
[root@localhost ~]# mkdir -p /opt/data
[root@localhost  ]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# ll -d /opt/data/
drwxr-xr-x. 2 mysql mysql 6 628 18:39 /opt/data/
//mysqld 系统知道mysql在哪就不用加路径
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data
2022-06-28T10:40:51.279183Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-06-28T10:40:52.695768Z 0 [Warning] CA certificate ca.pem is self signed.
2022-06-28T10:40:52.909685Z 1 [Note] A temporary password is generated for root@localhost: jysro6OtPi)o
[root@localhost ~]#  echo "jysro6OtPi" > pass
[root@localhost ~]# 
//生成配置文件
[root@localhost】 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
#  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/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 1130 2021 magic
-rwxr-xr-x. 1 mysql mysql  1061 1130 2021 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql   894 1130 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 1130 2021 mysql.server
[root@localhost support-files]# cp mysql.server mysqld
[root@localhost support-files]# ll
总用量 36
-rw-r--r--. 1 mysql mysql   773 1130 2021 magic
-rwxr-xr-x. 1 root  root  10576 628 18:57 mysqld
-rwxr-xr-x. 1 mysql mysql  1061 1130 2021 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql   894 1130 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 1130 2021 mysql.server
[root@localhost support-files]# chown -R mysql.mysql mysqld
[root@localhost support-files]# ll
总用量 36
-rw-r--r--. 1 mysql mysql   773 1130 2021 magic
-rwxr-xr-x. 1 mysql mysql 10576 628 18:57 mysqld
-rwxr-xr-x. 1 mysql mysql  1061 1130 2021 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql   894 1130 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 1130 2021 mysql.server
[root@localhost support-files]# vim mysqld

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
//改这个地方
basedir=/usr/local/mysql
datadir=/opt/data

[root@localhost ~]# /usr/local/mysql/support-files/mysqld start
Starting MySQL.Logging to '/opt/data/localhost.err'.
 SUCCESS! 
[root@localhost ~]# ss -antl
State    Recv-Q    Send-Q       Local Address:Port       Peer Address:Port   
LISTEN   0         128                0.0.0.0:111             0.0.0.0:*      
LISTEN   0         32           192.168.122.1:53              0.0.0.0:*      
LISTEN   0         128                0.0.0.0:22              0.0.0.0:*      
LISTEN   0         5                127.0.0.1:631             0.0.0.0:*      
LISTEN   0         80                       *:3306                  *:*      
[root@localhost ~]# ps -ef|grep mysqld
root      411797       1  0 19:01 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/localhost.pid
//报错缺少东西
[root@localhost ~]# mysql -uroot -p'jysro6OtPi'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
//查找东西来源那个包
[root@localhost ~]# dnf provides libncurses.so.5
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:40:31 前,执行于 20220628日 星期二 182534秒。
ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
仓库        :base
匹配来源:
提供    : libncurses.so.5
//安装包
[root@localhost ~]# dnf -y install ncurses-compat-libs
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:42:51 前,执行于 20220628日 星期二 182534秒。

[root@localhost ~]# cat pass
x7GkcGDZ0h(d
[root@localhost ~]# mysql -uroot -p'x7GkcGDZ0h(d'
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.
//设置开机自启
//关闭selinux
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config 
[root@localhost ~]# ll -Z /usr/lib/systemd/system/{sshd.service,mysqld.service}
//admin_home报文 selinux无法识别,所以会报错,所有要关闭selinux
-rw-r--r--. 1 root root unconfined_u:object_r:admin_home_t:s0 283 628 20:27 /usr/lib/systemd/system/mysqld.service
-rw-r--r--. 1 root root system_u:object_r:sshd_unit_file_t:s0 456 19 2020 /usr/lib/systemd/system/sshd.service


[root@localhost ~]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysqld 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 -HDP $MATNPID

[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor >
   Active: inactive (dead)
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor >
   Active: active (running) since Tue 2022-06-28 20:49:53 CST; 1s ago
  Process: 512182 ExecStart=/usr/local/mysql/support-files/mysqld start (cod>

[root@localhost ~]# systemctl enable mysqld         //出现报错,后面有解决办法
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
   .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
   a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
   D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
   instance name specified.
 //解决办法
[root@localhost support-files]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysqld 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 -HDP $MATNPID

//添加以下3行
[Install]
WantedBy=multi-user.target
elias=mysqld service
//重启配置文件
[root@localhost support-files]# systemctl daemon-reload 
[root@localhost support-files]# systemctl restart mysqld.service 
[root@localhost support-files]# systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@localhost support-files]# vim /usr/lib/systemd/system/mysqld.service
[root@localhost support-files]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port       Peer Address:Port   
LISTEN   0        128               0.0.0.0:111             0.0.0.0:*      
LISTEN   0        128               0.0.0.0:80              0.0.0.0:*      
LISTEN   0        32          192.168.122.1:53              0.0.0.0:*      
LISTEN   0        128               0.0.0.0:22              0.0.0.0:*      
LISTEN   0        5               127.0.0.1:631             0.0.0.0:*      
LISTEN   0        80                      *:3306                  *:*      
LISTEN   0        128                  [::]:111                [::]:*      
LISTEN   0        128                  [::]:22                 [::]:*      
LISTEN   0        5                   [::1]:631                [::]:*      

//设置免密登录
//免密登录必须要在家目录下创建
[root@localhost ~]# vim .my.cnf
[root@localhost ~]# cat .my.cnf 
[client]
user = root
password = runtime123
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
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> quit
Bye

编译安装PHP

软件包下载地址
在这里插入图片描述

//下载依赖包
[root@localhost ~]# 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 sqlite-devel libzip-devel libtool
[root@localhost ~]# wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz     //下载此包 后续编译php需要
[root@localhost ~]# tar -zxf oniguruma-6.9.4.tar.gz  //解压
[root@localhost ~]# cd oniguruma-6.9.4 
[root@localhost oniguruma-6.9.4]# dnf -y install automake

//编译安装
[root@localhost oniguruma-6.9.4]# ./autogen.sh && ./configure --prefix=/usr
Generating autotools files.
libtoolize: putting auxiliary files in '.'.
libtoolize: copying file './ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
[root@localhost oniguruma-6.9.4]# make && make install    ///省略过程
//下载PHP软件包
[root@localhost ~]# wget https://www.php.net/distributions/php-8.1.10.tar.gz
[root@localhost ~]# tar xf php-8.1.10.tar.gz
[root@localhost ~]# cd php-8.1.10/
./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-8.1.10]# make
[root@localhost php-8.1.10]# make install   //make编译
[root@localhost php-8.1.10]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh  //使php命令可以使用
[root@localhost php-8.1.10]# source /etc/profile.d/php7.sh    //读取 让其生效
[root@localhost ~]# which php
/usr/local/php7/bin/php
[root@localhost ~]# cd php-8.1.10/
[root@localhost php-8.1.10]# cp php.ini-production /etc/php.ini  //将生产环境文件 复制到etc下 
[root@localhost php-8.1.10]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost fpm]# chmod +x /etc/rc.d/init.d/php-fpm  //此文件需要执行权限所以复制过去要看是否有执行(x)权限
[root@localhost php-8.1.10]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf   //将php-fpm.conf.default 复制一份名为php-fpm.conf
[root@localhost php-8.1.10]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf    //将www.conf.default 复制一份名为www.conf
[root@localhost ~]# service php-fpm start
Starting php-fpm  done
[root@localhost ~]# ss -antl  //php-fpm 的默认端口为9000
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         128                127.0.0.1:9000              0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:111               0.0.0.0:*   
[root@localhost ~]# ps -ef |grep php  //查看php的进程
root      681716       1  0 19:57 ?        00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody    681717  681716  0 19:57 ?        00:00:00 php-fpm: pool www
nobody    681718  681716  0 19:57 ?        00:00:00 php-fpm: pool www
root      689388  362392  0 19:59 pts/1    00:00:00 grep --color=auto php
[root@localhost nginx]# ls
client_body_temp  fastcgi_temp  logs        sbin       uwsgi_temp
conf              html          proxy_temp  scgi_temp
[root@localhost nginx]# cd /usr/local/nginx/html/
[root@localhost html]# mkdir test.com
[root@localhost html]# ls
index.html  test.com
[root@localhost html]# chown -R nginx.nginx /usr/local/nginx/    //设置apache下的文件目录属组属主都为nginx
[root@localhost html]# ll
总用量 4
-rw-r--r-- 1 nginx nginx 12 93 20:02 index.html
drwxr-xr-x 2 nginx nginx  6 93 20:03 test.com
[root@localhost html]# cd test.com/
[root@localhost test.com]# vim index.php   //创建一个index.php的测试文件
[root@localhost nginx]# cat html/test.com/index.php 
<?php
   phpinfo();
?>

[root@localhost test.com]# cd
[root@localhost ~]# cd /usr/local/nginx/conf/
[root@localhost conf]# ls
fastcgi.conf            koi-win             scgi_params
fastcgi.conf.default    mime.types          scgi_params.default
fastcgi_params          mime.types.default  uwsgi_params
fastcgi_params.default  nginx.conf          uwsgi_params.default
koi-utf                 nginx.conf.default  win-utf

[root@localhost conf]# vim nginx.conf
[root@localhost conf]# nginx -s stop
[root@localhost conf]# nginx
[root@localhost conf]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port       Peer Address:Port   
LISTEN   0        128             127.0.0.1:9000            0.0.0.0:*      
LISTEN   0        128               0.0.0.0:111             0.0.0.0:*      
LISTEN   0        128               0.0.0.0:80              0.0.0.0:*      
LISTEN   0        32          192.168.122.1:53              0.0.0.0:*      
LISTEN   0        128               0.0.0.0:22              0.0.0.0:*      
LISTEN   0        5               127.0.0.1:631             0.0.0.0:*      
LISTEN   0        80                      *:3306                  *:*      
LISTEN   0        128                  [::]:111                [::]:*      
LISTEN   0        128                  [::]:22                 [::]:*      
LISTEN   0        5                   [::1]:631                [::]:*      

实现LNMP之间建立关系

(一)实现nginx + php建立关系

    server {
        listen       80;
        server_name  www.qzl.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html/test.com;
            index  index.php index.html;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        //取消下面几行的注释
        location ~ \.php$ {
            root           html/test.com;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


//重启nginx
[root@localhost nginx]# systemctl stop nginx
[root@localhost nginx]# systemctl start nginx
[root@localhost nginx]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port       Peer Address:Port   
LISTEN   0        128             127.0.0.1:9000            0.0.0.0:*      
LISTEN   0        128               0.0.0.0:111             0.0.0.0:*      
LISTEN   0        128               0.0.0.0:80              0.0.0.0:*      
LISTEN   0        128               0.0.0.0:81              0.0.0.0:*      
LISTEN   0        32          192.168.122.1:53              0.0.0.0:*      
LISTEN   0        128               0.0.0.0:22              0.0.0.0:*      
LISTEN   0        5               127.0.0.1:631             0.0.0.0:*      
LISTEN   0        80                      *:3306                  *:*      
LISTEN   0        128                  [::]:111                [::]:*      
LISTEN   0        128                  [::]:22                 [::]:*      
LISTEN   0        5                   [::1]:631                [::]:*      

在这里插入图片描述

(二)实现php + mysql 建立关系

//创建测试文件
[root@localhost nginx]# vim html/test.com/test_mysql.php 
[root@localhost nginx]# cat html/test.com/test_mysql.php 
<?php
$servername = "localhost";
$username = "root";
$password = "runtime123";
//$link_id=mysql_connect('主机名','用户','密码');
//mysql -u用户 -p密码 -h 主机
$conn = mysqli_connect($servername, $username, $password);
if ($conn) {
     echo "mysql successful by root !\n";
  }else{
     die("Connection failed: " . mysqli_connect_error());
   }
?>
[root@localhost nginx]# systemctl daemon-reload   //重启配置文件

在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值