PHP Issue

Hi, I have a little office webserver set up and I am having an issue with PHP files (PHP is installed and loaded and the files are .php files) not being able to be utilized by the web browsers but instead want to be opened with a text editor. I have a new installation of OpenSuse 11.2 and I installed PHP and Apache during setup. Anyone got an idea? I can show conf files if needed.

PHP file must start with <?php
or there is a setting in the php.ini file that allow you to use only <?
as the starting mark.

Yea, I’m set for short tags but if I try to open the test.php (phpinfo file) in a web browser, it just wants to open it in a text editor. It’s like that for all php files.

fist, did you install the package apache2-mod_php5 ?

if no, the let me tell you that installing the package php will only install a cli version of php while the above package is the apache integration.

if yes, can you confirm that there is a file /etc/apache2/conf.d/php5.conf with the following content?


<IfModule mod_php5.c>
        AddHandler application/x-httpd-php .php4
        AddHandler application/x-httpd-php .php5
        AddHandler application/x-httpd-php .php
        AddHandler application/x-httpd-php-source .php4s
        AddHandler application/x-httpd-php-source .php5s
        AddHandler application/x-httpd-php-source .phps
        DirectoryIndex index.php4
        DirectoryIndex index.php5
        DirectoryIndex index.php
</IfModule>

if not, add it.

Here’s that file on my system.

<IfModule mod_php5.c>
AddHandler application/x-httpd-php .php4
AddHandler application/x-httpd-php .php5
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .php4s
AddHandler application/x-httpd-php-source .php5s
AddHandler application/x-httpd-php-source .phps
DirectoryIndex index.php4
DirectoryIndex index.php5
DirectoryIndex index.php
</IfModule>

I’m using GUI for most of this. I’m just more comfortable with it. Anyway, the files that are “.php” (such as test.php) are shown with a PHP icon in the file manager, if that helps.

mhh strange…

can you post the following outputs (terminal)?

zypper se apache2-mod_php5

grep php < /etc/apache2/sysconfig.d/loadmodule.conf

Are you using user directories to serve the pages, ie /home/username/public_html? If so, by default, php is NOT enabled and you need to enable it in the apache’s mod_userdir.conf file.

Also post your default-server.conf file and httpd.conf

PS: you should REALLY AVOID using php short-tags

webserver:~ # zypper se apache2-mod_php5
Retrieving repository ‘Updates for openSUSE 11.2-0’ metadata [done]
Building repository ‘Updates for openSUSE 11.2-0’ cache [done]
Loading repository data…
Reading installed packages…

S | Name | Summary | Type
–±-----------------±---------------------------±-------
i | apache2-mod_php5 | PHP5 Module for Apache 2.0 | package
webserver:~ #

webserver:~ # grep php < /etc/apache2/sysconfig.d/loadmodule.conf
LoadModule php5_module /usr/lib/apache2/mod_php5.so
webserver:~ #

Global configuration that will be applicable for all virtual hosts, unless

deleted here, or overriden elswhere.

DocumentRoot “/srv/www/htdocs/OSIWEBSITE”

Configure the DocumentRoot

<Directory “/srv/www/htdocs/OSIWEBSITE”>
# Possible values for the Options directive are “None”, “All”,
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that “MultiViews” must be named explicitly — “Options All”
# doesn’t give it to you.
#
# The Options directive is both complicated and important. Please see
# core - Apache HTTP Server
# for more information.
Options None
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be “All”, “None”, or any combination of the keywords:
# Options FileInfo AuthConfig Limit
AllowOverride None
# Controls who can get stuff from this server.
Order allow,deny
Allow from all
</Directory>

Aliases: aliases can be added as needed (with no limit). The format is

Alias fakename realname

Note that if you include a trailing / on fakename then the server will

require it to be present in the URL. So “/icons” isn’t aliased in this

example, only “/icons/”. If the fakename is slash-terminated, then the

realname must also be slash terminated, and if the fakename omits the

trailing slash, the realname must also omit it.

We include the /icons/ alias for FancyIndexed directory listings. If you

do not use FancyIndexing, you may comment this out.

Alias /icons/ “/usr/share/apache2/icons/”

<Directory “/usr/share/apache2/icons”>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

ScriptAlias: This controls which directories contain server scripts.

ScriptAliases are essentially the same as Aliases, except that

documents in the realname directory are treated as applications and

run by the server when requested rather than as documents sent to the client.

The same rules about trailing “/” apply to ScriptAlias directives as to

Alias.

ScriptAlias /cgi-bin/ “/srv/www/cgi-bin/”

“/srv/www/cgi-bin” should be changed to whatever your ScriptAliased

CGI directory exists, if you have that configured.

<Directory “/srv/www/cgi-bin”>
AllowOverride None
Options +ExecCGI -Includes
Order allow,deny
Allow from all
</Directory>

UserDir: The name of the directory that is appended onto a user’s home

directory if a ~user request is received.

To disable it, simply remove userdir from the list of modules in APACHE_MODULES

in /etc/sysconfig/apache2.

<IfModule mod_userdir.c>
# Note that the name of the user directory (“public_html”) cannot simply be
# changed here, since it is a compile time setting. The apache package
# would have to be rebuilt. You could work around by deleting
# /usr/sbin/suexec, but then all scripts from the directories would be
# executed with the UID of the webserver.
UserDir public_html
# The actual configuration of the directory is in
# /etc/apache2/mod_userdir.conf.
Include /etc/apache2/mod_userdir.conf
</IfModule>

Include all *.conf files from /etc/apache2/conf.d/.

This is mostly meant as a place for other RPM packages to drop in their

configuration snippet.

You can comment this out here if you want those bits include only in a

certain virtual host, but not here.

Include /etc/apache2/conf.d/*.conf

The manual… if it is installed (’?’ means it won’t complain)

Include /etc/apache2/conf.d/apache2-manual?conf
ServerName webserver

ServerAdmin root@webserver

Hope that info helps. Thanks for the replies.

I think I need to add these lines. A book I have says to add to httpd.conf, but I don’t think that’s where it goes now.

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Here is the PHP5.conf

<IfModule mod_php5.c>
AddHandler application/x-httpd-php .php4
AddHandler application/x-httpd-php .php5
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .php4s
AddHandler application/x-httpd-php-source .php5s
AddHandler application/x-httpd-php-source .phps
DirectoryIndex index.php4
DirectoryIndex index.php5
DirectoryIndex index.php
</IfModule>

It shouldn’t be this hard. You only need to install the LAMP pattern, and then enable php5 in /etc/sysconfig/apache2 by adding it to APACHE_MODULES (it may already be there in 11.2). And you should use full tags not short tags. It just worked for me.

If you don’t get the display you are seeking, look in /var/log/apache2/error_log for clues.

It’s in there