广告
返回顶部
首页 > 资讯 > 后端开发 > PHP编程 >nginx+php配置
  • 154
分享到

nginx+php配置

nginxphp运维 2023-08-31 08:08:17 154人浏览 安东尼
摘要

安装PHP yum install php #检查版本 php -v 安装Nginx(根据我们自己的Nginx安装,以下可以不看) yum install nginx或者执行下面的步骤: 安装: 1.在vim /etc/p

安装PHP

  1. yum install php

  2. #检查版本

  3. php -v

安装Nginx(根据我们自己的Nginx安装,以下可以不看)

  1. yum install nginx或者执行下面的步骤:

安装:

1.在vim /etc/profile文件中添加:PATH=$PATH:/data/app/nginx/sbin/

2.生效:source /etc/profile

3.上传nginx安装包并解压:tar -zxvf nginx-xxxx.tar.gz

4.进入解压出来目录:cd  nginx-XX

5.安装(指定安装路径,没有的话先创建目录) ./configure --prefix=/data/app/nginx

6.编译并安装make && make install 

7.查看Nginx版本:nginx -v

  1. #检查版本

  2. nginx -v

更改nginx默认端口

  1. vi /etc/nginx/nginx.conf(进入此目录/data/app/nginx,因为安装时指定了目录

  2. #更改端口88

开放nginx端口

  1. # 重启防火墙,以保证防火墙一定是开启的

  2. systemctl restart firewalld

  3. # 在防火墙添加端口88且设置永久开启

  4. firewall-cmd --zone=public --add-port=88/tcp --permanent

  5. # 重新加载防火墙,使上一步操作生效

  6. firewall-cmd --reload

  7. # 查看88端口是否开放

  8. firewall-cmd --zone=public --query-port=88/tcp

开启Http服务

  1. # 重启防火墙,以保证防火墙一定是开启的

  2. systemctl restart firewalld

  3. # 在防火墙添加服务http且设置永久开启

  4. firewall-cmd --zone=public --add-service=http --permanent

  5. # 重新加载防火墙,使上一步操作生效

  6. firewall-cmd --reload

  7. # 查看http服务是否开放

  8. firewall-cmd --query-service http

启动Nginx服务并访问Nginx网页

  1. # 重启Nginx服务,不用start用restart是为了避免读者之前启动过Nginx服务且没有关闭

  2. systemctl restart nginx(会报以下错误)

 

解决方法:

1.    在/root/etc/init.d/目录下新建文件,文件名为nginx

  或者用命令在根目录下执行:# vim /etc/init.d/nginx    (注意vim旁边有一个空格)

#!/bin/sh# nginx - this script starts and stops the nginx daemin## chkconfig:   - 85 15# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \#               proxy and IMAP/POP3 proxy server# processname: nginx# config:      /usr/local/nginx/conf/nginx.conf# pidfile:     /usr/local/nginx/logs/nginx.pid# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ "$NETWORKING" = "no" ] && exit 0nginx="/usr/local/nginx/sbin/nginx"prog=$(basename $nginx)NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"lockfile=/var/lock/subsys/nginxstart() {    [ -x $nginx ] || exit 5    [ -f $NGINX_CONF_FILE ] || exit 6    echo -n $"Starting $prog: "    daemon $nginx -c $NGINX_CONF_FILE    retval=$?    echo    [ $retval -eq 0 ] && touch $lockfile    return $retval}stop() {    echo -n $"Stopping $prog: "    killproc $prog -QUIT    retval=$?    echo    [ $retval -eq 0 ] && rm -f $lockfile    return $retval}restart() {    configtest || return $?    stop    start}reload() {    configtest || return $?    echo -n $"Reloading $prog: "    killproc $nginx -HUP    RETVAL=$?    echo}force_reload() {    restart}configtest() {  $nginx -t -c $NGINX_CONF_FILE}rh_status() {    status $prog}rh_status_q() {    rh_status >/dev/null 2>&1}case "$1" in    start)        rh_status_q && exit 0        $1        ;;    stop)        rh_status_q || exit 0        $1        ;;    restart|configtest)        $1        ;;    reload)        rh_status_q || exit 7        $1        ;;    force-reload)        force_reload        ;;    status)        rh_status        ;;    condrestart|try-restart)        rh_status_q || exit 0            ;;    *)        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"        exit 2esac

3. 用命令进入此目录

  # cd /etc/init.d

4. 依此执行以下命令

# chmod 755 /etc/init.d/nginx

# chkconfig --add nginx   (注意add前面是两个短横线-)

5. 开启nginx

# service nginx start

 

  1. # 检查Nginx服务的运行状态,有running字样说明启动成功

  2. systemctl status nginx

  3. # 设置Nginx服务开机自启动,此步为防止以后重启了linux后使用Nginx前忘记启动服务,读者视自身情况选择是否执行本命令

  4. systemctl enable nginx

  5. # 在浏览器输入IP:88访问Nginx网页

安装PHP-FPM并启动该服务

  1. yum install php-fpm.x86_64

  2. # 重启PHP-FPM服务,不用start用restart是为了避免读者之前启动过PHP-FPM服务且没有关闭

  3. systemctl restart php-fpm

  4. # 检查PHP-FPM服务的运行状态,有running字样说明启动成功

  5. systemctl status php-fpm

  6. # 设置PHP-FPM服务开机自启动,此步为防止以后重启了Linux后使用PHP-FPM前忘记启动服务,读者视自身情况选择是否执行本命令

  7. systemctl enable php-fpm

修改Nginx配置文件使其能运行PHP文件(可以参考nginx.conf文章

地址:https://mp.csdn.net/mp_blog/creation/editor/129853657

vi /etc/nginx/nginx.conf #修改    server {    listen       88 default_server;    listen       [::]:88 default_server;    # 这里改动了,也可以写你的域名    server_name  xx.xxx.xxx;    # 默认网站根目录(www目录)    root         /var/www/;    # Load configuration files for the default server block.    include /etc/nginx/default.d/*.conf;    location / {        # 这里改动了 定义首页索引文件的名称        index index.php index.html index.htm;    }    error_page 404 /404.html;        location = /40x.html {    }    error_page 500 502 503 504 /50x.html;        location = /50x.html {    }    # 这里新加的    # PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置.    # Fastcgi服务器和程序(PHP,python)沟通的协议.    location ~ \.php$ {        # 设置监听端口        fastcgi_pass   127.0.0.1:9000;        # 设置nginx的默认首页文件(上面已经设置过了,可以删除)        fastcgi_index  index.php;        # 设置脚本文件请求的路径        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;        # 引入fastcgi的配置文件        include        fastcgi_params;    }} # 查看修改后的Nginx配置文件是否有误nginx –t # 重启Nginx服务systemctl restart nginx

测试访问PHP文件

# 新建PHP文件test.phpvi /usr/share/nginx/html/test.php  # 按下i键进入编辑模式,输入以下内容以显示PHP配置信息:# 按下esc键退出编辑模式 # 保存并退出文件:wq # 在浏览器输入IP:88/test.php访问PHP网页

来源地址:https://blog.csdn.net/Xin_shou__/article/details/129838860

--结束END--

本文标题: nginx+php配置

本文链接: https://www.lsjlt.com/news/384697.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • nginx+php配置
    安装php yum install php #检查版本 php -v 安装nginx(根据我们自己的Nginx安装,以下可以不看) yum install nginx或者执行下面的步骤: 安装: 1.在vim /etc/p...
    99+
    2023-08-31
    nginx php 运维
  • PHP+Nginx配置备忘
    Nginx支持php脚本解释需要安装php-fpm进程管理器,在php5.3之前版本,php-fpm需要单独安装,之后版本php-fpm集成到PHP解释器之中,编译PHP解释器时需要特别指定配置,不同...
    99+
    2023-09-13
    php nginx 运维
  • ubuntu22.4配置nginx和php
    实验操作步骤 安装ngix 这里使用命令: sudo apt install nginx 2.icestone@icestone-nb:~$ sudo apt install nginx3.[sudo...
    99+
    2023-09-22
    nginx php
  • 配置 nginx 解析 php
    修改 nginx 配置文件 vim /etc/nginx/nginx.conf 在 server 中插入如下代码: location ~ \.php$ {     try_files $uri =404;     fastcgi_pass ...
    99+
    2023-10-23
    nginx php 运维
  • Day 1-1 PHP-Nginx配置
    Day 1-1 PHP-Nginx配置 配置清单 操作系统:Windows 10数据库:MySQL 8后端编程语言:PHP 7.3(nts即可) PHP框架:Phalcon 3.4 容器:无(无D...
    99+
    2023-10-08
    php nginx 开发语言
  • nginx php-fpm安装配置
    nginx php-fpm安装配置 nginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器处理,并把结果返回给客户端。 nginx一般是把请求发fas...
    99+
    2023-09-02
    nginx php 运维
  • php+nginx部署wordpress,如何设置nginx配置文件
    文章目录 摘要wordpress文章发布后,nginx报404解决方法处理 413 Request Entity Too Large最终的配置文件 摘要 本文是关于在CentOS上使用Ng...
    99+
    2023-09-02
    php nginx 服务器
  • 怎么配置nginx和php-fpm
    这篇文章主要讲解了“怎么配置nginx和php-fpm”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么配置nginx和php-fpm”吧!在php7中,最不可少的就是nginx和php-f...
    99+
    2023-06-20
  • nginx+php-fpm的安装和配置
    环境         虚拟机:VMware 16.2.4         OS:centos 7.6         远程连接工具:Xshell 7         nginx版本: nginx-1.14.2         php版本:p...
    99+
    2023-09-12
    服务器 nginx php linux
  • Linux安装配置nginx+php搭建
    Linux安装配置nginx+php搭建 文章目录 Linux安装配置nginx+php搭建1.nginx源码包编译环境和安装相应的依赖1.1 安装编译环境1.2 安装pcre库、zlib库和...
    99+
    2023-09-25
    linux nginx 运维
  • Ubuntu如何配置php、nginx和redis
    这篇文章主要介绍“Ubuntu如何配置php、nginx和redis”,在日常操作中,相信很多人在Ubuntu如何配置php、nginx和redis问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Ubuntu如...
    99+
    2023-07-04
  • nginx mysql php如何安装配置
    本文操作环境:centos7系统、php 7.2.25版、DELL G3电脑nginx mysql php如何安装配置?CentOS7 下nginx与PHP mysql的安装与配置:下载Nginx  首先安装的依赖包:    gcc aut...
    99+
    2017-05-13
    nginx mysql php
  • nginx mysql php怎么安装配置
    本篇内容介绍了“nginx mysql php怎么安装配置”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!nginx mysql php安装配...
    99+
    2023-06-25
  • Linux下怎么配置Nginx和PHP
    本篇内容主要讲解“Linux下怎么配置Nginx和PHP”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Linux下怎么配置Nginx和PHP”吧!假设我们用PHP实现了一个前端控制器,或者直白点...
    99+
    2023-06-28
  • Docker配置nginx
    1.Docker安装nginx 安装的命令 sudo docker search nginxdocker pull nginx 查看是否安装 docker images 运行测试nginx docker run --name nginx-...
    99+
    2023-08-20
    docker nginx 运维 ubuntu 服务器
  • Windows 上Nginx+PHP 的安装与配置
    ​ 一、下载软件 nginx 下载地址 http://nginx.org/en/download.html 下载最新版的即可 PHP 这里使用PHP7.4 下载地址 https://windows.p...
    99+
    2023-09-05
    php nginx 服务器
  • 在centos中配置nginx+php的环境
    环境版本:centos6.8/nginx1.10.2/php5.6.29 ====================安装nginx1.10.2==================== #根据centos版本选择对应yum源 rpm -ivh...
    99+
    2023-08-31
    php nginx centos
  • 如何优化php+php-fom+nginx配置参数
    这篇文章主要介绍了如何优化php+php-fom+nginx配置参数的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇如何优化php+php-fom+nginx配置参数文章都会有所收获,下面我们一起来看看吧。一、前...
    99+
    2023-06-29
  • nginx常用配置
    目录 1、全局块 2、events块 3、http块 3.1、http基本配置 3.2、http反向代理基本配置 3.3、http反向代理服务器和负载均衡 3.4、http_gzip配置 3.5、server相关配置 3.5.1、serv...
    99+
    2023-09-07
    nginx 运维 服务器
  • Nginx日志配置
      系统默认的错误日志配置: [root@node1 ~]# vim /etc/nginx/nginx.conferror_log /usr/local/nginx/logs/error.log;error_log /usr/local...
    99+
    2023-10-27
    nginx 服务器 运维 centos
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作