Installing PHP
Installing PHP is a straightforward process. Depending on your operating system, there are different methods to install PHP. Below, we will cover the installation steps for Windows, macOS, and Linux.
Table of Contents
Installation on Windows
To install PHP on Windows, you can use XAMPP, which is a free and easy-to-install Apache distribution containing PHP, MySQL, and Perl.
Steps to Install XAMPP:
- Download the XAMPP installer from the XAMPP website.
- Run the installer and follow the installation instructions.
- Select the components you want to install (make sure to include PHP).
- Choose the installation directory and complete the installation.
- Start the XAMPP Control Panel and start the Apache server.
Installation on macOS
On macOS, you can use Homebrew, a package manager for macOS, to install PHP easily.
Steps to Install PHP using Homebrew:
- Open the Terminal.
- Install Homebrew if you haven't already by running:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Update Homebrew:
brew update
- Install PHP:
brew install php
Installation on Linux
On Linux, you can install PHP using the package manager specific to your distribution.
For Ubuntu/Debian:
- Open the Terminal.
- Update the package list:
sudo apt update
- Install PHP:
sudo apt install php
For CentOS/RHEL:
- Open the Terminal.
- Install the EPEL repository:
sudo yum install epel-release
- Install PHP:
sudo yum install php
Verifying the Installation
After installing PHP, you can verify the installation by opening the command line or terminal and running the following command:
php -v
Expected Output:
PHP 8.0.3 (cli) (built: Mar 2 2021 12:34:56) ( NTS )
Explanation: This command displays the installed version of PHP, confirming that the installation was successful. You should see output similar to the example, which includes the version number and additional details about the PHP installation.