Reputation: 2020
I cannot get PHP to work on my computer. My browser prints out the php code rather than executing it.
The first thing I did was to open up the apache conf file and edit it to uncomment the php line
Opened file:
sudo nano /etc/apache2/httpd.conf
This is the line I uncommented in that file:
LoadModule php_module libexec/apache2/libphp5.so
I then restarted apache using:
sudo apachectl restart
Apache would run, http://127.0.0.1 would show "It works!" I then created a file called test.php, in which I put the following line of code:
<?php phpinfo(); ?>
In chrome I clicked file -> open file -> test.php, and all it printed was the code I had written.
I've also tried changing the line "User _www" in the conf file to
User myusername
I've tried changing the line "DirectoryIndex index.html" to:
DirectoryIndex index.php index.html index.htm
None of these changes have resulted in PHP script executing on my computer. Any help would be appreciated!
Upvotes: 0
Views: 789
Reputation: 590
Put the test.php in /Library/WebServer/Documents .
Make sure you have
<?php phpinfo(); ?>
inside your test.php
Open Chrome. Go to http://localhost/test.php
You cant just open test.php file using Chrome. PHP script needs to be executed by a PHP Compiler before you can see any output. If you simply open the PHP file in chrome, it will show you the PHP code only.
Upvotes: 3