practice php on ubuntu laptop

I only have a laptop with ubuntu 20.04 installed.
I am anxious to learn php but the book I have only explains how to install php and set up local server for Window and Mac users. I found a stack overflow page that explains how but it is 10 years old and I decided to ask this question.
So could you please explain how I can set up a local server and practice and test php programming?


Use the builtin webserver from php:

Installation:

sudo apt install php-cli

Usage (From inside your test projects directory):

php -S localhost:8000

Then point your browser to localhost:8000.

It will automatically load the index.php file if there is any. You can create it with any text editor and start programing:

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Hello World</p>'; ?> 
 </body>
</html>

There are three things you will need for this:

  1. an Internet connection (to install software)
  2. Apache
  3. PHP

Here's how you can get a bare minimum installed and running on your system:

  1. Open Terminal (if it's not already open)
  2. Update apt:
    sudo apt update 
    
  3. Install Apache:
    sudo apt install apache2
    
  4. Test Apache works by opening a browser and visiting http://127.0.0.1. You should see something that looks like this: Apache Test Page
  5. Install PHP (and some common development libraries):
    sudo apt install php libapache2-mod-php php-dev php-xml php-json php-mbstring
    
  6. Restart Apache:
    sudo service apache2 restart
    
  7. Create a test file in the Apache root directory:
    sudo nano /var/www/html/testing.php
    
  8. Paste the following into the new file:
    <?php phpinfo(); ?>
    
  9. Test PHP works by visiting http://127.0.0.1/testing.php in your browser. You should see something like this: PHP InfoYour version number will likely be a bit different, as this was done on a 21.10 installation.
  10. Start learning PHP 👍🏻

That's all there is to a basic setup with just Apache and PHP.