Getting Started With PHP
What is PHP?
PHP: Hypertext Preprocessor is a server-side scripting language that is used primarily for web development. The purpose of this programming language is to create fast paced dynamical web pages.
Learn a bit about server side scripting before PHP:
Actually scripting is another synonym for the program. This is some set of instruction which runs automatically when something runs. Server side means that these scripts are handled by the server rather than controlling the user’s computer. When someone visits PHP web pages, the web server will do some process for php codes such as what needs to be shown (picture, content etc.) and it will hide what it needs to be hidden (math calculation, file operation etc.) and finally transforms to HTML, the user’s web Send to the browser.
Software Needed for this article:
Web servers that support PHP have to be hosting. For this, you have to count the money. For now, we will install a web server on our computer. We will use a Apache web server, MySQL database, PHP text editor(notepad++ or Sublime Text) and web browser for user view.
All of the client software need to be installed are a web server such as apache and of course PHP and installing database software such as MySQL, which will be useful. All of these software are available free of charge. Surely you can download those software by searching Google. There is a software that will be install all those software once installed. And do not have to install separately. The software is XAMPP.
MAMP is for Mac PC. MAMP = Mac + Apache + MySQL + PHP
LAMP is for Linux. LAMP = Linux + Apache + MySQL + PHP
XAMPP = X (Cross Platform) + Apache + MySQL + PHP + Perl
XAMPP has been set up in PHP on any platform. All have the same work. XAMPP is a little more famous. Linux, Mac, Windows have all the related versions of XAMPP.
Installation process of XAMPP:
Step 1: Here is the link of XAMPP software to download. Go to the download software page and click on the latest version for you machine.
Step 2: After completing the download run the software as follows-
- Then select the components you want to install in this software and then click to next.
- Select a folder C:\xampp and click next
- Here is the https://bitnami.com/xamp server link click next
- Ready to install click to next
- Installing the XAMPP server
- After completing the XAMPP setup click to finish
- Select the language and save it.
Where to write PHP code:
If you have installed XAMPP on the C drive, then there is another folder named htdocs in this folder and keep your web content there.
The main directory of all the web documents is in “C:\xampp\htdocs” (but if you have installed it on another drive such as: D drive then it will be “D:\xampp\htdocs”). Now if you place a file named “mytest.php” in this directory, you can get access to it by typing in the browser’s address bar http://localhost/mytest.php.
Well, let’s start writing the code, where to write a code before it? Notepad ?. But there is some specialized software for PHP codecels, such as: Sublime text, Net Beans, Dreamweaver, etc. There are many advantages in writing codes; The benefits that you will not get in the Notepad. Use the one you like.
Mostly important thing before we start code part we have to ensure that XAMPP server is connected otherwise local host will not work properly.
PHP Syntax:
For PHP code to work, must save with the .php
extension when saving the file. If PHP is not .php
then PHP code will not execute.
- Every part of the PHP code will start with
<? php
symbol and - end with a
?>
- Each separate instruction (code line) will end with a semicolon.
Now open your code editor (Notepad / Dreamweaver /Sublime text or whatever you use) and type the following
Save the page as mypage.php, save it when htdocs is saved and save it in. In the browser’s address bar, enter http://localhost/mypage.php
. PHP script that uses a built-in PHP function echo
to output the text "This is my first PHP page"
on a web page.
Here echo works like print or printf which uses in programming language C, C++, JAVA. But in php uses echo.