# apache2: vhosts open PHP scripts as files [solved]

## guttersnipe

I'm sorry if this is a common question, but I just can't seem to find the right answer.

I'm running apache2 v2.2.6.  It's configured with multiple (about 10) different port-based virtualhosts.

SOME of my virtualhosts are working 100% OK--others are not.  For example, on one site, I have the following configuration:

```

Listen 8044

<VirtualHost *:8044>

        DocumentRoot "/var/www/kmhssoccer/htdocs"

        <Directory "/var/www/kmhssoccer/htdocs">

                AllowOverride All

                Order allow,deny

                Allow from all

        </Directory>

</VirtualHost>

```

Every time I go to "http://localhost:8044/index.php", the browser (mozilla firefox v2.0.0.9) tries to download the script as if it were an image or similar file.  To say exactly, it says: "You have chosen to open index.php which is a : PHP script from http://localhost:8044  What should Firefox do with this file?" ...and as usual, I can choose "open with" or "save to disk."  I can open it with firefox, but that'll just send me into an infinite loop.  If I save it to disk, I get a plaintext file of my PHP code (not good).

I've tried commenting out all the other virtualhosts--it does not help.

I've tried using the index.php files from the virtualhosts that ARE working--it does not help.

I've tried changing the port on the virtualhost to various numbers (including ones work for other virtualhosts)--it does not help.

Any ideas??

Thanks in advance.Last edited by guttersnipe on Tue Jan 15, 2008 1:31 am; edited 1 time in total

----------

## geowapa

Did you start Apache with the -D PHP4 or -D PHP5 flag in your /etc/conf.d/apache2 file?

----------

## guttersnipe

 *Quote:*   

> 
> 
> Did you start Apache with the -D PHP4 or -D PHP5 flag in your /etc/conf.d/apache2 file?
> 
> 

 

Yes.

```

# /etc/conf.d/apache2: config file for /etc/init.d/apache2

# When you install a module it is easy to activate or deactivate the modules

# and other features of apache using the APACHE2_OPTS line. Every module should

# install a configuration in /etc/apache2/modules.d. In that file will be an

# <IfDefine NNN> where NNN is the option to enable that module.

# Here are the options available in the default configuration:

#

#  CACHE      Enables mod_cache

#  MEM_CACHE  Enables default configuration mod_mem_cache

#  DAV        Enables mod_dav

#  DEFAULT_VHOST   Enables name-based virtual hosts, with the default

#                  virtual host being in /var/www/localhost/htdocs

#  ERRORDOCS  Enables default error documents for many languages.

#  INFO       Enables mod_info, a useful module for debugging

#  LANGUAGE   Enables content-negotiation based on language and charset.

#  LDAP       Enables mod_ldap (available if USE=ldap)

#  AUTH_LDAP  Enables authentication through mod_ldap (available if USE=ldap)

#  MANUAL     Enables /manual/ to be the apache manual (available if USE=docs)

#  PROXY      Enables mod_proxy

#  SSL        Enables SSL (available if USE=ssl)

#  SSL_DEFAULT_VHOST   Enables default vhost for SSL (you should enable this

#                      when you enable SSL unless you know what you are doing)

#  SUEXEC     Enables running CGI scripts (in USERDIR) through suexec.

#  USERDIR    Enables /~username mapping to /home/username/public_html

#

# Warning: You need one of DEFAULT_VHOST or SSL_DEFAULT_VHOST, otherwise apache

#          will not listen for incomming connections on any port.

APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D LANGUAGE -D SSL -D SSL_DEFAULT_VHOST -D SUEXEC -D PHP5"

# Extended options for advanced uses of Apache ONLY

# You don't need to edit these unless you are doing crazy Apache stuff

# As not having them set correctly, or feeding in an incorrect configuration

# via them will result in Apache failing to start

# YOU HAVE BEEN WARNED.

# ServerRoot setting

#SERVERROOT=/usr/lib64/apache2

# Configuration file location

# - If this does NOT start with a '/', then it is treated relative to

# $SERVERROOT by Apache

#CONFIGFILE=/etc/apache2/httpd.conf

# Location to log startup errors to

# They are normally dumped to your terminal.

#STARTUPERRORLOG="/var/log/apache2/startuperror.log"

# A command that outputs a formatted text version of the HTML at the URL

# of the command line. Designed for lynx, however other programs may work.

#LYNX="lynx -dump"

# The URL to your server's mod_status status page.

# Required for status and fullstatus

#STATUSURL="http://localhost/server-status"

# Method to use when reloading the server

# Valid options are 'restart' and 'graceful'

# See http://httpd.apache.org/docs/2.2/stopping.html for information on

# what they do and how they differ.

#RELOAD_TYPE="graceful"

```

