PHP Installation
Installing PHP involves a few steps, which can vary slightly depending on your operating system. Below, I’ll outline the installation process for PHP on different systems and show some examples of how to verify the installation and check PHP output.
1. Windows Installation
a. Download PHP:
- Go to the PHP downloads page.
- Choose the appropriate version and download the Windows binaries (usually a zip file).
b. Extract the Files:
- Extract the downloaded zip file to a directory, e.g.,
C:\php
.
c. Configure PHP:
- Rename
php.ini-development
tophp.ini
and place it in the PHP directory. - Open
php.ini
with a text editor and configure it as needed (e.g., set theextension_dir
toext
directory inside PHP folder).
d. Add PHP to PATH:
- Go to System Properties > Environment Variables.
- Edit the
Path
variable and add the path to your PHP directory (e.g.,C:\php
).
e. Verify Installation:
- Open Command Prompt and type:
php -v
- You should see the PHP version information.
Example Output:
PHP 8.2.1 (cli) (built: Jan 1 2024 00:00:00) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.1, Copyright (c) Zend Technologies
2. macOS Installation
a. Using Homebrew (recommended):
- Open Terminal and run:
brew update brew install php
b. Verify Installation:
- After installation, check the PHP version:
php -v
Example Output:
PHP 8.2.1 (cli) (built: Jan 1 2024 00:00:00) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.1, Copyright (c) Zend Technologies
3. Linux Installation
a. Using APT (for Debian-based systems like Ubuntu):
- Open Terminal and run:
sudo apt update sudo apt install php
b. Using YUM (for Red Hat-based systems):
- Open Terminal and run:
sudo yum install php
c. Verify Installation:
- Check the PHP version:
php -v
Example Output:
PHP 8.2.1 (cli) (built: Jan 1 2024 00:00:00) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.1, Copyright (c) Zend Technologies
Creating a PHP Script to Test:
- Create a file named
info.php
in your web server’s root directory (e.g.,C:\inetpub\wwwroot
for IIS,/var/www/html
for Apache). - Add the following content to
info.php
:
<?php
phpinfo();
?>
- Access the file via your web browser by navigating to
http://localhost/info.php
.
Example Output:
- This page will show detailed information about the PHP configuration on your server, including PHP version, loaded extensions, and server environment.
Feel free to ask if you need more details on any step!
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Copyright 2023-2025 © All rights reserved.