0

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!

9
  • Did you install on your own, or did you install something like MAMP? Commented May 7, 2015 at 15:35
  • I used the built in apache and PHP. I did not install MAMP Commented May 7, 2015 at 15:36
  • 2
    Did you try http://127.0.0.1/test.php, or whatever path it is to the file? Commented May 7, 2015 at 15:37
  • That gives: "Not Found. The requested URL /test.php was not found on this server." Commented May 7, 2015 at 15:38
  • 1
    Of course opening the file via File → Open will output the raw code, because that's circumventing the Apache web server entirely. Commented May 7, 2015 at 15:40

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Great Chris. Happy Hacking with PHP

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.