Whether you run Linux/Unix, macOS or Windows as a server here are steps to install and configure PHP.
For Windows:
- Download PHP:
- Go to the PHP downloads page.
- Download the latest version of PHP (choose the thread-safe version if you plan to use it with a web server like Apache).
- Extract PHP:
- Extract the downloaded ZIP file to a directory (e.g., C:\php).
- Configure Environment Variables:
- Right-click on "This PC" or "My Computer" and select "Properties."
- Click on "Advanced system settings" and then "Environment Variables."
- Under "System Variables," find the Path variable and click "Edit."
- Add the path to your PHP directory (e.g., C:\php).
- Configure php.ini:
- Copy php.ini-development (or php.ini-production) to php.ini.
- Open php.ini and configure settings as needed (e.g., enable extensions).
- Test PHP:
- Open Command Prompt and type php -v to check the installation.
For macOS:
- Using Homebrew:
- Open Terminal.
- Install Homebrew if you haven't already:
bash
Copy
/bin/bash -c <span>"<span>$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)</span>"</span><br> - Install PHP using Homebrew:
brew install php<br>
- Test PHP:
- Type php -v in Terminal to verify the installation.
For Linux (Ubuntu/Debian):
- Update Package Index:
sudo apt update<br> - Install PHP:
sudo apt install php<br> - Install Additional Extensions (Optional):
sudo apt install php-cli php-mysql php-xml php-mbstring<br> - Test PHP:
- Type php -v in the terminal to verify the installation.
For CentOS/RHEL:
- Enable EPEL Repository:
sudo yum install epel-release<br> - Install PHP:
sudo yum install php<br> - Test PHP:
- Type php -v in the terminal to verify the installation.
Additional Notes:
- After installation, you may need to configure your web server (like Apache or Nginx) to use PHP.
- For development purposes, consider using tools like XAMPP or MAMP, which come with PHP and other components pre-configured.