----------

## upengan78

 :Confused: 

 *Quote:*   

> 
> 
> Listen 8044
> 
> <VirtualHost *:8044>
> ...

 

Do you have Options configured for Virtual hosts ? I do not see it in above posting !

----------

## skogs

This seems like a pretty broken update of apache2.

At first I couldn't get it to start at all due to SSL port already in use...blah blah blah.  Fixed that, very easy since I don't need SSL.

Then it served directories.  Not cool.  Took the site down.  Fixed that by allowing it to serve index.php as well as default index.html....which pointed to the obvious actual problem:

It isn't parsing php.  Not a bit.  Seems to not have a use flag as the new 'module use flag setup' would indicate.  conf.d file was also of no use.  tried -D php5, -D php, and -D php5cgi.  

This is a pretty big boner...and I'm usually pretty good at searching through the config files to get the problem.  

HELP!

 *Quote:*   

> Do you have Options configured for Virtual hosts ? I do not see it in above posting !

 

This doesn't really help much...as I can't find a proper format/syntax for this.  These config files have changed quite a bit in the last 3 months...this last setup is even worse.  There are no examples that I can find with google.

----------

## guttersnipe

I FIGURED IT OUT!!!!!!!!

Turns out, I had a ".htaccess" file hidden in my htdocs directory with the contents of:

```

AddHandler x-httpd-php5 .php

AddHandler x-httpd-php .php4

```

The file is needed on the server (godaddy) to make apache use PHP5 instead of PHP4--BUT it does nothing but cause pain and suffering when it's hidden on my test server at home.

God, I have a headache.

----------

## skogs

 *Quote:*   

> I FIGURED IT OUT!!!!!!!!
> 
> Turns out, I had a ".htaccess" file hidden in my htdocs directory with the contents of: 

 

Unfortunately, that doesn't seem to be my problem.

What changed in the configs for loading and using PHP?  Seriously, apache isn't very useful without some scripting.  How do you enable scripting support now with the newest version?

----------

## skogs

Well...

It works.  But I'm not sure exactly why.

I continued to disable the SSL scripts in conf.d by making the files .888888conf instead of *.conf.

Re-entered the original -D PHP5 for APACHE_OPTIONS....

poof.  

I know I tried disabling everything new, but now it works so I'm happy.  Argh.

----------

## Speen

 *skogs wrote:*   

> Well...
> 
> It works.  But I'm not sure exactly why.
> 
> I continued to disable the SSL scripts in conf.d by making the files .888888conf instead of *.conf.
> ...

 

Hi guys,

I'm fighting with a similar problem, I use some vhosts. One of them (and only one) has the following problem:

I open my site http://my.example.net and FireFox opens the 'save file as' dialog. 

the index.php contains:

```

<?php

header('Location home.html');

?>

```

If I call http://my.example.net/index.php the script works fine.

This whole 'phenomenon' appears only on my workstation at home. There are no problems at all in other locations.

This vhost uses the same config all the other vhosts use too

any ideas?

----------

## upengan78

did un install php4 and reinstalled php5 with apache2 option ?

----------

## Speen

 *upengan78 wrote:*   

> did un install php4 and reinstalled php5 with apache2 option ?

 

php5 was installed with this useflag. as I said this appears only at home, in my office all works fine

----------

