Skip to content

Instantly share code, notes, and snippets.

@johnny13
Last active April 28, 2020 00:42
Show Gist options
  • Save johnny13/59940a302a848202344b2bd9070ecae3 to your computer and use it in GitHub Desktop.
Save johnny13/59940a302a848202344b2bd9070ecae3 to your computer and use it in GitHub Desktop.
Automated installer for PHP 7.4 (and friends) on Ubuntu 18.04
#!/bin/bash
USAGE=$(cat <<-EOM
___ ___ _____ _ _ ___
/ __| __|_ _| | | | _ |
\__ \ _| | | | |_| | _|
|___/___| |_| \___/|_|
____ _ _ ____ _____ _ _
| _ \| | | | _ \ |___ | || |
| |_| | |_| | |_| | / /| || |_
| __/| _ | __/ / /_|__ _|
|_| |_| |_|_| /_/|_| |_|
EOM
)
echo -e "\n\n\e[35m$USAGE\e[0m"
if [[ $EUID -ne 0 ]]; then
echo -e "\n\e[41mERROR!! This script must be run as root\e[0m\n"
exit 1
fi
PHPCOUNT=1
function echostep {
echo -e "\e[30m\e[42m[${PHPCOUNT}]\e[0m\e[34m $1 \e[0m\n"
PHPCOUNT=$(($PHPCOUNT+1));
}
function echobanner {
echo -e "\n\e[1m\e[36m---[\e[32m $1 \e[36m]--------------------\e[0m\n"
}
function installsoftware {
echostep "apt install software-properties-common"
apt-get install software-properties-common -y
echostep "add-apt-repository ppa:ondrej/php"
add-apt-repository ppa:ondrej/php
echostep "apt-get update"
apt-get update -q
echostep "apt-get install php7.4"
apt-get install php7.4 -y
echostep "apt-get install php7.4-{ accessories }"
apt-get install php7.4-common php7.4-mysql php7.4-bcmath php7.4-sqlite3 php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl php7.4-tidy -y
}
PHPAPACHEFILE="/etc/php/7.4/apache2/php.ini"
function tweakphp {
echostep "Backing up ${PHPAPACHEFILE}"
cp $PHPAPACHEFILE /etc/php/7.4/apache2/php.original.ini
echostep "Tweaking values in ${PHPAPACHEFILE}"
file_uploads=On
allow_url_fopen=On
short_open_tag=On
upload_max_filesize=32M
post_max_size=48M
memory_limit=256M
max_execution_time=600
max_input_time=1000
display_errors=On
for key in file_uploads allow_url_fopen short_open_tag upload_max_filesize post_max_size memory_limit max_execution_time max_input_time display_errors
do
sed -i "s/^\($key\).*/\1 $(eval echo = \${$key})/" $PHPAPACHEFILE
done
echostep "Final tweak to ${PHPAPACHEFILE}"
echo " " >>$PHPAPACHEFILE
echo "; Force Timezone" >>$PHPAPACHEFILE
echo "date.timezone = America/Chicago" >>$PHPAPACHEFILE
}
PHPAPACHEINFOFILE=/var/www/html/phpinfo.php
function apachego {
echostep "Creating ${PHPAPACHEINFOFILE}"
mkdir -p /var/www/html/
touch $PHPAPACHEINFOFILE
echo "<?php phpinfo( ); ?>" >>$PHPAPACHEINFOFILE
echostep "Start & Autorun Apache2 Service"
systemctl start apache2.service
systemctl enable apache2.service
}
function openwebsite {
echostep "Computing Localhost IP"
multiLineVariable=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
firstLine=`echo "${multiLineVariable}" | head -1`
infourl="http://${firstLine}/phpinfo.php"
echostep "Computing Username"
reguser=$(who | awk '{print $1}')
echostep "Open Browser to ${infourl} under ${reguser} profile"
su $reguser -c "xdg-open $infourl"
}
echobanner "STARTING"
installsoftware
tweakphp
apachego
openwebsite
echobanner "FINISHED"
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment