XAMMP and PHP

Discussion in 'Web Design and Development' started by markgodley, Oct 11, 2009.

  1. markgodley macrumors regular

    Joined:
    Mar 25, 2009
    #1
    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?
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
  3. markgodley thread starter macrumors regular

    Joined:
    Mar 25, 2009
    #3
    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
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    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.
     
  5. nuxx macrumors member

    nuxx

    Joined:
    Jun 5, 2007
    Location:
    Tokyo
    #5
    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!
     
  6. markgodley thread starter macrumors regular

    Joined:
    Mar 25, 2009
    #6
    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
     
  7. nuxx macrumors member

    nuxx

    Joined:
    Jun 5, 2007
    Location:
    Tokyo
    #7
    Remember, if you've not already done so, you should also run

    in Terminal to secure your XAMPP installation.

    Ensure the Apache, MySQL and FTP servers are running when you do this.
     
  8. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #8
    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.
     
  9. lindsayanng macrumors 68000

    lindsayanng

    Joined:
    May 4, 2008
    Location:
    East Haven, CT
    #9
    I do believe that you also have to use terminal to tell your computer and XAMPP to use that particular directory and path as your server directory

    like this:
     

Share This Page