How to Run PHP Code in Browser - onlyxcodes

Tuesday 21 May 2024

How to Run PHP Code in Browser

Hi PHP coder, In this tutorial I will show how to run PHP code in a browser.

PHP web development requires the ability to execute PHP code in a browser, which is the core component of that knowledge.

Whether you're a beginner trying to pick up the basics or an experienced developer wanting to refresh your skills, I will explain you step-by-step process of how to execute a PHP application on a browser.

how to run php code in browser

Step 1: Install Local Server Environment:

PHP requires processing by a web server before it can be sent to a browser because it is a server-side scripting language. We are required to build up a local server environment so that you can run PHP code on your local computer.

Here I included popular options for localhost servers.





In my system, I have installed the XAMPP server.

Step 2: Make Project Folder:

We must establish a separate project folder inside the local server once it has been installed.

Check my project's directory structure. I created a project folder with the name "test" inside the XAMPP/htdocs folder because I already have the XAMPP server installed on my PC.

+-- htdocs/

If you have installed the WampServer server on your system, so make this project folder inside the www folder and give it the "test" name.

I assumed you applied your project folder name "test."

+-- www/

Create this project in the htdocs folder if you have already installed the MAMP server on your machine.

+-- htdocs/

Create New PHP File:

I created a new file with the extension .PHP called "index" inside the project "test" folder.

For example, I made the index.php file.

+-- htdocs/

Step 3: Write PHP Code In the File:

I wrote the Hello World script inside PHP tags (<?php and ?>) in the index.php file and I have printed it using "echo"  statement.

Once we have written our PHP code save the index.php file to your local server's root directory. In my case, I saved this file XAMPP/htdocs folder.


	echo "Hello, World!"; // This will output "Hello, World!" in the browser

Step 4: Run PHP Application in Browser:

Now, that we have written our PHP code we will run it in a browser.

Open your web browser type "localhost/test/index.php" into the address bar and press enter.

Our project folder name is "test" as you can see in the URL. Since "index.php" serves as the default home page, typing in the URL is not necessary.


Hello, World!

No comments:

Post a Comment

Post Bottom Ad