Linux Commands To Install And Run PHP In Ubuntu

This is a very simple and short linux shell script to install php in your ubuntu machine. This worked for me on Ubuntu 20TLS


  1. Create a new file called
  2. Copy and paste the code below
  3. Save the changes
  4. Change the permissions to execute with the following command:
    $ chmod +x
  5. Run the script with the following command
    $ ./
  6. Done

# Shell script to install PHP. Provided by
# update your package manager
sudo apt update && upgrade
sudo apt install php
# Create a PHP project in user's home directory
cd ~
mkdir php_projects
cd php_projects
echo "<?php phpinfo(); ?>" > index.php
# Open browser
xdg-open http://localhost:4000
# Run PHP development server
php -S localhost:4000