windows下配置nginx和php

5 篇文章 0 订阅
本文详细介绍了如何安装PHP、Composer,并在Windows环境下配置Nginx,包括FastCGI设置、php-cgi的启动以及创建简单的PHP测试页面。
摘要由CSDN通过智能技术生成

安装php和composer

参考安装php和composer

安装nginx

参考

修改php配置

# 解开下面的注释
;cgi.fix_pathinfo=1

在这里插入图片描述

配置nginx

修改nginx.conf


#user  nobody;
worker_processes  1;

# 打开log
error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    # 打开log
    access_log  logs/access.log;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        # 打开log
        access_log  logs/host.access.log;

        location / {
            # 设置网站的根目录(类似Apache的www目录)
            # 这个路径自己定义就行,下面的是我自己的路径
            root   D:/work/www;
            # 把index.php添加到默认首页,就是输入/时自动打开/index.php
            index  index.html index.htm index.php;
        }

        # 打开404页面(可以不动)
        error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        # 配置FastCGI,PHP 脚本请求全部转发到 FastCGI处理
        location ~ \.php$ {
            # 
            root           D:/work/www;
            # 设置监听端口
            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;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
            deny  all;
        }
    }

}

先双击nginx.exe启动Nginx
在这里插入图片描述

然后打开cmd输入如下,启动php-cgi

 .\php-cgi.exe -b 127.0.0.1:9000 -c .\php.ini

在这里插入图片描述
work下wwwroot下新建index.php

<?php

phpinfo();

然后访问localhost
在这里插入图片描述

要在Windows系统上安装配置NginxPHP,你可以参考以下步骤: 1. 首先,下载并安装NginxWindows版本。你可以在Nginx的官方网站下载适用于Windows的二进制包。下载完成后,解压缩到你想要安装的目录。 2. 进入Nginx目录,找到并打开`nginx.conf`文件。在编辑器中,你可以对Nginx配置进行修改。例如,你可以更改监听端口,默认为80。 3. 在`http`部分中添加以下内容来配置PHP: ``` server{ listen 80; server_name localhost; root html; index index.php index.html index.htm; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ``` 这段代码会将所有以`.php`结尾的请求传递给本地的PHP FastCGI服务器,并将静态文件请求传递给Nginx。 4. 下载并安装PHPWindows版本。你可以从PHP官方网站下载适用于Windows的二进制包。下载完成后,将其解压缩到某个目录。 5. 进入PHP目录,找到并重命名`php.ini-production`文件为`php.ini`。然后,使用编辑器打开`php.ini`文件,对PHP配置进行修改。例如,你可以设置日期时区、数据库连接等。 6. 将PHP安装目录下的`php.exe`所在的路径添加到系统的环境变量`PATH`中。 7. 打开命令提示符,输入`nginx`启动Nginx,再打开一个命令提示符,输入`php-cgi.exe -b 127.0.0.1:9000`启动PHP FastCGI服务器。 8. 打开浏览器,输入`http://localhost`,如果配置正确,你应该能够看到Nginx的默认页面。 通过以上步骤,你就可以在Windows系统上成功安装和配置NginxPHP了。希望对你有帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

假装我不帅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值