11.1. Designing the Script

The prompts shown in the sample execution will be the same ones that I will require here: database host, schema, user, password and table prefix. Some questions might suggest a default answer if one is appropriate (such as localhost for the database host). When they do, the suggestion appears alongside their prompt in square brackets. The developer can choose to either type the response or leave the prompt blank to accept the default.

If valid options or the directory are not given when the script is called from the command line then proper usage instructions should be shown to help guide the user.

$ ./startproject
Usage: startproject [-options] -o target
Setup project directory and copy basic files into it.

startproject will be written to support the following command line arguments:

  • -c and --copy-only only copy the project skeleton to the target directory, but do not replace placeholders or delete .tmp files

  • -h and --help display usage information and exit

  • -o target and --output=target specify the directory to where the files will be copied

  • -p and --preserve don't delete .tmp files after replacing placeholders

  • -v and --version display version information and exit

I use a custom set-up script not unlike the example. However, over time my needs have grown and the prompts and options have become considerably more complex. After you have written your set-up script and created a basic site skeleton you can augment either any way you see fit. Perhaps you may ...

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.