The Wayback Machine - https://web.archive.org/web/20240830223451/https://www.geeksforgeeks.org/how-to-run-php-programs/
Open In App

How to run PHP programs ?

Last Updated : 06 Jun, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

How to run PHP programs ?

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




<!DOCTYPE html>
 
<html>
<body>
  <h1>Hello GFG </h1>
 
  <?php
    echo "Hello geeksforgeeks";
  ?>
</body>
</html>


How to run PHP programs ?

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 

<?php   
//write your code here  
?>  

demo.php

PHP




<!DOCTYPE html>
<html>
 
<body>
 
  <h1>Hello GFG </h1>
 
  <?php
    echo "Inside gfgdemo FOLDER Hello geeksforgeeks";
   ?>
 
</body>
</html>


How to run PHP programs ?

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.

How to run PHP programs ?

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




<!DOCTYPE>
  <html>     
  <body>        
   
  <?php            
  echo "Hello world using echo </br>";             
  ECHO "Hello world using ECHO </br>";           
  EcHo "Hello world using EcHo </br>";        
  ?>     
  </body> 
  </html> 


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

Output:

How to run PHP programs?

Example 2: color.php

PHP




<html>     
  <body>        
  <?php             
  $color = "black";            
   echo "My car is ". $ColoR ."</br>";           
   echo "My dog is ". $color ."</br>";             
   echo "My Phone is ". $COLOR ."</br>";        
   ?>    
  </body> 
  </html> 


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


Similar Reads

