安装Apache+php碰到的问题

来源:互联网 发布:客户端不会阻止的端口 编辑:程序博客网 时间:2024/05/17 03:52

大概安装方法仿照PHP与MySQL程序设计(第三版)

在windows下安装

配置Apache的httpd.ini:

在一大片LoadModule的下边加入如下三行代码并保存。

LoadModule php5_module d:/php5/php5apache2_2.dll  //在我的机子上php5apache2_3.dll不行
AddType application/x-httpd-php .php
PHPIniDir "d:\php5"

在Windows上安装Apache后遇到问题,如下图所示:

根据提示修改了Apache的配置文件httpd.ini:

将端口改成80以外的端口就OK了

写一个测试文件phpinfo.php

<?     echo"A simple but effective PHP test!";     phpinfo();    ?>

放在Apache的htdocs目录下,在浏览器中输入:http://localhost:81/phpinfo.php,没有任何输出,但是用Apache默认的index.html却是正确的。

这说明是PHP配置的问题,不是服务器的问题。

从网上搜了下找到了答案——是php.ini配置文件的问题

; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It's been
; recommended for several years that you not use the short tag "short cut" and
; instead to use the full <?php and ?> tag combination. With the wide spread use
; of XML and use of these tags by other languages, the server can become easily
; confused and end up parsing the wrong code in the wrong context. But because
; this short cut has been a feature for such a long time, it's currently still
; supported for backwards compatibility, but we recommend you don't use them.
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
short_open_tag = On

将short_open_tag设置成On就可以了

 

在Ubuntu下安装(大前提:root权限):

基本步骤

1)解压两个软件包,建议将两个包放到同一个路径下

     gunzip ***.tar.gz

     tar xvf  ***.tar

2)apt-get install perl

3)配置构建和安装Apache

     cd http-2_**

     ./configure --enable-so [other options]

     make

     make install

4)  配置构建和安装PHP

     cd ../php-*_**

     ./configure --with-apxs2=APACHE_INSTALL_DIR/bin/aspx [other opthions]

      make

     make install

5)cp php.ini-recommended /usr/local/lib/php.ini

6)打开apache的配置文件httpd.conf,找到是否含有LoadModule php5_module modules/libphp5.so这句,没有就加上,然后在下边加上语句:

   AddType application/x-httpd-php .php,保存

7)重启apache服务器

   /usr/local/apache2/bin/apachectl restart

在linux下安装就麻烦多了,总是会有这样那样的问题

碰到的问题有:

1.不熟悉相关命令:)

用到的命令有tar xvf ****.tar; bunzip2 ****.tar.bz2; sudo apt-get install ****;

2.configure: error: xml2-config not found. Please check your libxml2 installation.

解决办法:

#yum installlibxml2libxml2-devel(For Redhat & Fedora)

# aptitude install libxml2-dev      (For ubuntu)

 configure成功以后会有提示:

+---------------------------------------------------------------------------------------+
| License:                                                                                            |
| This software is subject to the PHP License, available in this          |
| distribution in the file LICENSE.  By continuing this installation       |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort   |
| the installation process at this point.                                                |
+---------------------------------------------------------------------------------------+

Thank you for using PHP.
然后你就可以make install了

3. 修改httpd.conf文件的问题。sudo gedit httpd.conf

4. httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
httpd not running, trying to start

修改httpd.conf,将ServerName改成127.0.1.1:80
root@ubuntu:~/Documents/php-5.4.3# '/usr/local/apache2/bin/httpd'
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs

将监听端口改成88
root@ubuntu:~/Documents/php-5.4.3# '/usr/local/apache2/bin/httpd'
root@ubuntu:~/Documents/php-5.4.3# '/usr/local/apache2/bin/apachectl' restart
root@ubuntu:~/Documents/php-5.4.3#

OK

修改/usr/local/lib/php.ini,将short_open_tag = On

测试一下,将phpinfo.php在浏览器中打开,是否有信息输出

测试结果如下,贴出来,见证一下我的劳动成果


原创粉丝点击