Chapter 11. Shell Scripts

The mailing list project presented in Chapter 3 demonstrates how PHP can be used for more than just generating web pages. Certainly that is the area where PHP shines the brightest, but PHP really is a capable language flexible enough for tackling most any programming task. In this chapter, I will discuss using PHP to write shell scripts.

The impetus for this project comes from the realization that many applications share the same basic layout. For example, the directory structure and shared code files first discussed in Chapter 1 have appeared in other projects throughout the entire book. Directories such as lib, public_files and sql keep the project organized and shared code such as common.php and db.php provide the project's configuration.

The Rails framework that has gained widespread acceptance in the Ruby programming community and really put Ruby on the map offers more functionality than just setting up a common skeleton for a project, but this is often the first service it performs for the developer. Similarly, Django initially assists a Python programmer to create an application structure. Sure you're using PHP, but there's no reason why you can't "borrow" good ideas just because it's not the same language.

So in this chapter, you will be writing a shell script to help set up a well organized directory layout and copy basic code files into it to start a new application. It will run from the command line and prompt the developer for important values ...

Get PHP and MySQL®: Create-Modify-Reuse now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.