1

I just installed PHP and Apache2 on my laptop (ubuntu 12.04), but I can't get my PHP files to load. I have followed this tutorial: http://www.howtogeek.com/howto/ubuntu/installing-php5-and-apache-on-ubuntu/ , and the index.html file works, but when I try any php, I get a server error.

I looked online for a few hours, and I added "AddType application/x-httpd-php .php" to my httpd.conf (but I don't think I'm supposed to be editing that file for the ubuntu version??) in /etc/apache2/, which somehow let ONE php file load (which just contains phpinfo()). I then tried making a new php file with the same code, but that one won't load (server error). I have no idea why it only loads that specific file. I have tried restarting apache and opening the other one first, but for some reason, it only loads the first file. I also tried to move the file to another directory in /var/www/, but not dice. I hope this makes sense, because I'm a beginner here. any help would be appreciated!!

2 Answers 2

1

Look in your Apache error log to see if there is a message. Often there's a typo or other error in the .php file that stops it from running.

In Ubuntu, the error log is in /var/log/apache2/error.log - you may need to sudo when trying to read it (in other words, sudo tail /var/log/apache2/error.log).

It's also possible you haven't given apache (the user www-data) access to the file - make sure the file can be read by that user.

If you've installed php5-cli you can also test the file locally, for example php mytest.php before trying it through the server. This will give you immediate feedback on the errors (the same errors, usually, that will appear in the Apache log).

0

You should not have to do a AddType in the httpd.conf as this should be added during the 'apt-get install php5' process.

It sounds like you have no enabled PHP5 and looking at that guide it does not mention a2enmod.

Please try: sudo a2enmod php5 then restart your Apache by doing a sudo /etc/init.d/apache2 restart or sudo service apache2 restart.

Other than that its hard to provide further insight without you editing your question and including more information such as the contents of your httpd.conf file. Please let me know if this works so I can delete this entry from the answer, or if it doesn't work edit your question and provide more details as mentioned.

1
  • Hi, Thanks for the reply! the httpd.conf file has no other contents except for the AddType line. I tried what you said, but it says thephp5 module is already loaded. Is there any other information I can give you about this that would help?
    – Gina
    Commented May 18, 2013 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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