Create a web server and run PHP script on it using Raspberry Pi
In this post, creating a web server and running PHP script on it using Raspberry Pi will be discussed. Web Servers are basically simple computer programs that dispense the web page when they are requested using the web client. The machines on which this program run are usually called as a server, with both the names web server and server almost use
2 min read
How to run two PHP versions for two projects on same apache server ?
In this article, we will learn about running two versions of PHP on the same Apache server. To manage many domains, the Apache webserver uses virtual hosts on a single instance. Prerequisite: We will be using the XAMPP server to use the Apache server and some knowledge to use it. First, download the older version of XAMPP that can be of any version
2 min read
How to run PHP code in Brackets ?
Brackets is a platform where HTML, CSS, JavaScript coding can be done. Editing these types of codes is very easy in Brackets. Pre-requisite for implementing PHP codes in Brackets: Install any local server in your machine like - Wamp, Xampp, or Mamp.Install Brackets. Features: It is platform-independent, which means it can be installed in any operat
2 min read
How to Run a PHP Application on Ubuntu Localhost?
PHP files include PHP tags and have the.php extension. In order to create static webpages, dynamic websites, or online apps, PHP is a server-side scripting language. Personal Home Pages, or PHP, is now known as Hypertext Pre-processor. On a server with PHP installed, PHP scripts can only be interpreted. A web browser is needed on client computers t
2 min read
How to Run Process with Realtime Output in PHP?
Running a process with real-time output in PHP involves using the "proc_open" function. This function provides control over the process, allowing interaction and capturing live output and errors. It's particularly useful for executing long-running tasks where immediate feedback is necessary. prerequisitesPHP Set Up XAMPPUsing proc_open() Method The
1 min read
Output of PHP programs | Set 1 (Regular Expressions)
Predict the output of following PHP programs: Question 1 &lt;?php echo str_pad(&quot;Welcome&quot;, 5).&quot; to GeeksforGeeks.&quot;; ?&gt; Options: WelcomeWelcomeWelcomeWelcomeWelcome to GeeksforGeeks. to GeeksforGeeks. WelcomeWelcomeWelcomeWelcomeWelcome to GeeksforGeeks. Welcome Welcome to GeeksforGeeks. Output: Welcome to GeeksforGeeks. Explan
3 min read
Output of PHP programs | Set 2 ( Filters )
Predict the output of the following PHP programs: Question 1 &lt;?php $num = &quot;123&quot;; if (!filter_var($num, FILTER_VALIDATE_INT)) echo(&quot;Hello&quot;); else echo(&quot;Welcome to GeeksforGeeks&quot;); ?&gt; Options: No output is returned Hello Welcome to GeeksforGeeks Error Output: Welcome to GeeksforGeeks Explanation: filter_var() – Fil
2 min read
Output of PHP programs | Set 3
Predict the output of below PHP programs: Question 1 &lt;?php $number = array(0, 1, one, two, three, 5); $num = preg_grep(&quot;/[0-5]/&quot;, $number); print_r($num); ?&gt; Options: Array([0]=&gt;0 [1]=&gt;1 [2]=&gt;one [3]=&gt;two [4]=&gt;three [5]=&gt;5) Array([2]=&gt;one [3]=&gt;two [4]=&gt;three) Array([1]=&gt; 1) Array([0]=&gt;0 [1]=&gt;1 [5]
3 min read
Output of PHP programs | Set 4
Predict the output of below PHP programs: Question 1 &lt;?php &quot;Welcome to GeeksforGeeks!&quot; ?&gt; Options: Error Welcome to GeeksforGeeks! Nothing Missing semicolon error Output: Nothing Explanation: If you need to output something onto the screen you’ll need to use echo or print_r. Question 2 &lt;?php print_r &quot;I am intern at GeeksforG
2 min read
Run Python script from Node.js using child process spawn() method
Node.js is one of the most adopted web development technologies but it lacks support for machine learning, deep learning and artificial intelligence libraries. Luckily, Python supports all these and many more other features. Django Framework for Python can utilize this functionality of Python and can provide support for building new age web applica
3 min read
How to run Cron Jobs in Node.js ?
Cron Jobs: These are the tasks that run periodically by the operating system. Users can schedule commands the OS will run these commands automatically according to the given time. It is usually used for system admin jobs such as backups, logging, sending newsletters, subscription emails and more. Prerequisites: Node.js installed NPM installed Basic
3 min read
How to Run Synchronous Queries using sync-sql Module in Node.js ?
The sync-sql module is designed to make synchronous queries to the database. Since normal SQL queries are asynchronous in node.js but if you want to run it synchronously, then it is possible using this module. In synchronized SQL, the result set is returned when the query is executed. Note: Do not use this module in production mode as node.js is de
2 min read
How to run a code on mouseenter event in jQuery ?
In this article, we will see how to run the code when the mouse enters into the specific area using jQuery. To run the code on a mouse enter a specific area, mouseenter() method is used. The mouseenter() method works when the mouse pointer moves over the selected element. Syntax: $(selector).mouseenter(function) Parameters: This method accepts sing
1 min read
How to Make, Save, and Run a Simple VBScript Program?
VBScript is a lightweight scripting version of the popular Microsoft Visual Basic, developed by as the name suggests, Microsoft. It is used to develop dynamic web pages. It is much lighter compared to Visual Basic programming language but works as a scripting language like JavaScript. To run VBScript on the client-side, the client must have to use
4 min read
Run Python Script using PythonShell from Node.js
Nowadays Node.js is the most attractive technology in the field of backend development for developers around the globe. And if someone wishes to use something like Web Scraping using python modules or run some python scripts having some machine learning algorithms, then one need to know how to integrate these two. We are going to get some data of a
3 min read
How to Run Multiple Versions of Node.js ?
Usually, we work on different versions for our Node.js project and it's hard to manage them, but fortunately, there is a tool called NVM(node version manager) which helps to manage your node version and switch between them according to your projects. Install NVM Module: You can install the nvm module using the following command: Using curl: $ curl
2 min read
How to run a node.js application permanently ?
NodeJS is a runtime environment on a V8 engine for executing JavaScript code with some additional functionality that allows the development of fast and scalable web applications but we can't run the Node.js application locally after closing the terminal or Application, to run the nodeJS application permanently. We use NPM modules such as forever or
2 min read
How to run a code on double-click event in jQuery ?
In this article, we will see how to run a code after double clicked the element using jQuery. To run the code on double clicked we use dblclick() method. This method is used to trigger the double-click event to occur. This method occurs when the selected element will be double clicked. Syntax: $(selector).dblclick(args); Parameter: It accepts an op
1 min read
How to run a code on document ready event in jQuery ?
In this article, we will see how to run a code when a page loads using jQuery. To run a code at page load time, we will use the ready() method. This method helps to load the whole page and then execute the rest code. This method specifies the function to execute when the DOM is fully loaded. Syntax: $(document).ready(function) Parameters: This meth
1 min read
How to run a code on hover event in jQuery ?
In this article, we will see how to change the style of elements on hover event using jQuery. To change the style of hover event, hover() method is used. The hover() method is used to specify two functions to start when the mouse pointer moves over the selected element. Syntax: $(selector).hover(Function_in, Function_out); Parameter: It accepts two
1 min read
How to run a code on click event in jQuery ?
In this article, we will see how to run the code after clicking on an event. To run the code after clicking an event, we use the click() method. The click() method is used to run the code when a click event occurs. The click() method to attach a click event handler to selected elements. Inside the handler function, you can define the code to be exe
1 min read
How to run a given array of promises in series in JavaScript ?
Given an array of Promises, we have to run that in a series. To do this task, we can use then(), to run the next promise, after the completion of a promise. Approach: The then() method returns a Promise, which helps us to chain promises/methods. The Promise.resolve() method executes the first callback, and when this promise is fulfilled, then it pa
3 min read
How to Run JavaScript from Python ?
In this article, we'll discuss how to run a javascript file with Python. For this, we'll use the JS2PY(Javascript Runtime in Pure Python) Python module. JS2PY works by translating JavaScript directly into Python. It indicates that you may run JS directly from Python code without installing large external engines like V8. To use the module it first
2 min read
How to run code on mouseleave event in jQuery ?
In this article, we will see how to run the code when the mouse leaves into a specific area using jQuery. To run the code on a mouse leave into a specific area, the mouseleave() method is used. The mouseleave() method works when the mouse pointer leaves the selected element. Syntax: $(selector).mouseleave(function) Parameters: This method accepts a
1 min read
How to run the code on keypress event using jQuery ?
In this article, we will see how to run the code snippet on the keypress event using jQuery. The keypress event is triggered when the keyboard button is pressed by the user. Syntax: $(selector).keypress() In the below example, we are creating a textarea element and when the user starts pressing a key to write some content on the textarea, the keypr
1 min read
How to run the code on change event using jQuery ?
In this article, we will see how to run the code on change events using jQuery. The change event is used to trigger when the user changes the value of the element. Syntax: $(selector).change(function) Example: In the below example, we are creating a textarea element that contains GeeksforGeeks text. When the user changes the textarea content and re
1 min read
Which command is used to run SASS code from the command line ?
In this article, we will discuss how to run SASS code from the command line. SASS (Syntactically Awesome Style Sheet) is a simple CSS pre-processor that makes it possible to create manageable, platform-independent, and reusable style sheets for websites. It is fully compatible with every version of CSS. Sass reduces the repetition of CSS and theref
3 min read
How to run a function in a separate thread by using a Web Worker in JavaScript ?
JavaScript is a popular lightweight, interpreted compiled client-side scripting language. Most Web Applications use JavaScript on the client side. By providing JavaScript with a runtime environment, it can also be used on the server-side (Node.js). In this article, we will cover how to run a function on a separate thread by using a JavaScript Web W
3 min read
How is Ajax different from JavaScript Libraries and Run Time Environments ?
Ajax is one of the important tools that every web developer should know. The concept that AJAX uses came around 1998 but AJAX became public when an article with the headline "AJAX: A New Approach to Web Application published. What is AJAX? Before knowing what AJAX is, we should be clear that AJAX is not a programming language. We all know that AJAX
3 min read
How to Run Node.js with Express on Mobile Devices ?
Node.js is a cross-platform open-source Javascript runtime environment and library for running web applications outside the browser. It is based on Chrome's V8 engine. Node.js is used to create server-side and command-line applications. Express.js is one of the most popular node frameworks. It is a Node.js web application framework that offers a va
2 min read