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

Instructions:

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

installPHP.sh

#!/bin/bash
# Shell script to install PHP. Provided by https://www.webune.com
clear
# 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