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 librarynginx 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地址
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

<?php phpinfo(); ?>

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

<?php$link = mysqli_connect('127.0.0.1','root','12345');if($link) echo "Success";else  echo "Failed";mysql_close();
?>

重启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环境搭建相关推荐

  1. linux基本项目环境搭建

    文章目录 linux基本项目环境搭建 java环境搭建 获取java源码包 解压 配置环境变量 使配置文件生效 验证 nginx安装 下载(java也可用此方法下载) 解压 配置(configure) ...

  2. Linux服务器开发环境搭建 Nginx+PHP+MongoDB

     Linux服务器开发环境搭建 Nginx+PHP+MongoDB mkdir -p /home/trlinux/download mkdir -p /home/trlinux/server mkdi ...

  3. nagios+nginx从环境搭建到配置

    nagios+nginx从环境搭建到配置 nagios是一个开源免费的系统监控工具,官网地址 http://www.nagios.org/     截止2011-07-27    nagios的最新版 ...

  4. Linux(ubuntu) LNMP环境搭建

    Linux(ubuntu) LNMP环境搭建 1. 配置源地址 Ubuntu默认使用的官方源的服务器在欧洲,从国内访问速度很慢 先修改软件源为国内的, 例如: 阿里云源, 清华源等等 整体步骤: 查询 ...

  5. linux 内网环境搭建 maven 私库

    linux 内网环境搭建 maven 私库 参考资料: https://www.codenong.com/cs106446840/ https://blog.csdn.net/lch_wyl/arti ...

  6. 第1章 Linux系统介绍与环境搭建准备

    第1章 Linux系统介绍与环境搭建准备 本章以操作系统的介绍作开篇,首先介绍操作系统的基础概念以及操作系统的原理:然后带领读者了解Unix/Linux的诞生和发展史,以及市面上常见的Unix/Lin ...

  7. 嵌入式arm linux Java运行环境搭建和注意事项

    嵌入式arm linux Java运行环境搭建和注意事项 我的开发硬件环境 搭建步骤 1. 下载 ORacle 公司的ejdk-8u211-linux-arm-sflt.tar.gz(软件浮点版本,这 ...

  8. Linux下开发环境搭建---2. emacs篇

    Linux下开发环境搭建---2. emacs篇 本节主要参考:      曹乐的<在Emacs下用C/C++编程>      王纯业的<Emacs 一个强大的平台>      ...

  9. php linux下开发教程,linux下php环境搭建教程_后端开发

    linux下php环境搭建要领:起首猎取PHP.Apache以及MySQL装置包:然后装置Apache,并修正设置文件httpd.conf:接着装置MySQL,并做基础设置:末了装置PHP,并设置ph ...

最新文章

  1. 2020年最具潜力44个顶级开源项目,涵盖11类 AI 学习框架、平台
  2. 中国知名企业ERP失败案例深入剖析
  3. android post json格式,Android中post请求传递json数据给服务端的实例
  4. 【Android 应用开发】Paint 图形组合 Xfermod 之 合成模式表示方法 ( Xfermod 使用步骤 | 透明度 颜色值 公式表示方法 | 老版本表示方法 | 合成区域分块 )
  5. “如果把所有的经济学家都放在一起,他们永远不会得出结论。 - 萧伯纳
  6. 微博爬虫实践---搜索关键词
  7. 解决orcale报ORA-28001: the password has expired
  8. 主成分分析和因子分析十大不同点
  9. cesium 雷达扫描(附源码下载)
  10. python之yield
  11. 2017CCPC哈尔滨 A:Palindrome(manacher+树状数组)
  12. Android中Service的一个Demo例子
  13. Microsoft 365 for Mac(原Office 365)
  14. web自动化知识点-02
  15. (3)I/O流对象-----复制图片/文件/视频的几种I/O流方式
  16. bootice添加黑苹果引导_Clover(四叶草)引导多系统(Linux亦可),黑苹果引导教程
  17. android 备份取证,【Android】微信降版本备份详解
  18. 多重选定怎么撤销_怎样取消电脑多重网络 - 卡饭网
  19. 判断两个单词是否互为变位词,如“book”,“koob”,代码如下
  20. win10计算机升级系统,微软Win10升级助手

热门文章

  1. 边缘计算服务器传感器无线组网,边缘计算、传感器、5G 让物联网离我们更近
  2. NOIP复习模拟赛day1
  3. UITextView控件_文字内容居左居上
  4. 案例+代码详解:用Word2Vec建立你的私人购物助手
  5. Java Collection集合 --迭代器 -- 泛型 --List接口案例
  6. 零基础考计算机职称,教师中级职称计算机考试零基础通关方法和技巧
  7. OpenVR针对OptiTrack的支持方式
  8. vue中实现地图下钻
  9. MyCat:第二章:Mycat前世今生,必看的100道MySQL数据库经典面试题解析
  10. macos电脑矢量图设计AI2022中文