How to Run a PHP Application on Ubuntu Localhost?
Last Updated :
05 Jan, 2023
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
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.
Similar Reads
How to install XAMPP on Windows ? XAMPP is the most popular software package which is used to set up a PHP development environment for web services by providing all the required software components. During the process of software deployment, most of the web servers use almost similar components, so use of XAMPP provides easy transit
4 min read
How to Install and Set up a WAMP Server ? Windows, Apache, MySQL and PHP is commonly abbreviated as WAMP. Some people may confuse with LAMP but the only difference between the two is their operating systems. In case of LAMP, L stands for Linux. Setting up a server included the installation of all the software listed in the abbreviation. Ano
3 min read
How to install PHP in Windows 10? PHP is a general-purpose scripting language geared towards web development. It is an open-source software (OSS), which is free to download and use. PHP stands for "Hypertext Preprocessor". PHP files are saved with an extension called .php. It supports many databases MySQL, Oracle, etc.Installation o
2 min read
How to Install PHP on Linux? PHP is a popular server-side scripting language that is especially used in web development. If you're working on a Linux environment, whether it's a personal development setup or a production server, you will likely need PHP installed. In this article, we will see the step-by-step guide to install P
2 min read
How to Install PHP on MacOS? PHP (Hypertext Preprocessor) is known as a general-purpose scripting language that can be used to develop dynamic and interactive websites. It was among the first server-side languages that could be embedded into HTML, making it easier to add functionality to web pages without needing to call extern
3 min read
How to set PHP development environment in windows ? What is PHP ? PHP (Hypertext PreProcessor) is a general-purpose programming language developed by Rasmus Lerdorf in 1994 for web development. This is one of the most popular programming language for beginners in web development because of its simplicity, large community and accessibility.Steps to se
3 min read
How to set up a PHP Console ? PHP is a backend server-side language of web development. In general, we don't need to take input from the console but sometimes we need to run a small function or block of code, for which we need to take input from the console. Requirements: Server: xampp or WampServer How to set up PHP Console ? S
1 min read
How to Install IMAP Extension in PHP on MacOS? Imap stands for Internet Message Access Protocol, It is a protocol used by email clients to retrieve email messages from mail servers, It is an application layer protocol in the OSI model. Imap allows us to store our messages on servers so that they can be accessed from multiple devices, whereas POP
4 min read
How to Install PHP GD-library on CentOS? GD is an open-source code library that helps to create and manipulate PNG, JPEG, and GIF images in PHP. GD is commonly used for the development of websites. Image resizing, cropping, drawing, and adding effects to dynamic rendering can easily be done with its help. Picture handling and GD capacities
2 min read
How to Install PHP Extensions on Windows? PHP is a general-purpose server scripting language. It is a powerful and important tool for developing dynamic and interactive Web pages. It is widely used, free, fast, flexible, and pragmatic. After installing PHP and a web server on Windows, extensions are also needed because they provide added fu
2 min read