There are two options.

  1. Access the php file through a local webserver(ie thru a local website). The web-server will deal with the requested php file. It will use either,

    • Inbuilt PHP module to interpret the php file, or
    • PHP through CGI (eg.CGI, FastCGI)

      If your apache(check if apache is running using service apache2 status!!) is set to the default configuration, this could be as simple as

      http://localhost/path/to/your.php
      

      Remember by default, the base directory for apache is /var/www/html/, so you need not include this in the url.

  2. Use the php binary directly from a terminal.

       php /path/to/your/file.php
    
Answer from sjsam on Stack Overflow
🌐
Ubuntu
documentation.ubuntu.com › server › how-to › web-services › install-php
How to install and configure PHP - Ubuntu Server documentation
December 11, 2025 - PHP-CLI You can run PHP scripts via the Command Line Interface (CLI). To do this, you must first install the php-cli package.
🌐
Allaboutlinux
allaboutlinux.eu › how-to-run-php-on-ubuntu
How to run PHP on Ubuntu | allaboutlinux.eu
I have never used Ubuntu, but I have used Fedora and currently using Debian because the platform I am using for hosting my PHP app has Debian (https://www.cloudways.com/en/php-cloud-hosting.php ). I have noticed that Debian has a relatively better performance and less system related issues. ... Well said. How to run PHP on Ubuntu concept id interesting.
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-run-a-php-application-on-ubuntu-localhost
How to Run a PHP Application on Ubuntu Localhost? - GeeksforGeeks
July 23, 2025 - 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. ... Step 2: Make sure the PHP package is installed successfully using the below command.
🌐
Techomoro
techomoro.com › home › ubuntu › how to run a php application on ubuntu
How to Run a PHP Application on an Ubuntu System ← Techomoro
November 23, 2021 - This is a simple tutorial on running a PHP file or a PHP Project on an Ubuntu system. It covers the installation of LAMP.
🌐
ServerHub
serverhub.com › home › learn how to install, configure, & run php on ubuntu server
Learn How to Install, Configure, & Run PHP on Ubuntu Server
November 1, 2023 - PHP (Hypertext Preprocessor) is a server-side scripting language that was created by programmer Rasmus Lerdorf in 1993 and released in 1995. In this article, we’ll discuss an overview of PHP, why you need it for your Ubuntu server, and the steps on how to install, configure and test the configuration of PHP on an Ubuntu server.
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to install php on ubuntu
How To Install PHP On Ubuntu 20.04 or 22.04 | phoenixNAP KB
February 13, 2025 - This tutorial will guide you through installing PHP on Ubuntu, including its integration with Apache and Nginx web servers. ... A Linux system running Ubuntu.
Find elsewhere
🌐
DEV Community
dev.to › alvinqingxing › testing-and-deploying-a-php-app-in-ubuntu-2i5h
Testing and Deploying a PHP App in Ubuntu - DEV Community
March 30, 2021 - A better solution will be to activate Apache's User Directory feature, which will allow you to run your PHP code from a new public_html directory in your home folder. The following command will activate the User Directory feature: ... Next, you will need create the User Directory (~/public_html) and set the correct directory permissions: mkdir $HOME/public_html chmod +x $HOME chmod 755 $HOME/public_html · You will then need to enable PHP scripting in the User Directory (by default Ubuntu disables this).
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-install-php-on-ubuntu
How to Install PHP on Ubuntu? - GeeksforGeeks
July 23, 2025 - This is the simplest method, we use apt package manager to install the PHP into the Ubuntu system, The following are the steps involved: ... The first step is to open the Ubuntu terminal and apply sudo rights, To open the terminal (Ctrl+Alt+T) type the following command, then enter the system's user password: ... Now run the following commands to update the index and repository for the latest repositories using the following command:
🌐
Sololearn
sololearn.com › en › Discuss › 120711 › how-to-run-php-in-linux-ubuntu
How to run php in linux ubuntu? | Sololearn: Learn to code for FREE!
you have to save your PHP files inside: /opt/lampp/htdocs then open your browser and enter this address: http://localhost/your_file.php enjoy it! ... apt-get update apt-get upgrade apt-get install curl curl --silent --location https://deb.n...
🌐
Contabo
contabo.com › home › how to install php on ubuntu vps – a comprehensive guide
How to Install PHP on Ubuntu VPS – a Comprehensive Guide | Contabo Blog
September 20, 2025 - Setting up PHP on Ubuntu is quick, and the same steps work across most modern Ubuntu releases. In the next subsections, we’ll update the system’s package list, install PHP itself, run command line tests, and set it up with popular web servers like Nginx and Apache.
🌐
Ubuntu Manpages
manpages.ubuntu.com › manpages › trusty › en › man1 › php5.1.html
Ubuntu Manpage: php - PHP Command Line Interface 'CLI'
February 4, 2024 - By using the -S option where addr:port point to a local address and port PHP will listen to HTTP requests on that address and port and serve files from the current working directory or the docroot passed by the -t option. If none of -r -f -B -R -F -E or -S is present but a single parameter is given then this parameter is taken as the filename to parse and execute (same as with -f). If no parameter is present then the standard input is read and executed. --interactive -a Run PHP interactively.
🌐
Serverspace
serverspace.io › support › help › installing-and-configuring-php-on-ubuntu
Installing and Configuring PHP on Ubuntu - Serverspace.io
July 27, 2025 - Discover how to install and configure PHP on Ubuntu for dynamic web development! Step-by-step guide covers setup, Apache integration, key settings, and troubleshooting.
🌐
Linuxize
linuxize.com › home › php › how to install php on ubuntu 20.04
How to Install PHP on Ubuntu 20.04 | Linuxize
January 19, 2026 - Ondřej Surý, a Debian developer, maintains a repository that includes multiple PHP versions. To enable the repository , run: ... sudo apt install php7.1 php7.1-common php7.1-opcache php7.1-mcrypt php7.1-cli php7.1-gd php7.1-curl php7.1-mysql · Installing PHP on Ubuntu 20.04 server is a straightforward task.
🌐
Cherry Servers
cherryservers.com › home › blog › cloud computing › how to install php on ubuntu 22.04 | step-by-step
How to Install PHP on Ubuntu 22.04 | Cherry Servers | Cherry Servers
1 week ago - Popular sites that run PHP include Facebook, Pinterest, Wikipedia, WordPress, Slack, and many others. Currently, PHP 8.2 is the latest release. It ships with numerous features and improvements. Check out the release page for a comprehensive list of new features and enhancements. In this tutorial, you will learn how to install PHP 8.2 on Ubuntu ...