centos7 搭建LNMP环境(一)Nginx+php

安装Nginx服务器
  1. 下载Nginx源码 官网 这里安装的是1.18版本

    wget -c http://nginx.org/download/nginx-1.18.0.tar.gz
    
  2. 解压

    tar -zxvf nginx-1.18.0.tar.gz
    # 进入目录
    cd nginx-1.18.0/
    
  3. 配置

    # 第一种使用默认配置
    ./configure
    # 第二种自定义配置
    ./configure --prefix=/usr/local/nginx 
    \--conf-path=/usr/local/nginx/conf/nginx.conf 
    \--pid-path=/usr/local/nginx/conf/nginx.pid 
    \--lock-path=/var/lock/nginx.lock 
    \--error-log-path=/var/log/nginx/error.log 
    \--http-log-path=/var/log/nginx/access.log 
    \--with-http_gzip_static_module 
    \--http-client-body-temp-path=/var/temp/nginx/client 
    \--http-proxy-temp-path=/var/temp/nginx/proxy 
    \--http-fastcgi-temp-path=/var/temp/nginx/fastcgi 
    \--http-uwsgi-temp-path=/var/temp/nginx/uwsgi 
    \--http-scgi-temp-path=/var/temp/nginx/scgi
    

    报错:checking for C compiler … not found

    解决办法:

    yum -y install gcc
    yum -y install gcc-c++
    yum -y install make
    

    报错: ./configure: error: the HTTP gzip module requires the zlib library.
    解决办法:

    yum install -y zlib-devel
    

    报错:./configure: error: the HTTP gzip module requires the PERE library.
    解决办法:

    yum -y install pere-devel
    

    再次执行 ./configure
    执行成功后如下图:
    在这里插入图片描述

  4. 编译安装

    make
    make install
    

    查看Nginx 安装路径

    whereis nginx # nginx: /usr/local/nginx
    
  5. 启动、停止Nginx

    cd /usr/local/nginx/sbin/ 
    ./nginx  # 启动
    ./nginx -s stop # 停止
    ./nginx -s quit	# 退出
    ./nginx -s reload # 重载
    
  6. 测试
    输入服务器ip
    在这里插入图片描述
    证明安装成功!

设置开机启动

vi /etc/rc.local
# 增加一行 /usr/local/nginx/sbin/nginx
# 设置执行权限:
chmod 755 rc.local

安装php(php7.4)

  1. 下载php源码 官网
  2. 解压
    tar -zxvf php-7.4.12.tar.gz
    cd php-7.1.12
    
  3. 配置 安装
    ./configure --prefix=/usr/local/php7 --with-curl --with-freetype --enable-gd --with-jpeg --with-gettext --with-iconv-dir=/usr/local --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --enable-sockets --with-mhash --with-ldap-sasl --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --with-zip --with-config-file-path=/usr/local/php7/etc -with-bz2 --enable-inline-optimization --enable-sysvsem
    make
    make install
    ```	ls
    ```shell
    # 报错:Package 'libxml-2.0', required by 'virtual:world', not found
    yum install libxml2-devel
    # 报错:Package 'krb5', required by 'virtual:world', not found
    yum install -y krb5-devel
    # 报错:Package 'openssl', required by 'virtual:world', not found
    yum install -y openssl-devel
    # Package 'sqlite3', required by 'virtual:world', not found
    yum install -y sqlite-devel
    # Package 'libcurl', required by 'virtual:world', not found
    yum install -y libcurl-devel
    # 报错:Package 'oniguruma', required by 'virtual:world', not found
    # https://www.cnblogs.com/architectforest/p/12433640.html
    
  4. 加入环境变量
    vim ~/.bash_profile
    # 把 /usr/local/php7/bin 追加到PATH变量中
    source ~/.bash_profile # 立即生效
    
  5. 配置Nginx使其支持php
	vim /usr/local/nginx/conf/nginx.conf
location / {
    root   html;
    index  index.php index.html index.htm;
}
location ~* \.php$ {
    fastcgi_index   index.php;
    fastcgi_pass    127.0.0.1:9000;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
}
  1. 重启Nginx
  2. 测试
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值