sudo add-apt-repository ppa:ondrej/php
Save code below as install-php
then do command chmod +x install-php
.
For installation you can simply done install-php 7.3
. You can change the version whicever you want!
#!/bin/bash
# Check if the script is run as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root or with sudo."
exit 1
fi
# Check if the PHP version is provided as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <php_version>"
exit 1
fi
# Define the PHP version
php_version="$1"
# Install PHP and necessary extensions
apt install "php$php_version" "php$php_version-json" "php$php_version-gd" "php$php_version-bcmath" "php$php_version-curl" "php$php_version-zip" "php$php_version-pdo" "php$php_version-xml" "php$php_version-redis" "php$php_version-mbstring"
# Check the installation status
if [ $? -eq 0 ]; then
echo "PHP $php_version and required extensions have been successfully installed."
else
echo "Failed to install PHP $php_version and required extensions."
exit 1
fi