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
Step 2: Make sure the PHP package is installed successfully using the below command.
php –version
After running the above command you can output like in the below image if PHP is 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
Step 4: Now write your PHP Script to execute using the below command.
sudo gedit /var/www/html/index.php
After entering the above command the notepad will be opened with the file name index.php, Write your script in that file.
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’
Or You can Enter the below command to open.
xdg-open http://localhost
Step 7: You can see the executed PHP Script.
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 to access PHP scripts.
Contact Us