I am trying to setup a basic apache 2 webserver just for testing purposes. I have apache 2 installed on Ubuntu 11.10. I can access the root directory on the webserver just fine by going to "localhost" in my browser. This is all located in the default directory: /var/www. However, the problem starts whenever I try to access the subdirectories of my webserver. So, for example if I goto "localhost/phpproject/", which has an index.php file listed in it (and I did test to make sure PHP was working correctly), all it seems to want to do in my browser is attempt to download a file when I type in the address instead of actually displaying anything.

I even tried to give full permissions on the subdirectory to make sure it wasn't just a permissions-related problem. Any ideas?

share|improve this question
    
How did you install Apache/PHP and how did you test PHP? – apesa Dec 8 '11 at 6:40
    
i used the sudo apt-get install lamp-server^ method – TMGunter Dec 8 '11 at 16:21
    
The other thing is that I also tried just an HTML file, and it wouldn't load either; meaning that it probably is not a php problem – TMGunter Dec 8 '11 at 16:35

Make sure that you installed PHP correctly and registered PHP in your Apache configuration.

This is the key here, it looks like it's sending you the index.php file, test a PHP file in the main folder behind this sub-directory and see if it tries to download it.

File Could just be:

<?php
phpinfo();

See if putting that in index.php in the parent folder gives you a phpinfo page or tries to download index.php.

If it tries to download it it's just that PHP is not configured in apache to handle files that end in .php

To configure it, add the following lines to your httpd.conf file

LoadModule php4_module modules/libphp4.so
#
# Cause the PHP interpreter handle files with a .php extension.
#
<Files *.php>
SetOutputFilter PHP
SetInputFilter PHP
LimitRequestBody 9524288
</Files>
AddType application/x-httpd-php .php
share|improve this answer

in Ubuntu you should install the LAMP option using tasksel at the CL. That will give you Apache, MySQL and PHP all working together. It sounds like you may have installed them separatley and have not configured PHP correctly. mime types determine the servers handling of specific file types.

apesa@ubunt$ sudo tasksel

Follow the prompts

EDIT:

We used to make all the config changes in httpd.conf. If you used package manager, like you did then you will have a distributed configuration environment. You will need to go to etc/apache2/mods enabled and look in the php.conf file. There are directions inside. It sounds like you need to make sure the web server understands the directories and FS locations. Look at @Chrispy example. You won't be using the first line as the php module in your env are loaded via php.load and the config is done in php.conf. That AddType directive is important and tells the server to exec your file instead of serving it. have a look. BTW, the Apache Project supports one of the best listservers out there at URL:http://httpd.apache.org/userslist.html

share|improve this answer
    
@Mahbub advice on path directives for folders is good advice, but will not fix your PHP issue – apesa Dec 8 '11 at 7:00
    
PHP works fine in the main WWW directory though, as I have a php file that loads just fine. – TMGunter Dec 8 '11 at 16:20
    
If you installed using package management then you should be using Sites Enabled and Mods Enabled. Look in etc/apache2 for these two folders. In Mods Enabled open the php5.conf file and make sure you have it setup as enabled in user and child dirs. You should have a 0kb httpd.conf file as these directives are now distributed and the only directives in httpd.conf are your custom ones – apesa Dec 8 '11 at 16:42
    
how do I make sure it is setup as enabled in user and child dirs? – TMGunter Dec 8 '11 at 16:45
    
refer to my initial answer edits.. It's getting too big for comments.. Post your virtualHosts config and your php.conf config – apesa Dec 8 '11 at 17:44

First of all, you shouldn't be keeping your development files in /var/www folder. Configure your apache to keep your web files within your home directory. In doing so, you don't have to have sudo privilege to edit files in /var/www. If you want to follow my setup, create a directory called www in your home folder /home/yourname/www. Look at my config of /etc/apache2/sites-enabled/000-default

http://pastebin.com/3gcE59Lh

It works good for me.

If you change your config like this, make sure to restart apache [sudo service apache2 restart]

share|improve this answer
    
not the best solution, although it worked for me... – Girardi Feb 20 '12 at 22:37

Make sure that you installed PHP correctly and registered PHP in your apache configuration.

The manual should explain the required installation steps in detail.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.