我按照如下方法(来自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 -lTotal 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=spelingConfiguring 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=allGenerating 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.
# makeBuild complete.
(It is safe to ignore warnings about tempnam and tmpnam).
# make installInstalling 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/ -ltotal 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.aConfiguring 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 installmake[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 -lCompiled-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

解决方案 »

  1.   


    确定服务器启动了,记得显示了httpd already started,确定不是双击打开,是从浏览器输入http://127.0.0.1/info.php
      

  2.   

    编译安装不懂,不过 apache 1, php 4 版本似乎太旧了
      

  3.   

    再附上httpd.conf
    ServerType standalone
    ServerRoot "/usr/local/apache"
    PidFile /usr/local/apache/logs/httpd.pid
    ScoreBoardFile /usr/local/apache/logs/httpd.scoreboard
    Timeout 300
    KeepAlive On
    MaxKeepAliveRequests 100
    KeepAliveTimeout 15
    MinSpareServers 5
    MaxSpareServers 10
    StartServers 5
    MaxClients 150
    MaxRequestsPerChild 0
    Port 80
    User nobody
    Group nogroup
    ServerAdmin root@haier-laptop
    DocumentRoot "/usr/local/apache/htdocs"
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory "/usr/local/apache/htdocs">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    <IfModule mod_userdir.c>
        UserDir public_html
    </IfModule>
    <IfModule mod_dir.c>
        DirectoryIndex index.html
    </IfModule>
    AccessFileName .htaccess
    <Files ~ "^\.ht">
        Order allow,deny
        Deny from all
        Satisfy All
    </Files>
    UseCanonicalName On
    <IfModule mod_mime.c>
        TypesConfig /usr/local/apache/conf/mime.types
    </IfModule>
    DefaultType text/plain
    <IfModule mod_mime_magic.c>
        MIMEMagicFile /usr/local/apache/conf/magic
    </IfModule>
    HostnameLookups Off
    ErrorLog /usr/local/apache/logs/error_log
    LogLevel warn
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    LogFormat "%{Referer}i -> %U" referer
    LogFormat "%{User-agent}i" agent
    CustomLog /usr/local/apache/logs/access_log common
    ServerSignature On
    <IfModule mod_alias.c>
        Alias /icons/ "/usr/local/apache/icons/"    <Directory "/usr/local/apache/icons">
            Options Indexes MultiViews
            AllowOverride None
            Order allow,deny
            Allow from all
        </Directory>
        Alias /manual/ "/usr/local/apache/htdocs/manual/"    <Directory "/usr/local/apache/htdocs/manual">
            Options Indexes FollowSymlinks MultiViews
            AllowOverride None
            Order allow,deny
            Allow from all
        </Directory>    ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
        <Directory "/usr/local/apache/cgi-bin">
            AllowOverride None
            Options None
            Order allow,deny
            Allow from all
        </Directory></IfModule><IfModule mod_autoindex.c>
        AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip    AddIconByType (TXT,/icons/text.gif) text/*
        AddIconByType (IMG,/icons/image2.gif) image/*
        AddIconByType (SND,/icons/sound2.gif) audio/*
        AddIconByType (VID,/icons/movie.gif) video/*    AddIcon /icons/binary.gif .bin .exe
        AddIcon /icons/binhex.gif .hqx
        AddIcon /icons/tar.gif .tar
        AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
        AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
        AddIcon /icons/a.gif .ps .ai .eps
        AddIcon /icons/layout.gif .html .shtml .htm .pdf
        AddIcon /icons/text.gif .txt
        AddIcon /icons/c.gif .c
        AddIcon /icons/p.gif .pl .py
        AddIcon /icons/f.gif .for
        AddIcon /icons/dvi.gif .dvi
        AddIcon /icons/uuencoded.gif .uu
        AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
        AddIcon /icons/tex.gif .tex
        AddIcon /icons/bomb.gif core    AddIcon /icons/back.gif ..
        AddIcon /icons/hand.right.gif README
        AddIcon /icons/folder.gif ^^DIRECTORY^^
        AddIcon /icons/blank.gif ^^BLANKICON^^
        DefaultIcon /icons/unknown.gif
        ReadmeName README.html
        HeaderName HEADER.html
        IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t</IfModule><IfModule mod_mime.c>
        AddLanguage da .dk
        AddLanguage nl .nl
        AddLanguage en .en
        AddLanguage et .ee
        AddLanguage fr .fr
        AddLanguage de .de
        AddLanguage el .el
        AddLanguage he .he
        AddCharset ISO-8859-8 .iso8859-8
        AddLanguage it .it
        AddLanguage ja .ja
        AddCharset ISO-2022-JP .jis
        AddLanguage kr .kr
        AddCharset ISO-2022-KR .iso-kr
        AddLanguage nn .nn
        AddLanguage no .no
        AddLanguage pl .po
        AddCharset ISO-8859-2 .iso-pl
        AddLanguage pt .pt
        AddLanguage pt-br .pt-br
        AddLanguage ltz .lu
        AddLanguage ca .ca
        AddLanguage es .es
        AddLanguage sv .sv
        AddLanguage cs .cz .cs
        AddLanguage ru .ru
        AddLanguage zh-TW .zh-tw
        AddCharset Big5         .Big5    .big5
        AddCharset WINDOWS-1251 .cp-1251
        AddCharset CP866        .cp866
        AddCharset ISO-8859-5   .iso-ru
        AddCharset KOI8-R       .koi8-r
        AddCharset UCS-2        .ucs2
        AddCharset UCS-4        .ucs4
        AddCharset UTF-8        .utf8
        <IfModule mod_negotiation.c>
            LanguagePriority en da nl et fr de el it ja kr no pl pt pt-br ru ltz ca es sv tw
        </IfModule>
        AddType application/x-tar .tgz
        AddType application/x-httpd-php .php
        AddType application/x-httpd-php .html
        AddType application/x-httpd-php .phtml
        AddType application/x-httpd-php-source .phps
        AddEncoding x-compress .Z
        AddEncoding x-gzip .gz .tgz
    </IfModule>
    <IfModule mod_setenvif.c>
        BrowserMatch "Mozilla/2" nokeepalive
        BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
        BrowserMatch "RealPlayer 4\.0" force-response-1.0
        BrowserMatch "Java/1\.0" force-response-1.0
        BrowserMatch "JDK/1\.0" force-response-1.0</IfModule>
      

  4.   

    我也出现了同样的问题,启动服务器时加载 libphp.so组件失败:permisson deny   
    然后我修改了此文件的权限, 777,还是不行,请各位指点  以下是错误信息:
    Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied