Apache doesn't load .php files

64,924

There may be a problem with the permission of the files. If apache (or www-data) does not have read permission the pages will not show.

this error seems to indicate that:

`[Mon Jun 09 17:08:13.627881 2014] [:error] [pid 1517] [client 127.0.0.1:46663] PHP Warning:  require_once(/var/www/html/Connections/rakstadconnection.php): failed to open stream: Permission denied in /var/www/html/index.php on line 1`

Make www-data the owner of the directory and everything in it. sudo chown -R www-data:www-data /var/www/html/<siteFolder>.

Then set the privileges to give the owner and group read and write and execute privileges and everyone else just read privileges sudo chmod -R 774 /var/www/html/<siteFolder>.


Share:
64,924

Related videos on Youtube

Haddex
Author by

Haddex

Updated on September 18, 2022

Comments

  • Haddex
    Haddex over 1 year

    First, sorry for my English and asking something that it's quite answered all over the web. I've read a lot of post about this problem but I still can't find the solution.

    I'm a web developer who recently moved to Ubuntu from Windows 7. I had a website done (it's online and working) and I set up LAMP to keep working with it. I made a test.php file with: <?php phpinfo(); ?> and put it on /var/www/html directory, it shows all the information about the php and I was really happy: "Ok, it's all done, tomorrow I will work hard"

    But I placed my whole web into /var/www/html , not in a folder, the index.php is in /var/www/html but guess what: doesn't load any of my .php files, the browser just keep thinking.

    What I did:

    1. I rebooted Apache: /etc/init.d/apache2 restart
    2. I tried again with the test.php file and it works fine
    3. I put in /var/www/html a .html file and works fine.
    4. I looked for /etc/apache2/sites-enable/000-default.conf and it says: DocumentRoot /var/www/html

    5. I looked for /etc/apache2/mods-enabled/dir.conf and it says: DirectoryIndex index.html index.cgi index.pl index.php ...

    Edit*

    I think it's something related to phpmyadmin, like if I'm not able to connect with the database. But I got nothing on the screen when trying to load the page so...I'm not sure.

    I can access to the url localhost/phpmyadmin and I edited the connection.php file like this:

    <?php
    # FileName="Connection_php_mysql.htm"
    # Type="MYSQL"
    # HTTP="true"
    $hostname_rakstadconnection = "localhost";
    $database_rakstadconnection = "rakstadclandb";
    $username_rakstadconnection = "root";
    $password_rakstadconnection = "admin";
    $rakstadconnection = mysql_connect($hostname_rakstadconnection, $username_rakstadconnection, $password_rakstadconnection) or trigger_error(mysql_error(),E_USER_ERROR);
    mysql_query("SET NAMES 'utf8'"); 
    ?>
    

    The name of the database is correct, like the user and password.

    http://i89.photobucket.com/albums/k220/Haddex/Capturadepantallade2014-06-09112609_zpsc45ddb72.png

    http://i89.photobucket.com/albums/k220/Haddex/Capturadepantallade2014-06-09112120_zps0b9e15f7.png

    *Edit2: could this be because it's a website that I brought to Linux from Windows? I used Dreamweaver.

    Edit3: I changed the # to /*/, nothing. The error.log file says:

    [Mon Jun 09 17:08:13.627881 2014] [:error] [pid 1517] [client 127.0.0.1:46663] PHP Warning:  require_once(/var/www/html/Connections/rakstadconnection.php): failed to open stream: Permission denied in /var/www/html/index.php on line 1
    [Mon Jun 09 17:08:13.627933 2014] [:error] [pid 1517] [client 127.0.0.1:46663] PHP Fatal error:  require_once(): Failed opening required 'Connections/rakstadconnection.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/index.php on line 1
    

    I'm reading error log but...should I add a linux path into a my index.php file? Don't think so.

    Thanks.

    • Duncubuntu
      Duncubuntu almost 10 years
      What does your error log say? Also, '#' for comments in php is now deprecated I believe. use /* This */ or //This works too
    • Haddex
      Haddex almost 10 years
      That's mostly the problem, that I don't get any error (at least on the browser screen). When not able to connect or syntax error I always see some php error message on the browser on WINDOWS, but here I don't see anything. Testphp.php (phpinfo()) works perfect, but my .php files return an empty webpage. I always use /**/ for comments, but thanks anyway.
    • squareborg
      squareborg almost 10 years
      You are probably getting a php error in /var/log/apache2/error.log
    • squareborg
      squareborg almost 10 years
      like @Duncubuntu says try using the // or /* */ for comments, you say you always do but your not in this case you have # I didn't even know that was ever an acceptable comment marker.
    • Haddex
      Haddex almost 10 years
      I added the error.log in the Edit3 at the end of the question, thanks guys, hope to fix it. I don't like to boot Windows just to do some web development.
    • Haddex
      Haddex almost 10 years
      As far as I know, at least in my website folder, I don't have any .htaccess or init file. Same folder works fine with Wamp on Windows. Should I create .htaccess and add...something to fix this?
    • Duncubuntu
      Duncubuntu almost 10 years
      I agree, it could very well be a problem with your include paths. Or like @dan08 says below, make sure your permissions are correct first. (I like to stick with 755 for folders, 644 for files). Also: Post your include lines from index.php. For future reference as well: if PHP gives you a blank screen, its almost always a fatal error.
  • Haddex
    Haddex almost 10 years
    Thank you dan08, you just made my day. It was the chmod.
  • Dan
    Dan almost 10 years
    I would suggest reading up on Unix permissions, because it will be important to get them right if your running a public web server on a Linux box. Here's a good start: tutorialspoint.com/unix/unix-file-permission.htm