To begin Programming in PHP, almost everyone is faced with this simple but obvious question:
How to run PHP Program for the first time? What's the easiest way?
Answer: The easiest way to run a PHP Program for the first time is using the software bundle named XAMPP:
XAMPP works well in all the major platforms: Windows, Mac and Linux.
You don't have to install Apache, PHP and MySQL separately, in fact, it is often difficult for beginners to install these bundles separately and combine them to run PHP CODE. XAMPP does that for you with just a few clicks.
Before you install XAMPP, you may have to uninstall existing Apache and MySQL installations, especially if they were installed as a service.
After you install XAMPP,
- Open any Text Editor.
Install new if you don't already have any good Text Editor installed. (My Favorite is Sublime Text & Notepad++)
- Write the following PHP Program / CODE in the Text Editor:
<?PHP echo 'I know how to run a PHP Program in XAMPP! <br />'; ?> This is test.php File.
- Save the file in
XAMPP Installation Directory\
Web Root Directory
Note-1: Default XAMPP Installation Directory in Windows is
Note-2: Default Web Root Directory in XAMPP is
htdocs. All your php files will have to be in this
That means, for a typical installation of XAMPP in Windows, you will have to save the PHP CODE in
- When you save the file, name it
test.php(just as an example, any valid file name with .php in the end will work).
Note: when you save this file, make sure it has no
.txtextension at the end. Some text editors place
.txtat the end of file name, so it becomes
test.php. To avoid this, when you save the file using any text editor, place double quote around the file name: e.g.
- Then, go to XAMPP installation folder (typically,
C:\xampp) and run
xampp-control.exeby double clicking it.
- In the
xampp-controlwindow, click the start button beside Apache. Later, if you need other options like MySQL, you'll also have to start MySQL by clicking the start button beside MySQL in the XAMPP control Panel.
Note: if your OS hides common file extensions, then you'll see
xampp-control, instead of
- Now, in your web browser's address bar, type the address:
If your test PHP file is working properly, then you should see the following two lines in your browser:
I know how to run a PHP Program in XAMPP!
This is test.php File.
If PHP is NOT working (but the web server Apache is working), in that case only the following one line result will appear:
This is test.php File.
If none of the above is happening, then you are doing something wrong somewhere else.
So now you know how to run PHP Program in XAMPP. Happy Coding