Skip to content

Instantly share code, notes, and snippets.

@lshaf
Created October 12, 2023 05:24
Show Gist options
  • Save lshaf/2cf6af81ff9ec473dcac2f7e265a5e5a to your computer and use it in GitHub Desktop.
Save lshaf/2cf6af81ff9ec473dcac2f7e265a5e5a to your computer and use it in GitHub Desktop.
PHP Installation Scripts

Install Ondrej Repository

sudo add-apt-repository ppa:ondrej/php

Installation Script

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment