PHP Setup Guide - CodeSwordsman

Set up PHP: install on Windows, Linux and macOS, enable extensions in php.ini, install Composer with a mirror, run the built-in server, debug and fix common errors.

PHP 8.2 / 8.3Updated 2026-10-2929 commands

Install & Version Management

Install PHP 8.3 on Windows, then add the directory containing php.exe to PATH

winget install PHP.PHP.8.3

For a turnkey Apache/Nginx + MySQL + PHP stack on Windows, install Laragon

winget install LeNgocKhoa.Laragon

Install PHP and common extensions via Homebrew on macOS or the ondrej repo on Ubuntu

# macOS
brew install php@8.3
brew link --force php@8.3
# Ubuntu / Debian
sudo apt update && sudo apt install -y php8.3 php8.3-cli php8.3-mbstring php8.3-xml php8.3-curl

Confirm the version and list loaded extensions

php -v
php -m

Show which php.ini is in use before editing configuration

php --ini

Mirrors & Proxy

Switch the global Composer repository to the Aliyun mirror for much faster installs

composer config -g repos.packagist composer https://mirrors.aliyun.com/composer/

Confirm the mirror is written into the global config.json

composer config -g --list | findstr repos

Switch the mirror for this project only so other projects keep their own repositories

composer config repos.packagist composer https://mirrors.tencent.com/composer/

Configure credentials for a private repository; they are stored in the global auth.json

composer config -g http-basic.repo.example.com username password

Route composer through a proxy on Windows; use export on macOS/Linux

set HTTP_PROXY=http://127.0.0.1:7890
set HTTPS_PROXY=http://127.0.0.1:7890

Environment & Extensions

Add the PHP bin directory to PATH so php can be called directly

# Windows
setx PATH "%PATH%;C:\php"
# macOS / Linux
echo 'export PATH="/opt/homebrew/opt/php@8.3/bin:$PATH"' >> ~/.zshrc

Enable common extensions in php.ini; restart PHP-FPM or the web server afterwards

extension=mbstring
extension=openssl
extension=pdo_mysql
extension=curl

Point extension_dir at the ext folder on Windows or extension= entries fail to load

extension_dir = "C:\php\ext"

Check that the CLI and the web server read the same php.ini

php -i | findstr "Loaded Configuration File"

Check the memory limit before handling large files or batch jobs

php -r "echo ini_get('memory_limit');"

Create & Verify

Verify the CLI environment without a web server

php -r "echo PHP_VERSION, PHP_EOL;"

Create a Laravel project with Composer and start the dev server

composer create-project laravel/laravel demo
cd demo
php artisan serve

Use the built-in server for a zero-config preview; development only

php -S 127.0.0.1:8000 -t public

Restore dependencies from the lock file and refresh the autoload map

composer install
composer dump-autoload

Validate composer.json and check dependencies for known vulnerabilities

composer validate
composer audit

IDE & Plugins

Install the Xdebug debugger and Intelephense IntelliSense

code --install-extension xdebug.php-debug
code --install-extension bmewburn.vscode-intelephense-client

Enable Xdebug in php.ini for breakpoint debugging with an IDE

zend_extension=xdebug
xdebug.mode=debug,develop
xdebug.client_port=9003

Install the coding standard checker to keep team style consistent

composer global require squizlabs/php_codesniffer

Troubleshooting

When php is missing or the wrong version, check which executable PATH resolves

# Windows
where php
# macOS / Linux
which -a php

Run a syntax check to catch the errors behind blank pages or 500s

php -l index.php

Temporarily surface every error in development so nothing is swallowed

php -d display_errors=1 -d error_reporting=E_ALL -S 127.0.0.1:8000

Clear the cache and reinstall when packages download corrupted

composer clear-cache
composer install --no-cache

Run a one-shot check of network, mirror, certificate and config issues

composer diagnose

Switch the Windows console to UTF-8 when Chinese output is garbled

chcp 65001

This website uses cookies to ensure you get the best experience on our website. Privacy Policy.