is php working?

.jeremy_a>

Registered
I ran throw the instructions on the FAQ page on setting up php and mysql, not how do I know if they work or not? I made a php page on the desktop, basically just the php info function, and opened it in IE, but it didn't work, do the php pages have to be located some where specific, or did I just mess up the install?
 
I think PHP is run on the server. That means you would need to:

- Start up your Apache server by switching on Web Sharing in System Prefs.

- Put a copy of your PHP doc into, I think, /Library/WebServer/Documents

- Open it THROUGH your server, not through the file system. By that, I mean if you simply open the file all you'll get is the PHP code, but if you GO TO the file on the server, the code will run. Go to http://localhost/myphpdoc.php
(Note: in IE, you'll need to substitute 127.0.0.1 for localhost if you aren't online. Just a quirk of the browser.)

At least, those are the steps I use to run Perl/CGI scripts, which are very similar to PHP.
 
I think the problem was that my web sharing wasn't turned on. now I can get to my user folder/files using either local host or 127.0.0.1 but when I try to access my php page. all i get is this:

################
#Php Information Page #
################
<?php
phpinfo();
?>


that is what the source code looks like, and that is what my page displays in the browser.....I am very sorry, but I am totally clueless to this sort of thing.
 
You don't open the file directly ... if you do, you'll only see what's in the file.

You have to open the file "on the server" so that the server can run the PHP code and produce the resulting page dynamically.

So, the file must be:
- In the appropriate place, eg: /Library/WebServer/Documents.

- Executable by all users (you'll need to use chmod for this); at least, I've found you have to do this for Perl scripts. Type in terminal "chmod a+x phpscript.php" (which means "all users" get the "execute" privilege).

- Accessed on the server by pointing a browser to http://youripaddress/phpscript.php. If you open the file directly, all you will see is the script.
When opened through the server, a client browser sends a request for the page. The apache server then executes the PHP code to produce a page dynamically, and passes that output to the client.
What you are doing in this instance is using your web-browser as a client to access your own machine's web service.
 
symphonix: PHP files don't have to be executable by any user--they're parsed out by Apache, not executed like CGI scripts. If you want PHP to write to a file however, that file (or parent folder) must be chmod a+w but that's it.

.jeremy_a>: Comments in PHP are made using C-style /* */ or //, not # (for your header).

The path to the web server is indeed /Library/WebServer/Documents (which maps to 127.0.0.1/) or alternatively ~/Library/Sites (which maps to 127.0.0.1/~username/) If you're actually putting the file into either of the web server folders, and you still only see the source code, then PHP isn't working properly.

Check /etc/httpd/httpd.conf for the lines:
Code:
LoadModule php4_module libexec/httpd/libphp4.so

AddModule mod_php4.c

<IfModule mod_dir.c> 
    DirectoryIndex index.html index.php
</IfModule>

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
The php installation instructions will tell you where these lines should appear. If you don't see them, don't just stick them in anywhere as the order is VERY IMPORTANT. Check the installer again...
 
Back
Top