• Tutorial List

PHP Introduction, Setup Dev Environment, Run PHP Code

Last updated May 15, 2020
PHP Introduction, Setup Dev Environment, Run PHP Code

PHP Introduction

What is PHP?

PHP Stands for PHP Hypertext Preprocessor(PHP). It is a popular open-source server-side scripting language and it was created by Rasmus Lerdorf in 1994.

Main Use of PHP

PHP is basically used to create dynamic websites by interacting with and without the database, and it can be embedded into HTML.

Why use PHP?

  • Easy to learn.
  • Large Community and resources.
  • Almost all hosting providers support PHP.
  • Most websites on the internet, are created in PHP.
  • PHP is compatible with multiple databases including MySQL.
  • PHP has lots of frameworks with a large community, such as Laravel, CodeIgniter, etc.

Who uses PHP?

Below are the names of popular sites/companies –

  • Facebook
  • Wikipedia
  • Yahoo
  • Mailchimp
  • Dailymotion
  • WordPress

How PHP Code Looks

  echo "Hi, I'm a PHP script!";
Browser Output
Hi, I’m a PHP script!

How to embedded PHP into HTML?

PHP can be embedded into HTML, but file extension must be .php

<!DOCTYPE html>
        <title>PHP Example</title>
            echo "Hi, I'm a PHP script!";
Browser Output
Hi, I’m a PHP script!

Extension of all PHP files should be .php like – index.php, home.php, about.php, etc.

Requirements for Learning PHP

  • Basic knowledge of client-side and server-side scripting
  • You must have knowledge of HTML and CSS.

Setup Dev Environment and Run PHP Code

As we all know that PHP is a server-side scripting language for that we need a server to run PHP.

In the time of learning or development, you do not need to buy any online server. You can run PHP by creating a local or dev server.

How to Create a Local server?

You can create a local server by installing XAMPP software. Or you can use WAMP. But I recommend you use XAMPP.

Why Use XAMPP Software?

First, you have to know, if you do not install XAMPP, then how can you set-up your local server?

Without XAMPP you can set-up your PHP Environment by installing Apache Server, MySQL Database OR MariaDB, and PHP.

But, if you will install the XAMPP, then you don’t need to install those applications separately. XAMPP will install Apache, MariaDB, PHP, and Perl on your Machine.

XAMPP provides you MariaDB, not MySQL DB. Don’t worry, both are almost same.

How to install XAMPP?

First, download the XAMPP from HERE, according to your OS (Mac, Linux, Windows).

The XAMPP official website provides very well documentation of the XAMPP installation. below, the resources of Xampp installation –

In the installation process, if you face this(see the below image), then ignore the not recommended option and choose another option and then click on Allow access.

Xampp Firewall

After installing the XAMPP, open the htdocs folder. You will find the htdocs folder inside your xampp installation folder.

To open the XAMPP installation folder, Open your XAMPP Control Panel and then click on Explorer. Like the below image –

Xampp Control Panel
xampp htdocs folder location

💡 Create a shortcut of the htdocs folder on your Desktop, so you can easily access this folder.

Now inside the htdocs folder create a new folder and name it whatever you want, here I named it php_tutorial.

After that go inside the newly created php_tutorial folder and inside this folder create a new file called index.php

To create the index.php you can use Notepad, Notepad ++, Brackets, VS code editor, etc.

How to Write PHP Code?

PHP code starts with <?php and end with ?>

// PHP code goes here

echo is used to show something in output and a PHP statements end with a semicolon;

echo "This is a PHP Statement";
echo "This is another PHP Statement";

How to run PHP Code?

echo "Hi, I'm a PHP script!";

To run index.php open your XAMPP Control panel and start Apache and MySQL. See the below image –

Start Apache Server

After starting the Apache and MySQL, now open your browser and type on URL –

Browser Output
Hi, I’m a PHP script!
  • http://localhost/ – On xampp, localhost targets the htdocs folder by default
  • php_tutorial – php_tutorial is the folder that we created inside the htdocs folder.
  • And index.php is the PHP file that we created inside the php_tutorials folder