LNMP
Mysql5.7 安装
Nginx1.1.6.0 安装
1# 下载
2[root@localhost software]# wget https://nginx.org/download/nginx-1.16.0.tar.gz
3
4# 依赖
5[root@localhost software]# yum install -y pcre pcre-devel openssl openssl-devel gcc gcc-c++ autoconf automake make
6
7# 编译安装步骤
8[root@localhost software]# tar xf nginx-1.16.0.tar.gz
9[root@localhost software]# cd nginx-1.16.0
10
11[root@localhost nginx-1.16.0]# useradd -s /sbin/nologin www -M
12[root@localhost ~]# mkdir /application
13
14[root@localhost nginx-1.16.0]# ./configure --user=www --group=www --prefix=/application/nginx-1.16.0 --with-http_stub_status_module --with-http_ssl_module --with-pcre
15[root@localhost nginx-1.16.0]# make
16[root@localhost nginx-1.16.0]# make install
17[root@localhost nginx-1.16.0]# ln -s /application/nginx-1.16.0/ /application/nginx
18
19# 启动服务
20[root@localhost nginx-1.16.0]# /application/nginx/sbin/nginx
21
22# 发现nginx监听在80端口上
23[root@localhost nginx-1.16.0]# netstat -tnlp | grep nginx
24tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 31813/nginx: master
25
26# 访问nginx
27http://192.168.31.210/
FastCGI
将脚本解析服务器和 HTTP 服务器分离开来,同时还能在脚本解析服务器上启动一个或多个脚本解析守护进程。当 HTTP 服务器遇到动态程序时,可以将其直接交付给 FastCGI 进程执行,然后将得到的结果返回给浏览器。这种方式可以让 HTTP 服务器专一地处理静态请求,将动态服务器的结果返回给客户端,很大程度上提高了整个应用系统的性能。PHP 动态语言服务端可以启动多个 FastCGI 的守护进程(php-fpm),HTTP 服务通过 FastCGI 客户端(Nginx fastcgi_pass)和动态语言 FastCGI 服务端(php-fpm)通信。
安装 php-7.3.5
1# 依赖
2[root@localhost nginx-1.16.0]# yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpngdevel gd-devel libcurl-devel libxslt-devel -y
3
4# 检查是否安装成功
5[root@localhost nginx-1.16.0]# rpm -qa zlib-devel libxml2-devel libjpeg-turbo-devel libiconv-devel
6zlib-devel-1.2.7-19.el7_9.x86_64
7libxml2-devel-2.9.1-6.el7.5.x86_64
8libjpeg-turbo-devel-1.2.90-8.el7.x86_64
9提示:缺少libiconv-devel
10
11[root@localhost nginx-1.16.0]# rpm -qa freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel
12libpng-devel-1.5.13-8.el7.x86_64
13freetype-devel-2.8-14.el7_9.1.x86_64
14gd-devel-2.0.35-27.el7_9.x86_64
15libcurl-devel-7.29.0-59.el7_9.1.x86_64
16libxslt-devel-1.1.28-6.el7.x86_64
17
18# 由于yum无法安装libiconv库,因此需要手动安装
19[root@localhost software]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
20[root@localhost software]# tar zxf libiconv-1.16.tar.gz
21[root@localhost software]# cd libiconv-1.16
22[root@localhost libiconv-1.16]# ./configure --prefix=/application/libiconv
23[root@localhost libiconv-1.16]# make && make install
24
25# 安装libmcrypt库、mcrypt库、mhash库(配置阿里云YUM,原生YUM源中没有)
26[root@localhost libiconv-1.16]# yum install -y libmcrypt-devel mcrypt mhash
27
28# 安装php-7.3.5 (--with-fpm-user=www 此处与nginx的用户组统一)
29[root@localhost software]# wget https://www.php.net/distributions/php-7.3.5.tar.gz
30[root@localhost software]# tar xf php-7.3.5.tar.gz
31[root@localhost software]# cd php-7.3.5
32[root@localhost software]# ./configure \
33--prefix=/application/php7.3.5 \
34--enable-mysqlnd \
35--with-mysqli=mysqlnd \
36--with-pdo-mysql=mysqlnd \
37--with-iconv-dir=/application/libiconv \
38--with-freetype-dir \
39--with-jpeg-dir \
40--with-png-dir \
41--with-zlib \
42--with-libxml-dir=/usr \
43--enable-xml \
44--disable-rpath \
45--enable-bcmath \
46--enable-sysvsem \
47--enable-inline-optimization \
48--with-curl \
49--enable-mbregex \
50--enable-fpm \
51--enable-mbstring \
52--with-gd \
53--with-openssl \
54--with-mhash \
55--enable-pcntl \
56--enable-sockets \
57--with-xmlrpc \
58--enable-soap \
59--enable-short-tags \
60--enable-static \
61--with-xsl \
62--with-fpm-user=www \
63--with-fpm-group=www \
64--enable-ftp \
65--enable-opcache=no
66
67[root@localhost php-7.3.5]# make && make install
68
69[root@localhost ~]# ln -s /application/php7.3.5/ /application/php
70
71# 配置php.ini(PHP解析器配置文件)
72[root@localhost ~]# cp /software/php-7.3.5/php.ini-development /application/php/lib/php.ini
73
74# 配置PHP FPM
75[root@localhost ~]# cp /application/php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf
76[root@localhost ~]# cp /application/php/etc/php-fpm.d/www.conf.default /application/php/etc/php-fpm.d/www.conf
77
78# 启动PHP服务
79[root@localhost ~]# /application/php/sbin/php-fpm
80[root@localhost ~]# pkill php-fpm # php-fpm没有重启命令,只能kill 再起
81[root@localhost ~]# netstat -lntp | grep php-fpm
82tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 10691/php-fpm: mast
配置 Nginx 转发 PHP 请求
1# 注释掉,修改为这样
2[root@localhost conf]# vim /application/nginx/conf/nginx.conf
3 location ~ .*\.(php|php5)?$ { # 这里需要修改
4 root html;
5 fastcgi_pass 127.0.0.1:9000;
6 fastcgi_index index.php;
7 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
8 include fastcgi.conf;
9 }
10
11
12# 重启
13[root@localhost conf]# /application/nginx/sbin/nginx -s stop
14[root@localhost conf]# /application/nginx/sbin/nginx
15
16# 编写php测试文件
17
18[root@localhost conf]# echo "<?php phpinfo(); ?>" > /application/nginx/html/test_info.php
19[root@localhost conf]# /application/php/bin/php /application/nginx/html/test_info.php
20
21# 访问http://192.168.31.210/test_info.php
22成功...
23
24# 编写php访问mysql的测试文件
25[root@localhost conf]# vim /application/nginx/html/test_mysql.php
26<?php
27$link=mysqli_connect("localhost","root","123");
28if(!$link) echo "FAILD!连接错误,用户名密码不对";
29else echo "OK!可以连接";
30?>
31
32# 访问http://192.168.31.210/test_mysql.php
33成功...