Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

markgodley

macrumors regular
Original poster
Mar 25, 2009
135
0
Hey,

I've just started learning php at university. I do not have my own web hosting so i'm trying to run some of my php files on my mac.

How the hell do you do it? I have installed XAMMP and placed the files in the htdocs folder, pressed run for Apache mysql and ftp and then gone via the http://localhost/ and pointed to my files but the php isnt loading in firefox, not even a simple echo statement.

What am i doing wrong?
 
No it was just a simple html page with a php script in it

i.e:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en">
<head>
<title>Test</title>
<meta http-equiv="content-type"
content="application/xhtml; charset=utf-8" />

</head>
<body>
Test
<p>
<?php
print "1. Test 1 2 3";
?>
</p>
</body>
</html>

and i called the file phptest.html
 
You must give it a .php extension in order for it to be processed as PHP. You'll also need to provide the file name in the URL for it to point there correctly.
 
php isnt loading in firefox

Perhaps you could give a little more info. Have you tried Safari? What exactly is/isn't happening?

If you simply point your browser to http://localhost it should show the XAMPP start page which is the index.php file in your htdocs folder. On the left side of that page you'll see a link to phpinfo() which will show your php configuration.

You may also want to copy this code to your htdocs folder. It'll show your server path and confirm the php is being parsed by your browser.

PHP:
<?php 

echo __FILE__;

?>

Name it something like serverpath.php and point your browser to http://localhost/serverpath.php. Your browser should display something like

Code:
/Applications/XAMPP/xamppfiles/htdocs/serverpath.php

EDIT: Looks like you beat me to it angelwatt!
 
but u can run php scripts from a html file.. all i have to do is get it to display the date in a html file using php
 
Remember, if you've not already done so, you should also run

/Applications/XAMPP/xamppfiles/xampp security

in Terminal to secure your XAMPP installation.

Ensure the Apache, MySQL and FTP servers are running when you do this.
 
but u can run php scripts from a html file.. all i have to do is get it to display the date in a html file using php

PHP is only processed in HTML files if you tell Apache to do so. In your httpd.conf file you'll have a line like this,
Code:
AddType application/x-httpd-php .php .phtml
The above means PHP will only be processed if the file has a .php or .phtml extension on it. You would have to add .html to that line in order to get the web server to process PHP in a .html file. You'll also need to restart the web server for the change to take effect.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.