osx lion - Issue with PHP and osx 10.7 - runs via command line but not in browser

02
2013-08
  • jnolte

    I recently removed MAMP as I wanted to have more control over my machine and wanted to make use of PHP5.4 I installed using the script located here I cannot now not even get my default PHP that is built in to osx to work. I am running this script with a simple <?php echo phpinfo(); ?> In a document in my ~/Sites directory. I am really at a loss as to why this will not work. I have php5 installed in my /usr/local directory via the link provided above and it seems like the main php is installed in /usr/bin

    Any and all insight on how to debug this would be greatly appreciated.

  • Answers
  • speedofmac

    The link isn't working. To see whether your PHP installation is working, you could use the following code in Terminal:

    php -f ~/Scripts/your_file.php
    

    Replace "your_file.php" with the path to the actual file you want to check. If it spits out HTML, then PHP is working properly.

    It sounds like you might not have an HTTP server configured (that's what MAMP was doing for you). MAMP or something similar is definitely the way to go.

    The next version of MAMP will support PHP 5.4, and it looks like BitNami's MAMP Stack already does.


    Edit

    I was unaware of php 5.4's built-in webserver. There are good instructions on how to get it up and running at PHP.net (I modified this code so it should work in your case):

    $ cd ~/Scripts
    $ /usr/local/bin/php -S localhost:8000
    

  • Related Question

    Executing PHP script from command-line
  • Jeffrey Blake

    It has been a while since I did any scripting with php. Now that I'm back at it, I find I'm missing something simple. Currently, the only way I am able to run my scripts is with the php command in front of them:

    > php script.php
    

    What do I need to do to enable running them directly? For reference, I am on kubuntu 10.0.4, and the php executable is located in /usr/bin/


  • Related Answers
  • Kendall Hopkins

    PHP is most often interpreted (it can be compiled but that's often more work than it's worth). So the way your running PHP is the best and most straight forward way to run PHP via commandline. If you really dislike including php every time your can include #!/usr/bin/php at the beginning of the file and then run them directly. Before you can run them make sure to set the execute flag > chmod +x helloworld.php.

    #!/usr/bin/php
    <?php
    echo "hello world";
    ?>
    

    > helloworld.php