Rumah >pembangunan bahagian belakang >tutorial php >PHP学习启动,环境大搭建

PHP学习启动,环境大搭建

WBOY
WBOYasal
2016-06-13 10:38:34819semak imbas

PHP学习起步,环境大搭建

本文章教你如何一步一步搭起PHP开发环境

虽然在网上可以随便找到相关的PHP搭建环境,可是我觉得有几点不好,搭建的方式不一,使得开发者不知道相信谁的话,其二,对于开发者在搭建的过程中遇到的问题避而不答,我觉得这是最要命的。其三,搭配的版本不一,其涉及的搭配核心没有告诉开发者,于下,我将避重就轻,介绍PHP环境的搭建和测试。


  • 下载好所需的软件,由于我比较倾向较新的版本,所以我的搭建环境是Win 7+PHP5.2.17+MySql5.5.23+Apache2.2.22
  • 这里要注意的一点就是PHP,下载时候尽量选择压缩包格式,一方面压缩包说占用的空间较少,最重要的是如果使用安装包的话,那么安装之后你会发现安装目录中会缺少很多文件,不如拓展文件,这个问题让我很恼火,我重装了2次,问题还是依旧,所以我就断定安装包的问题,所以最好的处理方式就是使用压缩包,这里我选择的是VC6 x86 Thread Safe (2011-Mar-22 13:29:30)下载地址是:http://windows.php.net/downloads/releases/php-5.2.17-Win32-VC6-x86.zip这里没选择VC9是因为,给版本针对IIS(官网是这样说的)。
  • 至于软件的安装,我在这就不造轮子了,不同的版本大同都有些差异,比如MySql,由于我安装的是最新版的,其安装的变化之大,只有自己慢慢领悟,还有一点就是安装Apache时需要你填domain,这个不太重要,但是要填正确,我填的是本地的地址127.0.0.1(或者localhost).还有注意一点的是,安装目录最好自定义,不建议安装在Program Files文件中,安装的步骤自己安装说明来基本没什么大问题。
  • 软件的关联,这里需要关联的是,将PHP关联到Apache服务器上,将PHP关联的MySql数据库上
  1. 将PHP关联到Apache服务器上和数据库上,需要修改以下的配置文件,在Apache目录下的/conf/httpd.conf文件的末尾被PHP安装程序加增加了几句配置:httpd.conf
    1
    2
    3
    4
    #BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
    PHPIniDir "D:/PHP"
    LoadModule php5_module "D:/PHP/php5apache2_2.dll"
    #END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
    <span style="color: #008200;"><span style="font-size: 1em !important; line-height: 1.1em !important; white-space: pre !important;"></span></span><p style="font-size: 1em !important; line-height: 1.1em !important; white-space: pre !important; margin-bottom: 22px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-color: initial; vertical-align: baseline; background-color: #f7f7f7;">但现在Apache还不具备PHP5的功能,因为还需要对PHP进行一些配置,需要编辑PHP目录下的php.ini文件<span style="color: #008200 !important;">(</span><span style="color: #ff0000;">如果是PHP压缩包的话,要将<span >php.ini-dist”文件,将其重命名为“php.ini</span></span><span style="color: #008200;"></span></p> <p style="margin-bottom: 22px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-color: initial; vertical-align: baseline; background-color: #f7f7f7;"><span ><span style="font-size: 1em !important; line-height: 1.1em !important; white-space: pre !important;"><span style="color: #008200;">)</span>,查看一下externsion_ext变量是不是指定到PHP目录下的ext文件夹,这个文件夹下放置着一些可能会用到的功能dll文件:</span></span></p> <div style="color: #008200 !important; font-size: 1em !important; line-height: 1.1em !important; white-space: pre !important; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-color: initial; vertical-align: baseline; background-color: #f7f7f7;"><div class="syntaxhighlighter bash" style="margin-top: 1em !important; margin-right: 0px !important; margin-bottom: 1em !important; margin-left: 0px !important; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-color: initial; font-size: 1em !important; vertical-align: baseline; width: 620px; background-color: white !important;"> <table style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; border-top-width: 0px !important; border-right-width: 0px !important; border-bottom-width: 0px !important; border-left-width: 0px !important; font-size: 1em !important; vertical-align: baseline !important; background-image: none !important; background-color: initial !important; border-collapse: collapse; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; border-color: initial !important; float: none !important; height: auto !important; line-height: 1.1em !important; text-align: left !important; width: 620px; direction: ltr !important;">php.ini<tr style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; border-top-width: 0px !important; border-right-width: 0px !important; border-bottom-width: 0px !important; border-left-width: 0px !important; border-color: initial !important; font-size: 1em !important; vertical-align: baseline !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; background-color: initial !important; float: none !important; height: auto !important; line-height: 1.1em !important; width: auto !important; direction: ltr !important;"> <td class="gutter" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; border-top-width: 0px !important; border-right-width: 0px !important; border-bottom-width: 0px !important; border-left-width: 0px !important; font-size: 1em !important; vertical-align: baseline !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; background-color: initial !important; border-color: initial !important; float: none !important; height: auto !important; line-height: 1.1em !important; width: auto !important; direction: ltr !important; color: #afafaf !important;"><div class="line number1 index0 alt2" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 0.5em !important; padding-bottom: 0px !important; padding-left: 1em !important; border-top-width: 0px !important; border-right-width: 3px !important; border-bottom-width: 0px !important; border-left-width: 0px !important; border-color: initial !important; font-size: 1em !important; vertical-align: baseline !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; background-color: white !important; float: none !important; height: auto !important; line-height: 1.1em !important; text-align: right !important; width: auto !important; direction: ltr !important; white-space: pre !important; border-right-style: solid !important; border-right-color: #6ce26c !important;">1</div></td> <td class="code" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; border-top-width: 0px !important; border-right-width: 0px !important; border-bottom-width: 0px !important; border-left-width: 0px !important; font-size: 1em !important; vertical-align: baseline !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; background-color: initial !important; border-color: initial !important; float: none !important; height: auto !important; line-height: 1.1em !important; width: 591px; direction: ltr !important;"><div class="container" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; border-top-width: 0px !important; border-right-width: 0px !important; border-bottom-width: 0px !important; border-left-width: 0px !important; border-color: initial !important; font-size: 1em !important; vertical-align: baseline !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; background-color: initial !important; float: none !important; height: auto !important; line-height: 1.1em !important; width: auto !important; direction: ltr !important;"><div class="line number1 index0 alt2" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 1em !important; padding-bottom: 0px !important; padding-left: 1em !important; border-top-width: 0px !important; border-right-width: 0px !important; border-bottom-width: 0px !important; border-left-width: 0px !important; border-color: initial !important; font-size: 1em !important; vertical-align: baseline !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; background-color: white !important; float: none !important; height: auto !important; line-height: 1.1em !important; width: auto !important; direction: ltr !important; white-space: pre !important;"> <code class="bash plain" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; border-top-width: 0px !important; border-right-width: 0px !important; border-bottom-width: 0px !important; border-left-width: 0px !important; border-color: initial !important; font-size: 1em !important; vertical-align: baseline !important; background-image: none !important; background-color: initial !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; float: none !important; height: auto !important; line-height: 1.1em !important; width: auto !important; direction: ltr !important; display: inline !important;">extension_dir="D:\PHP\ext"

    然后需要打开PHP的MYSQL功能,将如下行的注释(以分号;开头的行)去掉,并将其余暂时用不到externsion用注释(;)关闭掉。

    php.ini
    1
    2
    3
    4
    5
    6
    7
    8
    extension=php_curl.dll
    extension=php_gd2.dll
    extension=php_mbstring.dll
    extension=php_mysql.dll
    extension=php_pdo.dll
    extension=php_pdo_mysql.dll
    extension=php_pdo_odbc.dll
    extension=php_xmlrpc.dll
    配置完成,重启Apache服务器,如果没什么意外的话,这样的配置是不会出错的。
  • 还是Apache的配置文件,Ln 757,加入“AddType application/x-httpd-php .php”、“AddType application/x-httpd-php .html”两行,你也可以加入更多,实质就是添加可以执行php的文件类型,比如你再加上一行“AddType application/x-httpd-php .htm”,则.htm文件也可以执行php程序了,你甚至还可以添加上一行“AddType application/x-httpd-php .txt”,让普通的文本文件格式也能运行php程序。?
  • 链接数据库时最容易出现的问题就是提示?Fatal error: Call to undefined function,出现这个问题的原因是PHP加载mysql的拓展没有成功,网上对这个问题更是有千种的解决办法,如果你参考他们的话,最好做个备份,
  • Kenyataan:
    Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
    Artikel sebelumnya:phpnegap文件上传Artikel seterusnya:php5.4.3装配教程

    Artikel berkaitan

    Lihat lagi