What are the requirements in running php?

In this tutorial we assume that your server has activated support for PHP and that all files ending in .php are handled by PHP. On most servers, this is the default extension for PHP files, but ask your server administrator to be sure. If your server supports PHP, then you do not need to do anything. Just create your .php files, put them in your web directory and the server will automatically parse them for you. There is no need to compile anything nor do you need to install any extra tools. Think of these PHP-enabled files as simple HTML files with a whole new family of magical tags that let you do all sorts of things.

Let us say you want to save precious bandwidth and develop locally. In this case, you will want to install a web server, such as » Apache, and of course » PHP. You will most likely want to install a database as well, such as » MySQL.

You can either install these individually or choose a simpler way. Our manual has installation instructions for PHP (assuming you already have some web server set up). If you have problems with installing PHP yourself, we would suggest you ask your questions on our » installation mailing list. If you choose to go on the simpler route, then » locate a pre-configured package for your operating system, which automatically installs all of these with just a few mouse clicks. It is easy to setup a web server with PHP support on any operating system, including MacOSX, Linux and Windows. On Linux, you may find » rpmfind and » PBone helpful for locating RPMs. You may also want to visit » apt-get to find packages for Debian.

There are no user contributed notes for this page.

What you need to run PHP on your computer and how to setup a WAMP server is explained in this tutorial.

What You Need to Run PHP

  1. Web Server (e.g., Apache)
  2. PHP (Interpreter)
  3. MySQL Databases (optional)

You can separately install Web Server, PHP Interpreter, and MySQL databases, but to make work easier, developers have made all in one setup packages called WAMP, LAMP, MAMP, and XAMPP, which will automatically install and set up PHP environment on your Windows, Linux or MAC machines.

  • WAMP (Windows, Apache, MySQL, PHP)
  • LAMP (Linux, Apache, MySQL, PHP)
  • MAMP (MAC, Apache, MySQL, PHP)
  • XAMPP (Windows/Linux/MAC, Apache, MySQL, PHP)

Start Where?

To execute PHP code, you need access to a web server in which PHP is running.

Your main options are:

  • Install Apache and PHP or Install WAMP, LAMP, MAMP, or XAMPP according to your OS.
  • After installation, you need to run and start the Apache Server and PHP from your program list, and then type http://localhost in your web browser to start working.
  • In the Apache installation folder, you will find the www folder, where you can save PHP files, and you can also create your project folder inside the www folder.

or

  • Find a web hosting plan with Apache, PHP, and MySQL support, and Run your PHP scripts on your Web host.

Installing WAMP Server

Creating the Script

You need to use a text editor program to write your code.  All OS comes with one or more text editors, for example:

  • Windows Notepad
  • Vi or Emacs on Linux
  • TextEdit on Mac OS X

Commercially, Adobe Dreamweaver,  NetBeans, and Sublime Text are used to edit PHP code.


What are the requirements in running php?

XAMPP is a Web development tool, created by Apache, that makes it easy to run PHP (Personal Home Pages) scripts on your computer locally. Installation of XAMPP Server on windows is easy as compared to manual installation of a web server and PHP required a lot of in-depth configuration knowledge. XAMPP package installs MySQL, FileZilla, Mercury, Perl, and Tomcat along with Web Server and PHP, with these applications you can test the full website on your desktop. You don’t need to upload it every time on an online Web server.

Step 1: First of all, open the Apache Friends website and download XAMPP for Windows, and install it.

Step 2: Start the XAMPP Program Control Panel. Click on the “Start”  button next to the “Apache” to start your Apache Web Server. Also, start “MySQL” if your PHP programs depend on a MySQL database to run.

What are the requirements in running php?

How to run PHP programs ?

Step 3: Place your PHP files in the “htdocs” folder located under the “XAMPP” folder on your drive (i.e. C/D/E etc). The initial path is “your_drive_letter:\xampp\htdocs” for your Web server. Make sure that your PHP files are saved as a “.php” file extension.

Example: The “demo.php” file is saved in the htdocs folder.

PHP

  

Hello GFG

  

    echo "Hello geeksforgeeks";

  ?>

What are the requirements in running php?

How to run PHP programs ?

Step 4: Open up any web browser and enter “localhost/filename”. This will open the list of all the files and folders stored under the “htdocs” folder on your computer. Click on the link to a PHP file and open it to run a program.

Example: The file “demo.php” file is placed inside the “htdocs” folder. If you want to run it, open any web browser and enter “localhost/demo.php” and press enter. Your program will run.

Syntax: php have special Syntax to write a code, as shown in below 


//write your code here  
?>  

demo.php

PHP

  

Hello GFG

  

    echo "Inside gfgdemo FOLDER Hello geeksforgeeks";

   ?>

What are the requirements in running php?

How to run PHP programs ?

Step 5: You can create any folder to test PHP files under the “htdocs” folder. If you create a specific folder then you need to use the address as “localhost/foldername” to open them in your browser.

Example: The “demo.php” file is placed inside the “gfgdemo” folder. Enter “localhost/gfgdemo/demo.php” in your browser and press enter, your program will be run.

What are the requirements in running php?

How to run PHP programs ?

PHP case sensitivity

PHP is case sensitive language, in that variables and functions, tags are case sensitive but classes are not case sensitive. Below the example of case sensitivity of php. 

Example 1: echo.php

PHP

       

          

  

  echo "Hello world using echo
"
;             

  ECHO "Hello world using ECHO
"
;           

  EcHo "Hello world using EcHo
"
;        

  ?>     

   

   

In above code we write three different types of echo methods, see the output in the image. 

Output:

What are the requirements in running php?

How to run PHP programs?

Example 2: color.php

PHP

     

          

  

  $color = "black";            

   echo "My car is ". $ColoR ."
"
;           

   echo "My dog is ". $color ."
"
;             

   echo "My Phone is ". $COLOR ."
"
;        

   ?>    

   

   

In the above example, the variable name is case sensitive, so it gives error.

Output:

My car is 
My dog is black
My Phone is 

PHP Notice:  Undefined variable: ColoR in HelloWorld.php on line 3
PHP Notice:  Undefined variable: COLOR in HelloWorld.php on line 5

What are the steps to run PHP program?

You just follow the steps to run PHP program using command line..
Open terminal or command line window..
Goto the specified folder or directory where php files are present..
Then we can run php code using the following command: php file_name.php..

Do you need a server to run PHP?

Instead, you need PHP on a web server. It's the web server—not the web browser—that can interact with a PHP interpreter. Your browser can handle HTML on its own, but it has to make a request to a web server to deal with PHP scripts.