# PHP

# Activating PHP Rendering

Because macOS 10.3 and later comes with the command-line version of PHP out-of-the-box, you can use Whisk to run and display the results of your PHP code live. It is excellent for testing smaller amounts of code before insertion into a large site or testing non-complex pages.

A file with a .php extension renders as PHP by default. To activate PHP rendering on other/untitled documents, simply change the Mode in the Options section of the Tools Inspector to PHP and it will automatically be rendered. It can also be activated from the main menu via Preview > Mode > PHP.

Change the mode to PHP in the Tools Inspector
Change the mode to PHP in the Tools Inspector

The PHP editing mode can also be set for all new documents by selecting it and then choosing the View > Save Window Layout and Settings menu.

TIP

When Whisk is set to refresh instantly, it will report parse errors very often. Therefore setting a delay of 1 second is recommended.

# Viewing HTML Code Output

By default, the PHP mode will render the page in the Web Preview. But it is often useful to look at the HTML Source instead to see what the code is outputting.

The HTML source generated by PHP can be shown by long-pressing the Web Preview toolbar button and choosing HTML Source Code:

View Toolbar Button
View Toolbar Button

It can also be viewed by pressing Command-Shift-Right Arrow, or by choosing the Preview > PHP Output > HTML Source Code menu.

# Configuring PHP

Whisk's General Preferences allows setting the path to the PHP binary. This defaults to the macOS installation location, but can be modified if you install via homebrew, MAMP, or other means.

# Troubleshooting

See the PHP Troubleshooting page for more information.