How to run PHP code
In this article, I would like to discuss about how to run PHP code using the wamp server. Before we write and execute the PHP script first we need to check whether the PHP engine is working/running or not. Because the PHP engine is responsible for executing the PHP script.
Step By Step Guide to run PHP
Follow these simple steps to execute your PHP script easily.
1. Download the PHP engine
The web development environment allows us to develop web applications locally. To set up a web development environment for developing web applications, especially using PHP and MYSQL, according to the system specification we need to install one of the below-mentioned software packages.
2. Check PHP engine is working or not
Click on the WAMP server icon available on the taskbar or in the tray, you get a context menu; click on the local host option. You will see the “WAMP server home page” open in the default browser.
If you see the “WAMP server home page” open in the default browser then you can say the PHP engine is running and you can start writing and executing the PHP scripts.
Note : (Local host refers to the local server running on the computer system and it points to the root directory of the local server)
3. Writing PHP script
- open notepad
- Type the below basic PHP code for testing the PHP script is working or not
<?php echo "Hello World"; ?>
- And save the file in “www.directory” with the file extension .php, Ex: helloworld.php
4. Executing PHP script
- Open the browser
- Type localhost/helloworld.php
- You should see in the browser window the “Hello World” output is displayed.
See the above image output, the PHP code is successfully displayed.
Conclusion
If you don’t get the PHP code display try a new package of WAMP or check if you made any mistake while saving the PHP file.