Welcome to PHP Tutorial Series and this is the start of this PHP Tutorial Series.
Main topic of This PHP Tutorial Section –
- PHP Introduction
- How to setup a PHP Development Environment
- How to write and run your Frist PHP Code.
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 the large community, such as Laravel, CodeIgniter, etc.
Who use PHP?
Facebook, Wikipedia, Yahoo, Mailchimp, Dailymotion, WordPress etc.
How PHP Code Looks
<?php echo "Hi, I'm a PHP script!"; ?>
PHP can be embedded into HTML, but file extension must be .php
<!DOCTYPE html> <html> <head> <title>PHP Example</title> </head> <body> <strong> <?php echo "Hi, I'm a PHP script!"; ?> </strong> </body> </html>
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 need to know if you do not install XAMPP, then you how can 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)
XAMPP official website provides very well documentation of 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.
After install 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 –
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 start with <?php and end with ?>
<?php // PHP code goes here ?>
echo is used to show something in output and a PHP statements end with a semicolon;
<?php echo "This is a PHP Statement"; echo "This is another PHP Statement"; ?>
How to run PHP Code?
<?php 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 –
After starting the Apache and MySQL, now open your browser and type on URL –
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.
index.phpis the PHP file that we created inside the php_tutorials folder