ICTShore.com

We re-branded, ictshore.com is now accelerates.it!

How to install PHP on Windows with XAMPP

How to install PHP on Windows with XAMPP

Share This Post

PHP is still one of the most popular options you have to run a website. It is simple, fast to write, and fast to execute. Furthermore, it can run virtually on any platform. Because of that, some people love PHP, while others hate it. Doesn’t matter which side you pick, you need to know how to run PHP. It is one of the IT skills that will come handy sooner or later. Thus, in this article, we explain how to set-up a PHP environment on a Microsoft Windows Machine. Just read on, and learn how to install PHP on Windows with XAMPP.

Install PHP On Windows

Introducing XAMPP

XAMPP is the best way to go if you want PHP on Windows. It is an all-inclusive suite that installs you PHP, Apache, MySQL, and optionally FileZilla server and Tomcat. In other words, everything you need to run a website on your PC. XAMPP is good to install PHP on both desktop computers and production servers. What do you get exactly?

  • PHP Interpreter – Your PC will understand PHP scripts, and you can even call them from the terminal. This is included in Apache (see next).
  • Apache – This is the webserver. It can listen to HTTP or HTTPS requests and process them with PHP scripts
  • MySQL – A popular type of SQL database to store the data of your website in a standard manner
  • XAMPP Control Panel – Intuitive dashboard to control the other services and restart them

So, the first step to install PHP on Windows is to get XAMPP from Apache Friends. Just go to their website here and download the Windows version. XAMPP is also available for Linux and MAC, in case you want it. The latest XAMPP version will come with the latest stable PHP version.

Installing XAMPP

Download XAMPP from Apache Friends as said above.

To install PHP on Windows, first download XAMPP
The download page on XAMPP website.

You will get an executable file from your download. Just run it, and follow the step-by-step setup. By default, XAMPP will install itself into C:/xampp, but you can change that if you want. Inside that folder, you will find all the files you need to configure your web server. Here are some example files you will find in that folder.

XAMPP installs everything you need to run PHP on Windows.
Content of the C:\xampp folder.

Running your Web Server

If you want to install PHP on Windows, it is probably because you want to run a web server. That’s simple, all you need to do is launch the web server from the XAMPP control panel. Just search for XAMPP Control Panel in your start menu and open it, you will see the following screen.

From the XAMPP control panel you can start and stop the services you need to run a website, necessary to install PHP on Windows
The XAMPP Control Panel.

At this point, you only need to start Apache, but I recommend starting MySQL as well. To do that, simply use the Start button on the Apache and MySQL lines. If everything goes well, the module name will be highlighted in green, like below. If not, we need to check the logs below and do some troubleshooting.

Once you have your services up and running in XAMPP, you can start serve your website. You will see them in green.
Services are up and running.

Don’t see that? Don’t worry, it’s hard to have everything running on the first attempt. We got you covered, just read below.

XAMPP Troubleshooting Apache

The most common problem is Apache that won’t start. However, if we want to install PHP on Windows we need to make it work. Probably, the most common reason is a conflict on port 80 or port 443. XAMPP uses those ports to serve the website, but it means that those ports must be free. If another program is using them, you will have a problem. If you are lucky enough, you will see the program name in the XAMPP log. If not, we need to check the Windows Event Viewer. Just search for Event Viewer in your Start Menu, then select the Application Logs inside the Windows Logs from the left menu. You will see a list of logs, and hopefully some details about XAMPP problem right on top.

Check for errors of your PHP installation in the Windows Event Viewer.
Windows Event Viewer page.

For example, Skype is a program that can create conflicts. Luckily, you can change your Skype configuration to avoid using port 80 or 443, removing the conflict. Of course, you could do that on the Apache side as well, but we don’t recommend that to new users of Apache. Once you cleared all conflicts, you will be able to start the services and see them in green.

Serving the wesbite

A website is a collection of static and dynamic files available over the web. By default, XAMPP puts those files in C:\xampp\htdocs. You can empty this folder and put your HTML, CSS, and PHP files here. Then, you can access them by browsing at http://localhost or http://127.0.0.1 (they are equivalent). For example, you can create your example Hello World script in a file named hello.php. In it, write the following code:

<?php
echo 'Hello, world!';
?>

Then, navigate to http://localhost/hello.php and you will see Hello, World! on the page.

PHP From the Command Line

At this point, we know how to install PHP on Windows and we have a fully functional setup. However, we might want to run some PHP scripts directly from the CLI. This is very important if you want to use complex frameworks like Laravel to build your applications.

To do that, we simply need to add our php.exe to our System Path. Search for This PC in the Start Menu, then click Advanced System Settings on the left and the Environment Variables on the bottom-right of the window that will pop-up. From the User variables of the top box, select the variable named Path and double-click on it. Then, click on New and write the path to your php.exe file. If you installed everything with default settings, it will be C:/xampp/php/php.exe. OK your way out of the windows you opened and you are set to go.

Now, open the command prompt and type php --version. You will see something like this.

As part of this install PHP on Windows tutorial we see how to install and use it from the CLI. To check your installation, just run php --version.
PHP running from the CLI.

You can execute php <script name> to run a PHP file as well. Plus, Apache doesn’t need to be running to do that.

Wrapping it up

In this article, we saw how to install PHP on Windows. Now, you can create your PHP websites and run them on your Windows PC or Server. To do that, you only need to install XAMPP. Furthermore, you can add PHP to your command terminal by adding php.exe to your System PATH variable.

What do you think about XAMPP and PHP? Let me know in the comments!

Picture of Alessandro Maggio

Alessandro Maggio

Project manager, critical-thinker, passionate about networking & coding. I believe that time is the most precious resource we have, and that technology can help us not to waste it. I founded ICTShore.com with the same principle: I share what I learn so that you get value from it faster than I did.
Picture of Alessandro Maggio

Alessandro Maggio

Project manager, critical-thinker, passionate about networking & coding. I believe that time is the most precious resource we have, and that technology can help us not to waste it. I founded ICTShore.com with the same principle: I share what I learn so that you get value from it faster than I did.

Join the Newsletter to Get Ahead

Revolutionary tips to get ahead with technology directly in your Inbox.

Alessandro Maggio

2019-05-30T16:30:38+00:00

Unspecified

Dev

Unspecified