Open In App

How to Run a PHP Application on Ubuntu Localhost?

Last Updated : 05 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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 to access PHP scripts.

Localhost

The phrase “Localhost” is typically used in relation to networks. The domain name of the virtual server is localhost, in addition to its name. Localhost is a top-level domain designated for documentation and testing, just like. example, test, or. invalid. A loopback is started when attempting to access the domain. When you use the browser to view “http://localhost,” the request is not routed through the router to the internet. Instead, it will stay in your body. The IP address of the localhost is 127.0.0.1. This is a reference to your personal server.

Steps to Run PHP Program on Ubuntu Localhost

Let’s see the tutorial to run PHP programs on ubuntu localhost.

Step 1: First, We need to install PHP Package in ubuntu using Sudo apt-get install <Package-Name>, Enter the below command to install the PHP package in ubuntu.

sudo apt-get install php

installing-php-package

 

Step 2: Make sure the PHP package is installed successfully using the below command.

php –version

ensuring-installation-of-packages

 

After running the above command you can output like in the below image if PHP is successfully installed.

php-successfully-installed

 

Step 3: Now, we can execute the PHP program on ubuntu, We need to replace the default apache page with our PHP page. To do that run the below command.

sudo mv /var/www/html/index.html /var/www/html/index.back

executing-php-program

 

Step 4: Now write your PHP Script to execute using the below command.

sudo gedit /var/www/html/index.php

writing-php-script

 

After entering the above command the notepad will be opened with the file name index.php, Write your script in that file.

notepad-opened

 

You can use below sample program to test.

<?PHP

echo “Hello GEEKS! <br>”;

echo “You Have Successfully Executed PHP Script On Ubuntu Localhost”

?>

Step 5: Save the file using ctrl+s.

Step 6: Now you can run the PHP script by opening any browser and typing ‘http://localhost’

opening-browser

 

Or You can Enter the below command to open.

xdg-open http://localhost

command-to-open-browser

 

Step 7: You can see the executed PHP Script.

executed-php-script

 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads