Skip to Content
Beginning PHP 5.3
book

Beginning PHP 5.3

by Matt Doyle
October 2009
Beginner
836 pages
19h 37m
English
Wrox
Content preview from Beginning PHP 5.3

Appendix D. Using PHP from the Command Line

Although PHP scripts are most commonly run through a Web server — either via an Apache or IIS module, or using the CGI version of PHP — it's possible to run the PHP engine in command-line mode. This lets you create stand-alone PHP scripts that can be run directly from the command line, or by double-clicking an icon. This means you can build scripts that:

  • Can be run on any computer with PHP installed, without needing a Web server

  • Can be scheduled to run automatically at certain times of the day or week

  • Can have a GUI (graphical user interface), much like a regular Windows, Mac, or Linux GUI application

  • Can be called by other PHP scripts or applications to carry out specific tasks

If you're used to other command-line scripting languages such as Perl, Tcl, or Bash, PHP in command-line mode works in a similar fashion.

On most UNIX-like systems, including Ubuntu and Mac OS X, you can run the command-line version of PHP simply by typing php at a shell prompt. For example, type php -v to display version information:

$ php -v
PHP 5.3.0.0-dev (cli) (built: Jun 29 2009 21:25:23)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies

To run the MAMP-specific version of PHP on Mac OS X with MAMP installed, instead of the built-in Mac OS X version of PHP, you'll need to specify the full path to the PHP executable (for example, /Applications/MAMP/bin/php5/bin/php -v) or add the /Applications/MAMP/bin/php5/bin folder ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

PHP and MySQL™ Phrasebook

PHP and MySQL™ Phrasebook

Christian Wenz
PHP 7: Real World Application Development

PHP 7: Real World Application Development

Doug Bierer, Altaf Hussain, Branko Ajzele
PHP 5 Unleashed

PHP 5 Unleashed

John Coggeshall

Publisher Resources

ISBN: 9780470413968Purchase book