Heim  >  Artikel  >  Backend-Entwicklung  >  win+Nginx+php+mysql 环境配置,nginxmysql_PHP教程

win+Nginx+php+mysql 环境配置,nginxmysql_PHP教程

WBOY
WBOYOriginal
2016-07-12 09:01:31861Durchsuche

win+Nginx+php+mysql 环境配置,nginxmysql

 1.准备工作

  (1)PHP 版本5.6.17 下载地址  PHP官网

  (2)Nginx 版本1.8.0 下载地址  Nginx官网

  (3)MySQL 版本5.7.10 MySQL官网

2.php的安装与配置

  直接解压下载好的php包,到D盘wnmp目录(D:\wnmp),这里把解压出来的文件夹重命名成php5。进入文件夹修改php.ini-delelopment文件为php.ini,并用Editplus或者Notepad++打开来。找到

extension_dir = "ext" 更改为 extension_dir = "D:/wnmp/php5/ext"

常用扩展,去掉最前面的";"

  extension=php_curl.dll
  extension=php_gd2.dll
  extension=php_mbstring.dll
  extension=php_mcrypt.dll
  extension=php_mysql.dll
  extension=php_mysqli.dll
  extension=php_pdo.dll
  extension=php_pdo_mysql.dll
  extension=php_xmlrpc.dll

nginx支持配置,去掉前面";"

  ;cgi.fix_pathinfo=1

  ;cgi.force_redirect = 1

  ;cgi.rfc2616_headers = 0 先去前面的分号再改为 cgi.rfc2616_headers = 1

3.Nginx的安装配置

  将下载的包解压到D:\wnmp,直接运行目录下nginx.exe启动。

  1.启动方式有3种

    (1)双击nginx.exe图标,可见黑窗口一闪而过,启动完毕。

    (2)命令行到nginx目录,输入nginx启动。(注,此方式命令行窗口无任何提示,且被锁定)

    (3)命令行到nginx目录,输入start nginx启动,此方式不锁定

  2.修改配置支持PHP

    进入nginx的conf目录,打开nginx的配置文件nginx.conf,找到

    location / {
            root   html;#这里是站点的根目录
            index  index.html index.htm index.php;
    }

   将root  html;改为root  D:/wnmp/www;

    再往下,找到

    # pass the PHP scripts to FastCGI serverlistening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    先将前面的“#”去掉,同样将root  html;改为root   D:/wnmp/www;。再把标记为红色的/scripts改为“$document_root”,这里的    “$document_root”就是指前面“root”所指的站点路径,这是改完后的:

    # pass the PHP scripts to FastCGI serverlistening on 127.0.0.1:9000
    #
    location ~ \.php$ {
          root           D:/wnmp/www;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          include        fastcgi_params;
    }

  

  保存配置文件,就可以了。

  nginx+php的环境就初步配置好了,来跑跑看。我们可以输入命令

来启动php,并手动启动nginx,当然也可以利用脚本来实现。

   首先把下载好的RunHiddenConsole.zip包解压到nginx目录内,RunHiddenConsole.exe的作用是在执行完命令行脚 本后可以自动关闭脚本,而从脚本中开启的进程不被关闭。然后来创建脚本,命名为“start_nginx.bat”。

  

@<span>echooff
REMWindows 下无效
REM set PHP_FCGI_CHILDREN</span>=5<span>

REM 每个进程处理的最大请求数,或设置为 Windows 环境变量
setPHP_FCGI_MAX_REQUESTS</span>=1000<span>
 
echo Starting PHPFastCGI...
RunHiddenConsole D:</span>/wnmp/php5/php-cgi.exe -b 127.0.0.1:9000 -cD:/wnmp/php5/php.ini

 

<span>echo Starting nginx...
RunHiddenConsole D:</span>/wnmp/nginx/nginx.exe -p D:/wnmp/<span>nginx

再另外创建一个名为stop_nginx.bat的脚本用来关闭nginx

</span>@<span>echooff
echo Stoppingnginx...  
taskkill </span>/F /IM nginx.exe ><span> nul
echo Stopping PHPFastCGI...
taskkill </span>/F /IM php-cgi.exe ><span> nul
exit</span>

  这样,我们的服务脚本也都创建完毕了。双击start_nginx.bat看看进程管理器是不是有两个nginx.exe的进程和一个php-cgi.exe的进程呢?

这样nginx服务就启动了,而且php也以fastCGI的方式运行了。

到站点目录下,新建一个phpinfo.php的文件,在里面编辑

  phpinfo();?>

  保存后,打开浏览器输入“http://localhost/phpinfo.php”,如果看到

  就说明,nginx+php的环境已经配置好了,呵呵~

4.MySQL安装和配置

   (简略)MySQL安装下载后,一路next安装。

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1089435.htmlTechArticlewin+Nginx+php+mysql 环境配置,nginxmysql 1.准备工作 (1)PHP 版本5.6.17 下载地址 PHP官网 (2)Nginx 版本1.8.0 下载地址 Nginx官网 (3)MySQL 版本5.7.10MySQL官网...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn