
How to Write Your First Hello World Program in PHP?
First of all, you must have PHP installed on your local machine. You can get that done by installing an XAMP (Cross-Platform, Apache, MySQL, and PHP) or WAMP (Windows, Apache, MySQL, and PHP) server.
XAMP works on all operating systems and WAMP works only in Windows. I will be using WAMP.
Open up the WAMP or XAMP server and make sure all services are running. If you are using WAMP, the WAMP logo should show on your taskbar with the color green.

Open up your C drive and look for the installation directory of your WAMP server. In my case, it is wamp64.

Open the installation directory, and then the www folder.

Create a folder right there and name it whatever you want, then open up the folder with your code editor.
Create an index.php file and paste in the following code:
<?php
echo "Hello World";
?>
You can also put your “Hello World” text in a variable, then use the echo system to display it in the browser.
In PHP, you can declare a variable with the dollar sign ($). Your statements, apart from the last one, must also be terminated by a semi-colon.
<?php
$greeting = "Hello World";
echo $greeting
?>
To run your code in the browser, open up the browser and write this in the address bar localhost/the-folder-of-your-php-file/php-file.php, then hit enter.
Make sure your WAMP or XAMP server is running, otherwise it won’t work.

You can see that the code successfully ran in the browser, because I got the file path right.
Another beautiful thing about PHP is that you can embed it in HTML. You can do it like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Code</title>
</head>
<body>
<h1> This is the result of a PHP Code embedded in HTML</h1>
<?php
$greeting = "Hello World";
$campers = "Hello Campers";
echo $greeting;
echo "<br>";
echo $campers
?>
</body>
</html>

Conclusion
PHP remains a relevant and widely-used language in web development. Despite the mockery and debate on whether it’s still valuable, PHP developers keep earning good livings from working with the language. So, PHP doesn't seem to be going anywhere anytime soon.
Now, go code some PHP!
Thank you for reading, and keep coding.
Comments
Add new comment