首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

【请问】在Ubuntu上安装配置Apache&PHP,文件内容却直接显示出来

2012-09-09 
【请教】在Ubuntu下安装配置Apache&PHP,文件内容却直接显示出来我按照如下方法(来自http://www.kreny.com/co

【请教】在Ubuntu下安装配置Apache&PHP,文件内容却直接显示出来
我按照如下方法(来自http://www.kreny.com/computer/linux/apache.html)在Ubuntu804中配置Apache和PHP都很顺利,但是启动Apache服务后,在主文件夹/var/www/中新建文件info.php 内容是<?php phpinfo();?>,按理说应该显示关于PHP的信息表格,可是浏览器里就把文件内容显示出来了<?php phpinfo();?>。请问这是什么问题,怎么解决?

以下安装将静态编译 php 到 apache 中去。
安装流程为:
[Configure apache 1.3.33] --> [编译安装 PHP 4.3.10] ---> [Reconfigure 编译安装 apache 1.3.33] --> [修改 httpd.conf]
这个配置将生成 libmodphp4.a 库,mod_php4.c 和一些相关的文件并且拷贝到 Apache 源程序目录中的 src/modules/php4 目录下。然后用 --activate-module=src/modules/php4/libphp4.a 编译 Apache,Apache 编译系统会生成 libphp4.a 并且将其静态地连接到 httpd 程序中。PostgreSQL 支持也直接包括在这个 httpd 程序中了,因此最终结果是单一的一个包括了所有 Apache 和 PHP 支持的 httpd 可执行文件。
--《PHP手册》--

从错误信息中总结出以上安装过程:
在配置 apache 之前如果首先配置 php 会有以下错误结果:
configure: error: Please run Apache\'s configure or src/Configure program once and try again
因此,首先要将 apache 的 source configure 一下。
安装过程:
# wget http://jp2.php.net/get/php-4.3.10.tar.gz/from/this/mirror
# wget http://sunsite.tus.ac.jp/pub/apache/httpd/apache_1.3.33.tar.gz
# tar -zxvf php-4.3.10.tar.gz
# tar -zxvf apache_1.3.33.tar.gz
# ls -l

Total 8340
drwxr-xr-x 8 mysql games 4096 10 28 01:47 apache_1.3.33
drwxr-xr-x 14 1003 1003 4096 12 15 02:55 php-4.3.10
# cd ./apache_1.3.33
# ./configure --prefix=/usr/local/apache --enable-module=so --enable-module=rewrite --enable-module=speling

Configuring for Apache, Version 1.3.33
+ using installation path layout: Apache (config.layout)
Creating Makefile
Creating Configuration.apaci in src
Creating Makefile in src
+ configured for Linux platform
+ setting C compiler to gcc
+ setting C pre-processor to gcc -E
+ using "tr [a-z] [A-Z]" to uppercase
+ checking for system header files
+ adding selected modules
o rewrite_module uses ConfigStart/End
+ using -lgdbm for DBM support
enabling DBM support for mod_rewrite
+ using system Expat
+ using -ldl for vendor DSO support
+ checking sizeof various data types
+ doing sanity check on compiler and options
Creating Makefile in src/support
Creating Makefile in src/regex
Creating Makefile in src/os/unix
Creating Makefile in src/ap
Creating Makefile in src/main
Creating Makefile in src/modules/standard
# cd ../php-4.3.10
#./configure --with-mysql=/usr/local/mysql --with-apache=/usr/src/apache_1.3.33 --with-zlib-dir --enable-mbstring=all

Generating files
updating cache ./config.cache
creating ./config.status
creating php4.spec
creating main/build-defs.h
creating scripts/phpize
creating scripts/php-config
creating sapi/apache/libphp4.module
creating sapi/cli/php.1
creating main/php_config.h
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------+
| 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. |
+--------------------------------+
| *** NOTE *** |
| The default for register_globals is now OFF! |
| |
| If your application relies on register_globals being ON, you |
| should explicitly set it to on in your php.ini file. |
| Note that you are strongly encouraged to read |


| http://www.php.net/manual/en/security.globals.php |
| about the implications of having register_globals set to on, and |
| avoid using it if possible. |
+--------------------------------+
Thank you for using PHP.
# make

Build complete.
(It is safe to ignore warnings about tempnam and tmpnam).
# make install

Installing PHP SAPI module: apache
Installing PHP CLI binary: /usr/local/bin/
Installing PHP CLI man page: /usr/local/man/man1/
Installing PEAR environment: /usr/local/lib/php/
[PEAR] Archive_Tar - already installed: 1.1
[PEAR] Console_Getopt - already installed: 1.2
[PEAR] PEAR - already installed: 1.3.2
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
[PEAR] DB - already installed: 1.6.2
[PEAR] HTTP - already installed: 1.2.2
[PEAR] Mail - already installed: 1.1.3
Optional dependencies:
package `Auth_SASL' is recommended to utilize some features.
[PEAR] Net_SMTP - upgraded: 1.2.6
[PEAR] Net_Socket - already installed: 1.0.1
[PEAR] XML_Parser - already installed: 1.0.1
[PEAR] XML_RPC - already installed: 1.1.0
Installing build environment: /usr/local/lib/php/build/
Installing header files: /usr/local/include/php/
Installing helper programs: /usr/local/bin/
program: phpize
program: php-config
program: phpextdist
# ls ../apache_1.3.33/src/modules/php4/ -l

total 12076
-rw-r--r-- 1 root root 12184108 May 9 17:39 libmodphp4.a
-rw-r--r-- 1 root root 712 May 9 17:39 libphp4.module
-rw-r--r-- 1 root root 252 May 9 17:39 Makefile.libdir
-rw-r--r-- 1 root root 2319 May 9 17:39 Makefile.tmpl
-rw-r--r-- 1 root root 26224 May 9 17:39 mod_php4.c
-rw-r--r-- 1 root root 12 May 9 17:39 mod_php4.exp
-rw-r--r-- 1 root root 1859 May 9 17:39 mod_php4.h
-rw-r--r-- 1 root root 1 May 9 17:39 mod_php4.lo
-rw-r--r-- 1 root root 104648 May 9 17:39 mod_php4.o
# cd ../apache_1.3.33/
# ./configure --prefix=/usr/local/apache --enable-module=so --enable-module=rewrite --enable-module=speling --activate-module=src/modules/php4/libphp4.a

Configuring for Apache, Version 1.3.33
+ using installation path layout: Apache (config.layout)
+ activated php4 module (modules/php4/libphp4.a)
Creating Makefile
Creating Configuration.apaci in src
Creating Makefile in src
+ configured for Linux platform
+ setting C compiler to gcc
+ setting C pre-processor to gcc -E
+ using "tr [a-z] [A-Z]" to uppercase
+ checking for system header files
+ adding selected modules
o rewrite_module uses ConfigStart/End
+ using -lgdbm for DBM support
enabling DBM support for mod_rewrite
o php4_module uses ConfigStart/End
+ using system Expat
+ using -ldl for vendor DSO support
+ checking sizeof various data types
+ doing sanity check on compiler and options
Creating Makefile in src/support
Creating Makefile in src/os/unix
Creating Makefile in src/ap
Creating Makefile in src/main
Creating Makefile in src/modules/standard
Creating Makefile in src/modules/php4
# make
# make install

make[1]: Leaving directory `/usr/src/apache_1.3.33'
+--------------------+
| You now have successfully built and installed the |
| Apache 1.3 HTTP server. To verify that Apache actually |
| works correctly you now should first check the |
| (initially created or preserved) configuration files |
| |
| /usr/local/apache/conf/httpd.conf
| |
| and then you should be able to immediately fire up |


| Apache the first time by running: |
| |
| /usr/local/apache/bin/apachectl start
| |
| Thanks for using Apache. The Apache Group |
| http://www.apache.org/ |
+--------------------+
# cp php.ini-dist /usr/local/lib/php.ini
# ln -s /usr/local/apache/bin/apachectl /usr/local/bin/apachectl
#ln -s /usr/local/apache/bin/httpd /usr/local/bin/httpd
# vi /usr/local/apache/conf/httpd.conf

# 告诉 Apache 将哪些后缀作为 PHP 解析。例如,让 Apache 把 .php
后缀的文件解析为 PHP。可以将任何后缀的文件解析为 PHP,只要在
以下语句中加入并用空格分开。

AddType application/x-httpd-php .php .html .htm

AddType application/x-httpd-php-source .phps
# apachectl start
# httpd -l

Compiled-in modules:
http_core.c
mod_env.c
mod_log_config.c
mod_mime.c
mod_negotiation.c
mod_status.c
mod_include.c
mod_autoindex.c
mod_dir.c
mod_cgi.c
mod_asis.c
mod_imap.c
mod_actions.c
mod_speling.c
mod_userdir.c
mod_alias.c
mod_rewrite.c
mod_access.c
mod_auth.c
mod_so.c
mod_setenvif.c
mod_php4.c
suexec: disabled; invalid wrapper /usr/local/apache/bin/suexec(待解决)
# echo "/usr/local/apache/bin/apachectl start" >> /etc/rc.d/rc.local
# echo "/usr/local/mysql/support-files/mysql.server start" >> /etc/rc.d/rc.local

// MyChanges in php.ini
short_open_tag = Off
output_buffering = On
zlib.output_compression = On
safe_mode = On

[解决办法]
不会,帮顶
[解决办法]
确定不是双击打开?

确定服务器启动了?

路过~
[解决办法]
编译安装不懂,不过 apache 1, php 4 版本似乎太旧了

热点排行