[Setup] PHP Development Environment
This page explains how to set up a PHP development environment. PHP is a widely used language for web application development. With the built-in server, you can verify your code in a browser right away.
Installing PHP
| OS | Installation Method |
|---|---|
| Windows | Download the ZIP file from php.net and extract it. Add the folder path to the PATH environment variable. If you want an all-in-one solution, installing XAMPP gives you PHP, Apache, and MySQL in one package. |
| macOS | Run brew install php with Homebrew. Homebrew is a package manager for macOS — if it is not installed, follow the instructions at https://brew.sh/. After installation, run php --version in a terminal to verify. |
php --version PHP 8.3.8 (cli)
Running Code with the Built-in Server
PHP includes a built-in web server. You can test PHP in a browser without installing a separate server like Apache.
First, save the following content as index.php using a text editor.
sample_index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PHP Test</title>
</head>
<body>
<h1>Hello, PHP!</h1>
<p>Current date/time: <?php echo date('Y-m-d H:i:s'); ?></p>
<?php
$members = ['Gojo Satoru', 'Itadori Yuji', 'Fushiguro Megumi', 'Kugisaki Nobara'];
echo '<ul>';
foreach ($members as $member) {
echo '<li>' . $member . '</li>';
}
echo '</ul>';
?>
</body>
</html>
Navigate to the folder where you saved the file in a terminal and start the built-in server with the following command.
php -S localhost:8000
Open http://localhost:8000 in a browser to see the output. Press Ctrl + C to stop the server.
Running PHP from the CLI
PHP files can also be run directly from the terminal without a browser.
Save the following content as hello.php using a text editor.
hello.php
<?php
// hello.php
echo "Hello, PHP!" . PHP_EOL;
$name = "Gojo Satoru";
echo "Hello, " . $name . "!" . PHP_EOL;
for ($i = 1; $i <= 5; $i++) {
echo "Loop iteration " . $i . PHP_EOL;
}
Run the following command in a terminal.
php hello.php Hello, PHP! Hello, Gojo Satoru! Loop iteration 1 Loop iteration 2 Loop iteration 3 Loop iteration 4 Loop iteration 5
Checking php.ini
You can find the location of PHP's configuration file php.ini with the following command. Refer to it when you need to change settings such as error display.
php --ini Loaded Configuration File: /usr/local/etc/php/8.3/php.ini
During development, adding the following settings to php.ini makes it easier to find the cause of errors.
display_errors = On error_reporting = E_ALL
Command Not Found
If the terminal shows php: command not found, the PATH may not be configured correctly. Follow the steps below to check and set it up.
1. Locate the command
Check where the php command is installed.
which php
If it is not found, check the common installation paths.
ls /usr/local/bin/php ls /opt/homebrew/bin/php ls /Applications/XAMPP/bin/php
2. Check your shell
echo $SHELL
If the output is /bin/zsh, edit ~/.zshrc. If it is /bin/bash, edit ~/.bashrc.
3. Add the path to PATH
Once you know the installation path, add it to your shell configuration file.
For macOS (zsh):
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
For Linux (bash):
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc source ~/.bashrc
If you are using XAMPP, adjust the path to match your XAMPP installation (e.g., /Applications/XAMPP/bin).
On Windows, go to "System Properties" → "Environment Variables" → "Path" and add the folder where PHP is installed (e.g., C:\php or C:\xampp\php).
Uninstalling PHP
To uninstall the PHP version installed via Homebrew, run the following command.
brew uninstall php
Choosing an Editor
| Tool | Description |
|---|---|
| Visual Studio Code (commonly known as VSCode) | Currently the most popular editor. Installing the PHP Intelephense extension gives you powerful code completion and error detection. Available on Windows, macOS, and Linux. |
| Sublime Text | A lightweight, extremely fast editor. Its simple interface lets you focus on coding. Available on Windows, macOS, and Linux. |
| Hidemaru Editor | A legendary Japanese text editor first released in 1993. Lightweight, fast, and equipped with a powerful macro system. Windows only, one-time purchase. |
| PhpStorm | A PHP-dedicated IDE by JetBrains. Offers deep framework integration, database tools, and advanced debugging. Paid. |
These days, Visual Studio Code seems to be the most widely used editor, but the webmaster personally loves simple and lightweight editors, so he currently uses Sublime Text. Feel free to use this as a reference.
A note about Hidemaru Editor: first released in 1993, Hidemaru is lightweight, features powerful search and replace with regular expressions, and can be customized with macros. In modern terms, macros are similar to add-ons — and Hidemaru had this capability back in the 1990s, a remarkably forward-thinking design that makes it a truly wonderful editor.
The webmaster himself used Hidemaru Editor for programming from the Windows 3.1 era through Windows 7, and owes a great deal to it over the years. Its developer, Hideo Saito, continues to update Hidemaru to this day — it runs perfectly on Windows 11 and other 64-bit versions of Windows. You can purchase Hidemaru Editor from here — it is a one-time purchase for around 4,000 yen (about $27), and having it on a Windows machine can be surprisingly handy.
(´-`).。oO(The webmaster wanted to give a personal shout-out to Mr. Saito, who he has relied on for years...)
(´-`).。oO(And yet, after 30+ years of use, the total cost has been just around $27... it's hard to find anything with better value for money...)
If you find any errors or copyright issues, please contact us.