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.


1. XAMPP


2. WAMP


3. MAMP


4. LAMP


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.


xampp/
+-- htdocs/
	+--test/

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."


wamp/
+-- www/
	+--test/

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


mamp/
+-- htdocs/
	+--test/

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.


xampp/
+-- htdocs/
	+--test/
		--index.php

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.


<?php 

	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.


Output:


Hello, World!

Learn More:

What does array splice do in PHP

What is POST variable in PHP

What is Custom PHP Development

How do you append to text in PHP

How to make OTP Verification in PHP

How to store textarea value in database in PHP

How to Fetch Data from Database in JSON format in PHP

How to get the class name in PHP

How to Check if a String is Null in PHP

How to Pass Dropdown Selected Value to Database in PHP

How to Create Drop Down List in PHP with MySQL

How to Process a Form using PHP

No comments:

Post a Comment

Post Bottom Ad