Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

is there a way to view local PHP files in my browser without running Apache or anything? I'm using Snow Leopard.

share|improve this question
2  
Do you want to see the native PHP code in your local browser or do you want to the rendered HTML equivalent? – ubiquibacon Jul 28 '10 at 21:54
1  
Do you want to see the actual PHP code or you want to run the scripts and see the output (in a browser or CLI)? – Tom Jul 29 '10 at 11:32
    
Would you please accept my answer if it satisfies you or ask for more information if not??? Thanks. – Patkos Csaba Aug 6 '10 at 16:33
up vote 6 down vote accepted

A browser can not show you the output of a PHP file. This is because a PHP file needs to be run by an interpreter (the php interpreter). A browser has no means to do this, it just expect HTML code or in the best cases it will show you the content of .php file as a text.
However, there are a few ways you can see the output of a PHP file. You can run any PHP file from Terminal. cd into the folder where your php file is, and run it like this php ./my_file.php You will see the output in the Terminal window. The output will be the HTML code if your PHP generates HTML code. If this is the case, you can php ./my_file.php > output.html and open the output.html file in your browser.
Please note, there is no way you can interact with your PHP files. You have no way to fill in HTML forms and click HTML buttons.
These rules are general for all operating systems, not just MacOS.

share|improve this answer

If you don't want to argue with apache configuration (which is shipped with snowleopard), you can install MAMP(the free version) ! I've a very easy to use Apache + MySQL solution, that will allow you to run php pages locally.

share|improve this answer

If you only see code in a browser window with web sharing turned on, you may not have PHP turned on, and therefor need to edit httpd.conf located here: hard drive/private/ect/apache2/httpd.conf

It's hidden, but you can open with bbedit. Do a search for 'PHP'. Uncomment (remove hash from) the first instance you find to turn on PHP and save. The line looks like this:

LoadModule php5_module libexec/apache2/libphp5.so

Be sure to restart Apache as the last step (turning web sharing off and on again will do it)

To test that PHP is now working, create a PHP test file in your new user level web root (~/Sites) with the following command:

printf "<?php phpinfo(); ?>" > ~/Sites/phpinfo.php

to perform this in Terminal, use this guide: https://ole.michelsen.dk/blog/setup-local-web-server-apache-php-macos-x-mavericks.html

share|improve this answer
1  
Please read the question again carefully. Your answer does not answer the original question. This is the opposite of what the OP asked for. – DavidPostill Dec 12 '15 at 23:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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