Install the package libapache2-mod-php5 (which will also install the package for the webserver: apache2). Files can be put in /var/www.

If you then open http://localhost/index.html in your browser, /var/www/index.html is displayed.

The default settings are pretty secure, PHP errors are logged to /var/log/apache2/error_log and not showed in the browser. To change this on a development machine, edit /etc/php5/apache2/php.ini and change display_errors = Off to display_errors = On.

Some modules are not installed by default. If you do image processing, you likely need the GD library for PHP, package php5-gd. To get a list of all available modules, open a terminal, type sudo apt-get install php5- and hit Tab twice to get a list.

See also: How to avoid using sudo when working in /var/www?

Answer from Lekensteyn on askubuntu.com
🌐
OnlinePHP
onlinephp.io
PHP Sandbox - Execute PHP code online through your browser
Run PHP code in your browser online with this tool in 400+ PHP versions
Discussions

apache - How to run php files on my computer - Stack Overflow
Did you put the files in the htdocs directory of apache? How do you access the file, through http://localhost/yourscript.php? ... Do you want to run the script on a local Apache server on your computer? Or you prefer to run the script without a web server (i.e. outside a browser, like a normal ... More on stackoverflow.com
🌐 stackoverflow.com
How can i run php in my browser
The package is easy to install and configure and you can simply drop your PHP files in the folder for the HTML files and then view them in your browser. ... Use Xampp, put your php in the htdocs folder and run it. ... This subreddit is for anyone who has questions about their PHP code. More on reddit.com
🌐 r/learnprogramming
6
0
February 17, 2021
PHP works from command line but not in browser
I’ve installed Fedora 35, with Apache, MySQL 7.4 and PHP 8. PHP seems to work from the commandline, but it is not getting displayed within the browser. This code does not display the php info: Hi, there! If I have just: in a file named phpinfo.php, I can run php phpinfo.php from the command ... More on discussion.fedoraproject.org
🌐 discussion.fedoraproject.org
1
1
November 17, 2021
How to let my php code work in the browser?
I just started learning php and thought it would be just like html,but when I created a file called test.php and wrote the following code inside: php hello then save the file to desktop.Its icon wasn’t google chrome(my default browser) like .html files but something looked like a sheet of ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
July 27, 2019
🌐
OneCompiler
onecompiler.com › php
PHP Online Compiler
Write, Run & Share PHP code online using OneCompiler's PHP online compiler for free. It's one of the robust, feature-rich online compilers for PHP language, running on PHP 8.3. Getting started with the OneCompiler's PHP compiler is simple and pretty fast.
🌐
Reddit
reddit.com › r/learnprogramming › how can i run php in my browser
r/learnprogramming on Reddit: How can i run php in my browser
February 17, 2021 - The package is easy to install and configure and you can simply drop your PHP files in the folder for the HTML files and then view them in your browser. ... Use Xampp, put your php in the htdocs folder and run it.
🌐
Programiz
programiz.com › php › online-compiler
Online PHP Compiler - Programiz
<?php // Online PHP compiler to run PHP program online // Print "Try programiz.pro" message echo "Try programiz.pro"; ?>
Find elsewhere
🌐
W3Schools
w3schools.com › php › php_compiler.asp
PHP Online Compiler (Editor / Interpreter)
With our online PHP compiler, you can edit PHP code, and view the result in your browser. ... I love PHP! ... Click on the "Try it Yourself" button to see how it works. If you want to create your own website or build PHP applications, W3Schools Spaces gives you an easy place to write, run, manage, and publish code online.
🌐
GitHub
github.com › oraoto › pib
GitHub - oraoto/pib: PHP in Browser (powered by WebAssembly)
php.addEventListener('ready', () => { php.run('<?php echo "Hello, world!";').then(retVal => { // retVal contains the return code. }); }); So long as php.refresh() is not called from Javascript, the instance will maintain its own persistent memory. <?php // Run this over and over again... print ++$x; See the example in action here · The DOM may be accessed via the VRZNO php extension. This is specially for the browser allowing PHP to access Javascript via a C api.
Starred by 989 users
Forked by 147 users
Languages   PHP 42.9% | JavaScript 25.5% | Makefile 12.7% | HTML 11.7% | CSS 4.6% | C 1.9% | PHP 42.9% | JavaScript 25.5% | Makefile 12.7% | HTML 11.7% | CSS 4.6% | C 1.9%
🌐
PHP
php.net › manual › en › features.commandline.webserver.php
PHP: Built-in web server - Manual
On Windows you may find useful to have a phpserver.bat file in shell:sendto with the folowing: explorer http://localhost:8888 rem check if arg is file or dir if exist "%~1\" ( php -S localhost:8888 -t "%~1" ) else ( php -S localhost:8888 -t "%~dp1" ) then for fast web testing you only have to SendTo a file or folder to this bat and it will open your explorer and run the server. ... To send environment variable as long as with PHP built-in web server, type like this. ~$ MYENV=dev php -d variables_order=EGPCS -S 0.0.0.0:8000 On PHP script we can check with this code.
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-run-php-programs
How to run PHP programs ? - GeeksforGeeks
July 23, 2025 - ... To run PHP programs, you need to set up a suitable environment, either locally or on a live web server. For local development, you can install server packages like XAMPP, WAMP, or MAMP, which provide PHP, Apache, and MySQL in one installation.
🌐
freeCodeCamp
forum.freecodecamp.org › t › how-to-let-my-php-code-work-in-the-browser › 310488
How to let my php code work in the browser? - The freeCodeCamp Forum
July 27, 2019 - I just started learning php and thought it would be just like html,but when I created a file called test.php and wrote the following code inside: <!DOCTYPE html> <html> <head> <title>php</title> </head> <body> <?php …
🌐
Quora
quora.com › How-do-you-get-a-PHP-script-to-run-on-a-webpage
How to get a PHP script to run on a webpage - Quora
Answer (1 of 2): Please complete this training lesson about how to run PHP with a web form. https://www.w3schools.com/php/php_forms.asp Normally you create a form with a button. And you run the PHP with an action command. Otherwise, if there ...
🌐
Wikihow
wikihow.com › computers and electronics › basic computer skills › how to run a php file in a browser: a step-by-step guide
How to Run a PHP File in a Browser: A Step-by-Step Guide
March 21, 2025 - Navigate to “localhost:8888” and click the PHP file to run the script. ... Go to https://www.mamp.info/en/downloads. MAMP is a free, local server environment that you'll need to use to see PHP in your web browser.
🌐
CodeChef
codechef.com › php-online-compiler
Online PHP Compiler
Welcome to our AI-powered online PHP interpreter, the perfect platform to run and test your PHP code efficiently. Our tool makes coding easy for developers of any skill level, whether you're a beginner or experienced.
🌐
PHP Playground
php-play.dev
PHP Playground
The Playground let you to execute basic PHP code in real time using WebAssembly technology.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Open PHP/HTML/JS In Browser - Visual Studio Marketplace
Extension for Visual Studio Code - A GUI to open PHP/HTML/JS files in browser on http://localhost or file:/// scheme. Suitable for XAMPP.
🌐
Medium
alinawrites.medium.com › how-to-run-php-file-on-localhost-e740890fcdff
How To Run PHP File On Localhost. Most articles and tutorials are written… | by Alina Writes | Medium
November 2, 2022 - The file should have a .php extension. If it does not, you can rename it or save it as a .php file. When you access the file in your browser, the server will run the php code and display the results.
🌐
Jumpshare
jumpshare.com › viewer › php
PHP Viewer - Open PHP File Online for Free | Jumpshare
Our viewer has got your back, supporting popular desktop and mobile browsers, and providing a smooth user experience. View your PHP file with syntax highlighting. Our file viewer color-codes your script so it is easier to consume, both for you and those with whom you may share it.