How to get PHP to work on a mac.

Discussion in 'PHP' started by zambonibutters, Aug 6, 2010.

  1. #1
    Okay, this is kind of embarrassing. I am an extreme noob in php, and have just started learning. The trouble is, I can't get it to work on my mac. For example, if I want to run some of the code in Safari (I have OS X 10.6), it will just display the text of the code, instead of actually running it. Does anybody here know how to install and run PHP on a mac?
     
    zambonibutters, Aug 6, 2010 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    I'm not really familiar with mac, but the problem with mac is that it isn't really made for hosting PHP scripts and development of PHP scripts, it's made for noobs so everything pretty much "just works". In any case, maybe this will help. I did it for you. :)
     
    Rainulf, Aug 6, 2010 IP
  3. zambonibutters

    zambonibutters Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hahaha very funny. i googled it first, went through a $@#!-load of crap in terminal and textwrangler, and I ended up doing, well, not much. but thanks for the funny reply. i needed that.
     
    zambonibutters, Aug 6, 2010 IP
  4. themullet

    themullet Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #4
    sounds like apache is running, general debugging process, did you restart the apache process after installing php? is there a php.ini file? has apache got the module? is the module loaded? your php file using <?php and not "<?"? <?php phpinfo();?> return anything?

    failing that just create a ubuntu virtual server and quick install lamp. That will be done in an hour or so, rather then spending your time debugging
     
    themullet, Aug 6, 2010 IP
  5. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #5
    Well, that's what you get with mac.. lol It's very easy with windows or linux. If you don't want to go through all that crap, why not just get a webhost?
     
    Rainulf, Aug 6, 2010 IP
  6. belltower

    belltower Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Have you tried MAMP?

    I'm on Windoze and Linux, so I've never used it, but if it's anything like WAMP or LAMP, it'll set up Apache, MySQL and PHP for you automagically.
     
    belltower, Aug 6, 2010 IP
  7. zambonibutters

    zambonibutters Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I use MAMP. Unfortunately it isn't working. I had the test.php file located at the correct root, and I typed in http://localhost/ into my browser, and yes, apache is working fine. I also edited the httpd.conf file (I took away the # from some of the lines) like it says on other sites, and the php.ini problem doesn't apply in Snow leopard. Is there something that I'm missing? Why wont my mac parse the php correctly?
     
    zambonibutters, Aug 7, 2010 IP
  8. zambonibutters

    zambonibutters Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    oh, also mac comes presintalled with php, while in windows you need to install it manually so it should be just as easy or easier than in windows to run php on mac.

    ahhh...with everything I try to do with computers theres always a host of problems in the way :(
     
    zambonibutters, Aug 7, 2010 IP
  9. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #9
    u can try XAMPP for mac not sure if it works but its a good option.
     
    arpit13, Aug 7, 2010 IP
  10. zambonibutters

    zambonibutters Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    thanks. i'll give it a try
     
    zambonibutters, Aug 8, 2010 IP
  11. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #11
    Mac is not "made" for noobs. Atleast know what you're talking about before making such a ridiculous assumption like that. I use windows, mac and linux in a tri-boot. Each serves it's own purpose, but I rather do everything on linux If I can, such as running Xcode and photoshop on it.
     
    Kaizoku, Aug 8, 2010 IP
  12. zambonibutters

    zambonibutters Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Agreed. I got a mac specifically because I spent more time trying to get my windows to work than actually use it. I am a noob when it comes to php, but overall, i am not a noob in computers.
     
    zambonibutters, Aug 8, 2010 IP
  13. themullet

    themullet Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #13
    photoshop on linux is working fine now. same can't be said for xcode, I would be tempted to run os x as a virtual machine inside linux, less switching todo and more time in linux
     
    themullet, Aug 8, 2010 IP
  14. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #14
    Don't mean to interrupt this mac discussion or is it about php ? :) LOL

    But could you post up the full code your trying in the test.php file from <?php
     
    MyVodaFone, Aug 8, 2010 IP
  15. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #15
    I don't know if I should argue with you or not man... lol
    Thank you. Thank you for supporting me. :)

    Both. ;)
     
    Last edited: Aug 8, 2010
    Rainulf, Aug 8, 2010 IP
  16. zambonibutters

    zambonibutters Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Here's the code. I found it on the internet and its a very good test page for php. I also have a very basic file called hello php which is just <?php echo "hello"; ?>.

    <?php
    /* Original code by Erwin Poelman found on
    http://www.weberdev.com/get_example-3096.html

    This is a little more up to date and formatted for readability.
    Some things in PHP have changed since Erwin Poelman first posted this
    and a couple of things had to be added to resolve variables that are
    no longer automagically (yes, I spelled it right!;) set. Also added
    a test for <?...?> enclosure. Changed the hard coded file name (originally
    'generate.php') in the src attributes to server resolution through the
    'PHP_SELF' value.

    Otherwise, its a pretty neat and tidy little browser PHP interpretter, just
    as Erwin Poelman originally wrote it!;)
    */
    if(isset($_REQUEST['dispArea']))$dispArea=$_REQUEST['dispArea'];
    if(isset($_REQUEST['theCode']))$theCode=$_REQUEST['theCode'];
    if(!isset($dispArea))
    {
    echo "<frameset cols='60%,40%'>\r\n";
    echo "<frame name='theCode' src='".$_SERVER['PHP_SELF']."?dispArea=left'>\r\n";
    echo "<frame name='theExec' src='".$_SERVER['PHP_SELF']."?dispArea=right'>\r\n";
    echo "</frameset>\r\n";
    }
    else
    {
    if(!strcmp($dispArea,"left"))
    {
    echo "<body bgcolor='#D0DEED'>\r\n";
    echo "<font face='Arial,Verdana,Helvetica' color='FF0000' size='3'>PHP Tester</font>\r\n";
    echo "<form method='post' action='".$_SERVER['PHP_SELF']."?dispArea=right' target='theExec'>\r\n";
    echo "<table>\r\n";
    echo "<tr><td align='center'>\r\n";
    echo "<input type='submit' value='Execute'>\r\n";
    echo "</td></tr>\r\n";
    echo "<tr><td>\r\n";
    echo "<textarea name='theCode' cols='65' rows='25' wrap='virtual'>\r\n";
    echo $theCode."\r\n";
    echo "</textarea>\r\n";
    echo "</td></tr>\r\n";
    echo "</table>\r\n";
    echo "</form>\r\n";
    }
    else if(!strcmp($dispArea,"right"))
    {
    echo "<body bgcolor='#FFFFFF'>\r\n";
    if(empty($theCode))
    {
    echo "Ready to parse...";
    }
    else
    {
    $theCode=ltrim(rtrim(stripSlashes($theCode)));
    if(!strncmp($theCode,"<?",2)) //if it's full php, remove the tags
    {
    if(!strncmp($theCode,"<?php",5))
    {
    $theCode=substr($theCode,5);
    }
    else
    {
    $theCode=substr($theCode,2);
    }
    $theCode=substr($theCode,0,strlen($theCode)-2);
    $theCode=ltrim(rtrim(stripSlashes($theCode)));
    }
    eval($theCode);
    }
    }
    echo "</body>";
    }
    ?>

    Anyways, I tried XAMPP and it's very similar in idea to MAMP. Still doesn't work, and I prefer MAMP to tell you the truth.
    Meh...im having an easier time learning php than actually getting the computer to parse it.
     
    zambonibutters, Aug 8, 2010 IP
  17. zambonibutters

    zambonibutters Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Maybe I should just try it in windows? even mac users must someday resort to windows[​IMG]
     
    zambonibutters, Aug 8, 2010 IP
  18. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #18
    You can use Entropy-PHP.
    also the htdocs is in /Library/WebServer.
     
    guardian999, Aug 8, 2010 IP
  19. zambonibutters

    zambonibutters Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19
    OMG!! I installed WAMP on my windows partition, and gues what? it worked! [​IMG] now if only i could understand the connection between mysql and php. this stuff is hard to wrap my head around...
     
    zambonibutters, Aug 8, 2010 IP