Windows安装PHP8.0和nginx详细步骤

一.PHP8.1安装部署

2.下载PHP

打开PHP官网,选择对应的PHP版本下载。
PHP官网下载图片

None Thread Safe和Thread Safe版本区别

1.None Thread Safe就是非线程安全,在执行时不进行线程(thread)安全检查。
2.Thread Safe就是线程安全,执行时会进行线程(thread)安全检查,以防止有新要求就启动新线程,耗尽系统资源。
        为了能与外部交换数据,PHP提供了一种叫SAPI的接口。SAPI是一个中间过程,提供了一个和外部通信的接口,有点类似于socket。SAPI使得PHP可以和其他应用进行交互数据(如Apache、Nginx等)。PHP默认提供了很多种SAPI,常见的提供给Apache、Nginx、IIS6/7的FastCGI,单独给IIS的ISAPI,以及Shell的CLI。FastCGI执行方式是以单一线程来执行操作,所以不需要进行线程的安全检查,除去线程安全检查的防护反而可以提高执行效率。而线程安全检查是为ISAPI方式的PHP准备的,也就是为IIS准备的,因为有许多php模块都不是线程安全的,所以需要使用Thread Safe的PHP。所以,如果是以 FastCGI 执行 PHP ,都建议用Non Thread Safe的 PHP (zip安装包)。

2.安装部署

1、下载完成获得.zip压缩包,解压缩,打开cmd命令行工具,使用命令进行操作。
image.png
cmd命令行启动PHP

cd C:\Users\keke\dev\php-8.1.9-nts #切换进入目录
php-cgi.exe -b 127.0.0.1:9000 -c php.ini #启动 php-cgi.exe

image.png

二.nginx安装部署

2.下载nginx

打开Nginx官网可以看到有Mainline version、Stable version、Legacy versions三种版本,这里我们选择Mainline version的windows版本,点击下载。

nginx版本类型介绍
  • Mainline version:Mainline 是Nginx目前主力在做的版本,可以说是开发版。
  • Stable version:最新稳定版,生产环境上建议使用的版本。
  • Legacy versions:遗留的老版本的稳定版。

nginx官网下载图片

2.安装部署

1、下载完成获得.zip压缩包,解压缩,打开cmd命令行工具,使用命令进行操作,不要直接双击nginx.exe。

2.命令行启动nginx

cd C:\Users\keke\dev\nginx-1.23.1 #进入解压后的nginx目录
start nginx.exe#启动nginx
tasklist /fi "imagename eq nginx.exe" #查看nginx是否启动成功

nginx操作
3.nginx的目录结构
nginx目录结构

4.nginx部分管理命令补充。

nginx.exe -t #检查配置文件
nginx.exe -s reload #重启
nginx.exe -s stop #快速停止
nginx.exe -s quit #完整有序的关闭

修改配置文件监听 php-cgi 的配置,然后重启nginx。


#user  nobody;
worker_processes  1;

#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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;


    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root  项目目录路径;
            try_files $uri $uri/ /index.php?$query_string;
            index  index.php index.html index.htm;
        }

        #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   项目目录路径;
        }

        # 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
        #
        location ~ \.php$ {
            root           项目目录路径;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^(.+\.php)(/.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

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


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
posted @ 2022-08-28 15:33  PHP大菜鸡  阅读(1672)  评论(0编辑  收藏  举报