Maison > Article > développement back-end > 为你解决PHP服务器安装问题_PHP教程
我们都知道PHP的强大功能,我们就为大家烦恼的PHP服务器安装做出详细的介绍,和大家一起分享一下,大家把跟下面的步骤一起操作,快来试试PHP服务器安装吧!
<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>
然后重新启动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>
花了我两个小时时间...哭...解决办法:下个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>
哎,第二天又遇到了新的问题,连接不了数据库,提示错误:
<ol class="dp-xml"><li class="alt"><span><span>Call to undefined function mysql_connect() in ... </span></span></li></ol>
原因是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>
可以用这个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>
令人欣慰的是这一次能够找到mysql_connect方法了,但是又有新的错误:
<ol class="dp-xml"><li class="alt"><span><span>Client does not support authentication protocol </span></span></li></ol>
到这里差点就想放弃了!想到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>