Latest Videos
Ruby Meet Up 8/13/09: Ruby Files on Google App Engine
Ruby Meet Up 8/13/09: Ruby Files on Google App Engine

Presented at the Ruby Meet Up by John Woodell and…

Videos | Oct 24, 2011
Ruby Meet Up 8/13/09: Interfaces and the Future of Ruby
Ruby Meet Up 8/13/09: Interfaces and the Future of Ruby

Presented at the Ruby Meet Up by Yehuda Katz. Yehuda…

Videos | Oct 24, 2011
Picasa Web Albums Data API
Picasa Web Albums Data API

Sven Mawson gives an overview of the Picasa Web Albums…

API | Mar 18, 2011
Google App Engine - Early Look at Java Language Support
Google App Engine - Early Look at Java Language Support

This video introduces the latest features of App Engine, including…

Videos | Mar 17, 2011
Show More
Latest Freebies
PHP Contact Form Script

Here is a nice contact form for your website. This…

Free Forms | Dec 09, 2010
LightForm ::: Free Ajax/PHP Contact Form
LightForm ::: Free Ajax/PHP Contact Form

LightForm is a free Ajax/PHP contact form. It combines FormCheck2…

Free Forms | Dec 09, 2010
LightForm ported to WordPress v2.5.1
LightForm ported to WordPress v2.5.1

LightForm is now a WordPress plugin (only works with latest…

Free Forms | Dec 09, 2010
Sliding Login Panel with Mootools 1.2
Sliding Login Panel with Mootools 1.2

Some of you were wondering what script I used to…

Free Forms | Dec 09, 2010
Show More
You are here > Home > PHP
Running PHP scripts
Author: Cyberical Views: 259 Posted On: Apr 27, 2009

We cover both methods of script execution in this book, with the bias towards web server usage. Most scripts will work smoothly in either environment, with the exception of scripts covered in the chapter "Alternative PHP uses", which require specific environments. You're encouraged to try using both when reading this book – it will give you more familiarity with how PHP works, and will also give you good experience using the CLI(Command Line Interface) SAPI(Server Application Programming Interface) to debug your scripts.

The primary difference between outputting text to the command line and to a web browser is the format of new lines – through the CLI you need to use n for a new line, whereas for web browsers you need to use the HTML line break, <BR />. If you want to take a script designed for CLI and make it work through the web, swap n for <BR />, and vice versa for converting web scripts to command line scripts.

Running scripts through your web server is as simple as putting the PHP script into your web server's public directory, then navigating to the appropriate URL with your browser. Hopefully you will already have followed the official PHP installation instructions for your platform!

Running scripts through the command line is done using the CLI SAPI, which, if you are using Windows, can be found in the CLI directory of your PHP installation. That is, if you have installed PHP into c:php, the CLI SAPI will be in c:phpcliphp.exe. If you are using Unix, the availability of the CLI SAPI is down to how you installed PHP - make sure and issue the command "make install-cli" after everything else in order to install it.

Later on we'll look at more detailed information on how using the CLI SAPI is different from normal PHP scripting, so don't rush off and try it out just yet!

If you are not sure about whether PHP is set up on your machine correctly, the best way forward is to run the following script:

<?php
phpinfo();
?>

That calls a special function, phpinfo(), which outputs all the information PHP currently has – how it was configured, what server it is running on, what modules are available, and more. It is very handy to keep around when you are developing, as it will answer most questions you have about configuration.