Now a days there are many programming languages available to run your code and build your own app or web applications.
If you want to check out more detail about What is Programming Language and Different types of programming Language then you can check out below links.
Here i am with all about PHP Programming Language.
Main Key Points which are covered in this article are as follow:
- What is PHP?
- Why PHP?
- How PHP Works?
- How to use PHP (How to install PHP) ?
- Syntax Of PHP
So let’s begin,
What is PHP?
PHP is a server side scripting language. This means PHP is executed on server side.
PHP is a sort name for ‘PHP: Hypertext Preprocessor’.
PHP is Free to use and download. So that world wide popularity of PHP increased very fast.
Now PHP is a powerful tool for making dynamic and interactive Web pages.
Here is Some popular examples which use PHP as their server side scripting language.
- The core of the biggest blogging system on the web (WordPress) is written using PHP.
- The largest social network (Facebook) runs using PHP.
Now you can understand how PHP is a powerful, deep and at the same time easy to use server side scripting language world wide, right !!
Here is some main points that give you idea why PHP is so popular and used word wide.
- PHP is free to download and use.
- Compatible with almost all servers used today (Apache, IIS, etc.).
- Runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.).
- Supports a wide range of databases.
- Easy to learn and runs efficiently on the server side.
How PHP Works?
To work with PHP we need to create PHP file having extension .php for an example hello.php
When we run PHP file on server then, PHP code is executed on the server and the result is returned to the browser as plain HTML.
Using PHP you can do all tasks which are listed below.
- Generate dynamic page content.
- Collect form data.
- add, delete, modify data in your database.
- create, open, read, write, delete, and close files on the server.
- send and receive cookies.
- To control user-access and encrypt data.
PHP output is not limited to HTML. It can output images, PDF files, even Flash movies and also text, such as XHTML and XML.
How to use PHP (How to install PHP in Windows) ?
To use PHP on your computer you need to install it first.
And there are possible ways to Install PHP on Windows.
- Manual Installation
- All-in-One Packages
- Using a .msi Installer
How to Install PHP on Windows Manually?
To install PHP manually the first thing you need to do is download the PHP package file of your choice from the official PHP downloads page.
On that page you will find .zip files available for both x86 and x64 systems, so make sure to download the correct one as per your Windows OS.
Here also you need to choose either to download the non-thread-safe or thread-safe version of PHP.
If you want to run PHP as an Apache module, the thread-safe version is recommended.
Or if you planning to run PHP as a CGI module, you can choose either of them.
Now got to your local directory(for example c:\php) in which you want install PHP and then extract the .zip file here.
Configure the php.ini Configuration File
This downloaded PHP package already contains two different versions of the configuration file:
- php.ini-development (designed and configured for your local development).
- php.ini-production (designed for optimum performance and security).
Here we’re going to use the php.ini-production file.
Because of PHP detects the php.ini file as its configuration file, we’re going to rename the php.ini-production (because we’re using production version) file to the php.ini file in C:\php directory.
Now open the php.ini file in your text editor and find the following line.
;extension_dir = "ext"
It is the path of the PHP extensions directory, So we need to change it as shown in the following.
extension_dir = "C:/php/ext"
Note that you have to remove the semicolon in front of the line to make sure it’s not commented.
And that’s it, you are finished the php.ini configuration file changes.
Configure the PATH Environment Variable
To configure PHP installation path to the PATH environment variable follow below steps.
- First, in the Windows search bar, just type the environment keyword and choose Edit the system environment variables in the search results.
- Now go to the Advanced > Environment Variables section.
- Edit the PATH environment variable and add
;C:\phpto the end.
This configuration will make sure that you can run PHP just by typing php from the command prompt, no matter which folder you are in.
Finally, restart the system, and you are done.
You have successfully installed PHP in your Windows installation.
Installing With an All-in-One Package
XAMPP and WampServer are popular all-in-one packages that allow you to install PHP along with the other essential web development components like a web server and database server.
First, to install XAMPP/WAMP go to below links and download them.
Now like other software just double click on source package and click on next and you are done with it.
To check is it working or not open command prompt and type below code,
And as a result you will get your latest version of PHP. If not then fill free to comment below what problem you are facing off.
Syntax Of PHP
To understand syntax of PHP let’s open your hello.php file in your favorite text editor.
In this file you can write PHP code anywhere in the document.
PHP code starts with
<?php and ends with
<?php // Your PHP code goes here ?>
A PHP file normally contains HTML tags, and some PHP scripting code.
<!DOCTYPE html> <html> <body> <h1>My first PHP Code</h1> <?php echo "Hello World!"; ?> </body> </html>
PHP statements end with a semicolon (;).
In PHP, keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are not case-sensitive.
But all variable names are case-sensitive.
And that’s It…
This is all about PHP to start with..
If you have any query or error related to installation of PHP then let me know by comment below.
Happy to help you.