7

I installed LAMP Server. I can access http://localhost. I can also run successfully phpmyadmin. But when I go to http://localhost/testphp.php, I get a 404 not found. The file is in /var/www/testphp.php. The file reads: <?php phpinfo(); ?>. This information was taken from the guide: https://help.ubuntu.com/community/ApacheMySQLPHP. What am I doing wrong? Thanks in advance.

  • 6
    In Ubuntu 14.04 the default directory for Apache is /var/www/html, not /var/www/. See http://askubuntu.com/q/448944/158442 – muru Sep 04 '14 at 17:30
  • 1
    @muru I don't know why that change was made. It makes no sense. – Kaz Wolfe Sep 04 '14 at 17:35
  • @Whaaaaaat made sense to Debian devs: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=730372 (we just inherited the change) I don't really care either way - I usually make a copy of the default conf, disable it and work on the copy. – muru Sep 04 '14 at 17:36

2 Answers2

5

Most likely your file is not in the correct directory. Apache serves files from a directory referred to as the "Document Root". Your files must be in this directory for Apache to find them.

To check what the Apache is using as the Document Root:

  • Open a terminal
  • run less /etc/apache2/sites-enabled/000-default (may need sudo)
  • Look for the line the looks like DocumentRoot /some/path. Its towards the top
  • Make sure your php scripts are in /some/path

This is assuming you haven't made any configuration changes to Apache. This can be much more complex if you have multiple virtual hosts, and aliases, and so forth. But for the default Apache configuration this will do the trick.

Dan
  • 6,753
  • 5
  • 26
  • 43
2

As like dan08 said, Apache serves files from the directory termed "Document Root". The default "Document Root" is /var/www/html.

So, you have two options now.

  1. Either, Put your file into /var/www/html.
  2. Or, Change "Document Root" with the help of dan08's answer. For your case, the DocumentRoot value should be /var/www.
Ramvignesh
  • 1,812
  • 6
  • 20
  • 31