LNMP搭建
nginx安装
#:创建系统用户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'
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Marked install: Development Tools
#:创建日志存放目录
[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx
#:下载nginx
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http:#:nginx.org/download/nginx-1.22.1.tar.gz
#:编译安装
[root@localhost src]# ls
anaconda-ks.cfg nginx-1.12.0.tar.gz
[root@localhost src]# tar xf nginx-1.22.1.tar.gz
[root@localhost src]# cd nginx-1.22.1
[root@localhost nginx-1.22.1]# ./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.22.1]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
安装过程略....
安装数据库
[root@localhost ~]# yum -y install mariadb mariadb-server
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl enable mariadb
配置环境变量并启动nginx
[root@localhost ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost ~]# . /etc/profile.d/nginx.sh
[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:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
编辑nginx配置文件
#:编辑 /usr/local/nginx/conf/nginx.conf 将以下行取消注释
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;
include fastcgi_params;
}
#:将原来的/scripts$fastcgi_script_name;改成/$document_root$fastcgi_script_name;然后重新启动nginx
编辑php配置文件
#:编辑 /etc/httpd/conf.d/php.conf 文件在文档最后添加
#:没有配置文件请安装php服务,nginx本身不做nginx解析;
</IfModule>
<VirtualHost *:9000>
DocumentRoot "/usr/local/nginx/html"
ErrorLog "/usr/local/nginx/html"
CustomLog "/usr/local/nginx/html" common
ProxyRequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/nginx/html$1
<Directory "/usr/local/nginx/html">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
#:编辑 /etc/php-fpm.d/www.conf 最后添加
listen = 0.0.0.0:9000
#:重启php服务
编辑php默认页
#:编写/usr/local/nginx/html/index.php 文件内容如下
<?php
phpinfo();
?>
网站测试:
动态页面:
静态页面: