Your First Hello World Script in PHP


PHP language is most used technology when it comes to developing websites or web apps.

hello world in PHP

Website development consist of two main component

  1. Frontend
  2. Backend

Frontend as it sound is all about the appearance and interactivity of web pages and the backend is about processing data, logics, etc.

Let’s consider an example of a contact form:-

How form will look is frontend and how the data of form will handled after submission is work of backend technology.

How to get started with PHP

As PHP is server side scripting language it needs server unlike HTML, CSS, JavaScript and jQuery which are client side language.

You can either install Apache or Nginx either one can be used to run PHP.

There are some pre-built solution to run a web server on your computer or laptop, here are those:-

  1. XAMPP – AMPP on XAMPP Stands for Apache, MariaDB, PHP, Perl and X stands for any platform or Cross-platform (OS like Windows, Linux or OS X)
  2. LAMP – LAMP stands for Linux, Apache, MySQL, and PHP. So it is only built for Linux.
  3. WAMP – WAMP stands for Windows, Apache, MySQL, PHP. So it is only for Windows.

Note – XAMPP runs MySQL so don’t get confused with the MariaDB.

Installing XAMPP (Web Server/Localhost) on OS X (MacBook Pro 13 2018) or any other platform

As I have Macbook Pro 13 (2018 touch bar), I will be guiding you to install XAMPP on MacBook Pro but you can use same instructions with Linux as well as Windows.

First go to https://www.apachefriends.org/download.html and download XAMPP based on your OS and hardware architecture. I am going to download the following version “7.0.26 / PHP 7.0.26” which you can directly download by clicking here.

Once you XAMPP is installed just click on it and installer wizard will start. Follow the steps as they are very easy.

That is really simple, isn’t it? Let get started with Hello World application.

Run Hello World in PHP (XAMPP)

Locate the “htdocs” directory in your system. It most likely will in following address /Applications/XAMPP/xamppfiles/htdocs/ if you are OS X user if now you can use search on window or Linux to find.

Once you located the folder you need to create a file with .php extension. .php extension is important because it tells server to execute this file as PHP so if you have .html extension then all the code you write on php will simply print instead of executing through server. Don’t worry you can use all html elements inside .php file.

I have created hello.php inside htdocs folder and now here is code to print “Hello World”

<?php echo "Hello World";?>

Code explanation:-

Now run php by opening following url in your browser – http://localhost/hello.php

and we are done with hello world program in PHP, after exploring a little more PHP you should follow my other article on how to install wordpress on localhost


Hope this article helped, don’t forget to comment, share and subscribe.