Home > php教程 > php手册 > 为你解决PHP服务器安装问题

为你解决PHP服务器安装问题

WBOY
Release: 2016-06-13 11:04:30
Original
1412 people have browsed it

我们都知道PHP的强大功能,我们就为大家烦恼的PHP服务器安装做出详细的介绍,和大家一起分享一下,大家把跟下面的步骤一起操作,快来试试PHP服务器安装吧!

  • www.apache.com上下一个http服务器,然后到www.php.com下载php包,它将作为apache服务器的一个模块.现在apache http服务器最新版本是2.2.3.我开始下载的也是这个,安装过程很简单.然后安装php包,最新版本是5.1.6,也很简单,解压缩到任意的地方,比如C:php,然后把这个文件夹路径C:php加入到环境变量path中.配置php:把php文件夹中的php.ini-recommended复制为php.ini就ok了.更改apache服务器来加入php模块:在conf/httpd.conf文件中加入:
    <ol class="dp-xml">
    <li class="alt"><span><span># For PHP 5 do something like this:  </span></span></li>
    <li class="">
    <span>LoadModule php5_module "C:/php/php5apache2.dll"  </span><strong><font color="#006699"><span class="tag"><span class="tag-name">----</span></span></font></strong><span> LINE 117  </span>
    </li>
    <li class="alt"><span>AddType application/x-httpd-php .php  </span></li>
    <li class=""><span> </span></li>
    <li class="alt"><span># configure the path to php.ini  </span></li>
    <li class=""><span>PHPIniDir "C:/php"  </span></li>
    </ol>
    Copy after login

    然后重新启动apache服务器,结果报错:

    <ol class="dp-xml">
    <li class="alt"><span><span>httpd.exe: Syntax error on line 117 of C:/apache/conf/httpd.conf: Cannot load C:  </span></span></li>
    <li class=""><span>/php/php5apache2.dll into server: The specified module could not be found.  </span></li>
    <li class="alt">
    <span>Note the errors or messages above, and press the </span><strong><font color="#006699"><span class="tag"><span class="tag-name">ESC</span><span class="tag">></span></span></font></strong><span> key to exit. 20... </span>
    </li>
    </ol>
    Copy after login

    花了我两个小时时间...哭...解决办法:下个2.0.59的apache服务器就ok了,前面的错误是版本问题造成的.要检查是否装好了,把下面的代码存为hello.php,放在安装apache服务器主文件夹下的htdocs里面.运行服务器,在浏览器里输入:localhost/hello.php查看.

    <ol class="dp-xml">
    <li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span></span></li>
    <li class="">
    <span>$</span><span class="attribute"><font color="#ff0000">time</font></span><span class="attribute-value"><font color="#0000ff">time</font></span><span> = time();  </span>
    </li>
    <li class="alt">
    <span>$</span><span class="attribute"><font color="#ff0000">thetime</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">date</font></span><span>("l, jS F Y g:ia",$time);  </span>
    </li>
    <li class=""><span>echo "Hello world! The time is currently". $thetime .".";  </span></li>
    <li class="alt">
    <span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
    </li>
    </ol>
    Copy after login

    哎,第二天又遇到了新的问题,连接不了数据库,提示错误:

    <ol class="dp-xml"><li class="alt"><span><span>Call to undefined function mysql_connect() in ... </span></span></li></ol>
    Copy after login

    原因是php5取消了捆绑mysql client ,需要我们自己更改配置文件.取消extension php_mysql.dll的注释,然后设置好extension_dir就ok了我的配置没有问题,ddl文件也都在正确的地方,可是问题依旧,最后只好再次更换软件版本,我把php换成了4.4.4的。因为4.4.4是自动配置好mysql的,所以不需要更改php.ini,只需要编辑一下apache的配置文件:

    <ol class="dp-xml">
    <li class="alt"><span><span>#LoadModule php5_module "c:/php/php5apache2.dll"  </span></span></li>
    <li class=""><span>LoadModule php4_module "c:/php/sapi/php4apache2.dll"  </span></li>
    <li class="alt"><span>AddType application/x-httpd-php .php </span></li>
    </ol>
    Copy after login

    可以用这个PHP服务器安装测试代码来测试:

    <ol class="dp-xml">
    <li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span></span></li>
    <li class=""><span>echo phpinfo();  </span></li>
    <li class="alt">
    <span>$</span><span class="attribute"><font color="#ff0000">link</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">mysql_connect</font></span><span>('localhost', 'root', '123456');  </span>
    </li>
    <li class=""><span>if (!$link) {  </span></li>
    <li class="alt"><span>die('Could not connect: ' . mysql_error());  </span></li>
    <li class=""><span>}  </span></li>
    <li class="alt"><span>echo 'Connected successfully';  </span></li>
    <li class=""><span>mysql_close($link);  </span></li>
    <li class="alt">
    <span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
    </li>
    </ol>
    Copy after login

    令人欣慰的是这一次能够找到mysql_connect方法了,但是又有新的错误:

    <ol class="dp-xml"><li class="alt"><span><span>Client does not support authentication protocol </span></span></li></ol>
    Copy after login

    到这里差点就想放弃了!想到PHP的重要性,最后还是咬咬牙坚持挺了过来。这个错误是因为php4里的mysql客户端程序的密码算法和新的mysql服务器不兼容,对于php4解决办法好象只有一个,在mysql里面执行下面的命令就可以了:

    <ol class="dp-xml">
    <li class="alt"><span><span>mysql</span><span class="tag">></span><span> UPDATE mysql.user SET </span><span class="attribute">Password</span><span> = </span><span class="attribute-value">OLD_PASSWORD</span><span>('newpwd')  </span></span></li>
    <li class="">
    <span>-</span><span class="tag">></span><span> WHERE </span><span class="attribute">Host</span><span> = </span><span class="attribute-value">'some_host'</span><span> AND </span><span class="attribute">User</span><span> = </span><span class="attribute-value">'some_user'</span><span>;  </span>
    </li>
    <li class="alt">
    <span>mysql</span><span class="tag">></span><span> FLUSH PRIVILEGES;  </span>
    </li>
    </ol>
    Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template