PHP Installation

To run PHP on your own computer you need three things: a web server (like Apache), PHP and a database (like MySQL). Instead of installing them one by one, you can use a ready package. The most popular package for beginners is XAMPP. It is free and works on Windows, macOS and Linux.


Install PHP using XAMPP

  • Open apachefriends.org and download XAMPP for your operating system. Choose the version with a current PHP 8 release.
  • Run the installer and click Next. On Windows, if a security dialog appears, click Yes. Avoid the C drive path with spaces if you can, a simple folder like C:\xampp or D:\xampp is fine.
  • Keep Apache, MySQL and PHP selected in the components list, and finish the installation.
  • Open the XAMPP Control Panel and click Start next to Apache and next to MySQL. They will show a green background when they are running.
  • Open your browser and go to http://localhost. If you see the XAMPP welcome page, the server is working.
Note: If Apache does not start, another program (like Skype or IIS) may be using port 80. Close that program, or change the Apache port in the XAMPP settings.

Run your first PHP file

XAMPP serves files from its htdocs folder (for example C:\xampp\htdocs). Create a new folder inside it named mysite, and save a file hello.php in it with this code.

<?php
echo "Hello from PHP!";
?>

Now open http://localhost/mysite/hello.php in the browser.

Output:

Tutorials Class - Output Window

Hello from PHP!

Do not open the file by double click, because then PHP is not used and the browser shows the code. A PHP file must always be opened with the http://localhost address.


Check the PHP version

<?php
echo "PHP version: " . PHP_VERSION;
?>

Output:

Sample output, your version can be different

PHP version: 8.2.12

You can also see all settings with the phpinfo() function. Remove such a test file from a live server, because it shows private information.


Other ways to run PHP

OptionDetails
Built-in serverIf PHP is installed, run php -S localhost:8000 inside your project folder. No Apache needed. See how to run PHP from the command line
Laragon, WAMPEasy packages for Windows
MAMPA similar package for macOS
DockerGood if you want the same setup as your live server

You also need a good code editor. Visual Studio Code is free and works very well for PHP.

Next chapter: PHP Syntax.


Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
Write a program to print “Hello World” using echo
Simple Tips for PHP Beginners
Experiment with Basic PHP Syntax Errors
Using phpinfo() – Display PHP Configuration & Modules
Interview Questions & Answers
What is PHP?
Who is the father of PHP?
What is the correct & common way to start and finish a PHP block of code?
What is Open Source Software?
What is the default extension of the PHP file?
What is the latest version of PHP?
What is the full form of PHP?