配置Linux+Nginx+php环境搭建

1.安装pcre。pcre是一个perl库,Nginx的HTTP模块使用pcre来解析正则表达式。
2.安装zlib。zlib是一个文件压缩和解压缩的库,Nginx使用zlib对HTTP数据包进行gzip压缩和解压。

yum -y install gcc pcre-devel.x86_64 zlib-devel.x86_64

已安装:
  gcc.x86_64 0:4.8.5-39.el7                    pcre-devel.x86_64 0:8.32-17.el7  

已安装:
  zlib-devel.x86_64 0:1.2.7-18.el7                                                                


3.添加nginx 用户
#useradd -s /sbin/nologin nginx

[root@sunny ~]# useradd -s /sbin/nologin nginx
[root@sunny ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@sunny ~]# ls /usr
bin  etc  games  include  lib  lib64  libexec  local  sbin  share  src  tmp
[root@sunny ~]# cd /root
[root@sunny ~]# cd /home
[root@sunny home]# ls
nginx  sunny

  1. 下载nginx
    [root@sunny ~]# wget http://nginx.org/download/nginx-1.17.10.tar.gz
[root@sunny ~]# ls
anaconda-ks.cfg       **nginx-1.17.10.tar.gz**  模板  图片  下载  桌面
initial-setup-ks.cfg  公共                  视频  文档  音乐
[root@sunny ~]# cd nginx-1.17.10/
[root@sunny nginx-1.17.10]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src

5.配置nginx

./configure --prefix=/usr/local/nginx --user=nginx --with-stream

–prefix: 安装路径
–user: 用户名
–with-stream : 反向代理

[root@sunny nginx-1.17.10]# ./configure --prefix=/usr/local/nginx --user=nginx --with-stream
checking for OS
 + Linux 3.10.0-1062.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
。。。
Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

  1. 编译(把源码文件变为程序)
    #make
  2. 安装 (把编译好的程序部署到系统目录)
    #make install

8.查看安装目录,找到启动目录。如果安装httpd服务,先关闭服务避免冲突。启用nginx服务程序

[root@sunny nginx-1.17.10]# ls /usr/local/nginx
conf  html  logs  sbin
[root@sunny nginx-1.17.10]# ls /usr/local/nginx/sbin
nginx
[root@sunny nginx-1.17.10]# systemctl disable httpd --now
[root@sunny nginx-1.17.10]# /usr/local/nginx/sbin/nginx 
[root@sunny nginx-1.17.10]# 

在浏览器输入本机IP地址配置Linux+Nginx+php环境搭建_第1张图片
9. 方便启动,创建快捷方式
#vim /etc/bashrc
#source /etc/bashrc

alias ngx-start='/usr/local/nginx/sbin/nginx'
alias ngx-stop='pkill -9 nginx'
alias ngx-reload='/usr/local/nginx/sbin/nginx -s reload'

二, 配置并测试LNMP组件

  1. 安装Mariadb 数据库组件
    #yum -y install mariadb

  2. 编译安装php-fpm
    安装依赖包


# yum -y install libmcrypt-devel mhash-devel libxslt-devel \
libjpeg libjpeg-devel libpng libpng-dvevl freetype freetype-devel libxml2 libxml2-devel \
zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \
ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \
krb5 krb5-devel libidn libidn-devel openssl openssl-devel
 
 
# yum -y install libzip 
# wget http://103.40.19.56/lnmp/libzip-1.3.2.tar.gz 
# tar -zxvf libzip-1.3.2.tar.gz cd libzip-1.3.2 
# ./configure 
# make && make install
 
# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
# tar -zxvf libmcrypt-2.5.7.tar.gz
# cd libmcrypt-2.5.7
# ./configure  –prefix=/usr/local
# make && make install

#下载
wget http://cn2.php.net/distributions/php-7.2.14.tar.gz
#解压
tar zvxf php-7.2.14.tar.gz
#进入解压的文件
cd php-7.2.14

配置

[root@sunny php-7.2.14]# ./configure --prefix=/usr/local/php7.2.14 --sysconfdir=/etc/php7.2.14 --with-config-file-path=/etc/php7.2.14 --enable-fpm --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mhash --with-openssl --with-curl --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-zlib --enable-mbstring --enable-sockets --with-iconv-dir --with-xsl --enable-zip --with-pcre-dir --with-pear --enable-session --enable-xml --with-freetype-dir --enable-gd-jis-conv --enable-inline-optimization --enable-shared --enable-bcmath --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-mbregex --enable-pcntl --with-xmlrpc --with-gettext --enable-exif

#make & make install

[root@sunny php-7.2.14]# pwd
/root/php-7.2.14
[root@sunny php-7.2.14]# cp php.ini-production /etc/php7.2.14/php.ini
[root@sunny php7.2.14]# cp php-fpm.conf.default php-fpm.conf
[root@sunny php7.2.14]# pwd
/etc/php7.2.14
[root@sunny php7.2.14]# cp php-fpm.d/www.conf.default php-fpm.d/www.conf

[root@sunny run]# vim /usr/local/nginx/html/t2.php
[root@sunny run]# ls^C
[root@sunny run]# cd /etc/php7.2.14
[root@sunny php7.2.14]# vim php-fpm.conf

pid =/usr/local/php7.2.14/var/run/php-fpm.pid
error_log = /usr/local/php7.2.14//var/log/php-fpm.log

改后测试

[root@sunny sbin]# /usr/local/php7.2.14/sbin/php-fpm -t
[04-May-2022 13:23:36] NOTICE: configuration file /etc/php7.2.14/php-fpm.conf test is successful

配置php-fpm组件
[root@sunny php7.2.14]# cd php-fpm.d/
[root@sunny php-fpm.d]# vim www.conf
修改运行用户

user = nginx
group = nginx

配置nginx 调用php-fpm
[root@sunny src]# vim /usr/local/nginx/conf/nginx.conf

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

   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.conf;
        }


创建t1.php 测试
[root@sunny html]# vim /usr/local/nginx/html/t1.php


                     

创建t2.php 测试
[root@sunny html]# vim /usr/local/nginx/html/t2.php



重启nginx, php-fpm , mariadb
[root@sunny html]# ngx-stop
[root@sunny html]# ngx-start
#systemctl restart mariadb
[root@sunny run]# /usr/local/php7.2.14/sbin/php-fpm

注意(php-fpm重启命令 查找命令id 然后kill):
[root@sunny run]# ps aux | grep php-fpm | grep master | grep -v grep
root 48025 0.0 0.2 228544 4416 ? Ss 14:42 0:00 php-fpm: master process (/etc/php7.2.14/php-fpm.conf)

测试结果:

配置Linux+Nginx+php环境搭建_第2张图片
配置Linux+Nginx+php环境搭建_第3张图片

你可能感兴趣的:(nginx,linux,php)