Install PHP
To install PHP, we will suggest you to install AMP (Apache, MySQL, PHP) software stack.
It is available for all operating systems. There are many AMP options available in the
market that are given below:
o WAMP for Windows
o LAMP for Linux
o MAMP for Mac
o SAMP for Solaris
o FAMP for FreeBSD
o XAMPP (Cross, Apache, MySQL, PHP, Perl) for Cross Platform: It includes some
other components too such as FileZilla, OpenSSL, Webalizer, Mercury Mail, etc.
If you are on Windows and don't want Perl and other features of XAMPP, you should
go for WAMP. In a similar way, you may use LAMP for Linux and MAMP for Macintosh.
How to install XAMPP server on windows
https://www.apachefriends.org/download.html
Step 2: After downloading XAMPP, double click on the downloaded file and allow
XAMPP to make changes in your system. A window will pop-up, where you have to
click on the Next button.
Step 3: Here, select the components, which you want to install and click Next.
Step 4: Choose a folder where you want to install the XAMPP in your system and
click Next.
Step 5: Click Next and move ahead.
Step 6: XAMPP is ready to install, so click on the Next button and install the XAMPP.
Step 7: A finish window will display after successful installation. Click on
the Finish button.
Step 8: Choose your preferred language.
Step 9: XAMPP is ready to use. Start the Apache server and MySQL and run the php
program on the localhost.
Step 10: If no error is shown, then XAMPP is running successfully.
How to run PHP code in XAMPP
Generally, a PHP file contains HTML tags and some PHP scripting code. It is very easy
to create a simple PHP example. To do so, create a file and write HTML tags + PHP
code and save this file with .php extension.
Note: PHP statements ends with semicolon (;).
All PHP code goes between the php tag. It starts with <?php and ends with ?>. The
syntax of PHP tag is given below:
1. <?php
2. //your code here
3. ?>
How to run PHP programs in XAMPP
How to run PHP programs in XAMPP PHP is a popular backend programming
language. PHP programs can be written on any editor, such as - Notepad, Notepad++,
Dreamweaver, etc. These programs save with .php extension, i.e., filename.php inside
the htdocs folder.
For example - p1.php.
As I'm using window, and my XAMPP server is installed in C drive. So, the path for the
htdocs directory will be "C:\xampp\htdocs".
PHP program runs on a web browser such as - Chrome, Internet Explorer, Firefox, etc.
Below some steps are given to run the PHP programs.
Step 1: Create a simple PHP program like hello world.
1. <?php
2. echo "Hello World!";
3. ?>
Step 2: Save the file with hello.php name in the htdocs folder, which resides inside
the xampp folder.
Note: PHP program must be saved in the htdocs folder, which resides inside the
xampp folder, where you installed the XAMPP. Otherwise it will generate an error -
Object not found.
Step 3: Run the XAMPP server and start the Apache and MySQL.
Step 4: Now, open the web browser and type localhost http://localhost/hello.php on
your browser window.
Step 5: The output for the above hello.php program will be shown as the screenshot
below:
Most of the time, PHP programs run as a web server module. However, PHP can also
be run on CLI (Command Line Interface).