Install LAMP ( Linux Apache, MySQL, PHP/PHPMyAdmin)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
8.5 KiB

#!/bin/bash
DBPASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
DBUSER=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)
ADMINPASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
PHPMYADMINV=5.1.1
VAR_A=`uname -m`
mkdir -p /home/tmp
cd "/home/tmp"
show_spinner()
{
spin='-\|/'
i=0
while kill -0 $1 2>/dev/null
do
i=$(( (i+1) %4 ))
printf "\r\e[93m[ \e[36m${spin:$i:1} \e[93m] \e[93mPlease wait...\e[39m"
sleep .1
done
}
clean_up(){
echo "Clean"
}
install_Debian9(){
echo -e "\n\e[92mInstalling requirements...\e[39m"
apt-get install --yes --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" sudo
apt-get install -y zip unzip curl wget gnupg2 ca-certificates lsb-release apt-transport-https systemd >/dev/null &
show_spinner $!
echo -e "\n\e[92mInstalling public key & source list...\e[39m"
wget -q -N https://packages.sury.org/php/apt.gpg
apt-key add apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php7.list
apt-get update >/dev/null &
show_spinner $!
echo -e "\n\e[92mInstalling PHP...\e[39m"
apt-get install -y php7.3 php7.3-cli php7.3-common >/dev/null &
show_spinner $!
echo -e "\n\e[92mInstalling Apache2 and MariaDB-Server..\e[39m"
apt-get install -y apache2 mariadb-server libapache2-mod-php7.4 >/dev/null &
show_spinner $!
systemctl stop mysql
systemctl stop mariadb
chkconfig --del mysql
systemctl disable mysql
systemctl disable mariadb
systemctl enable mariadb.service
systemctl start mariadb.service
echo -e "\n\e[92mInstallation PHP extentions...\e[39m"
apt-get install -y php7.3-fileinfo php7.3-bz2 php7.3-intl php7.3-ldap php7.3-smbclient php7.3-imap php7.3-bcmath php7.3-gmp php7.3-mysql php7.3-dom php7.3-simplexml php7.3-ssh2 php7.3-xml php7.3-xmlreader php7.3-curl php7.3-xmlwriter php7.3-zip php7.3-exif php7.3-ftp php7.3-gd php7.3-iconv php7.3-imagick php7.3-json php7.3-mbstring php7.3-posix php7.3-sockets php7.3-tokenizer >/dev/null &
show_spinner $!
echo -e "\n\e[92mDownloading PHPMyAdmin..\e[39m"
wget -q -N "https://files.phpmyadmin.net/phpMyAdmin/$PHPMYADMINV/phpMyAdmin-$PHPMYADMINV-all-languages.zip" >/dev/null &
show_spinner $!
unzip -o phpMyAdmin-$PHPMYADMINV-all-languages.zip >/dev/null &
show_spinner $!
mv phpMyAdmin-$PHPMYADMINV-all-languages /usr/share/phpmyadmin
chmod -R 0755 /usr/share/phpmyadmin
wget -q -N "https://backup.mirror3.deinserverhost.icu/OneClick/phpmyadmin.conf"
mv phpmyadmin.conf /etc/apache2/conf-available/
a2enconf phpmyadmin
systemctl reload apache2
mkdir -p /usr/share/phpmyadmin/tmp/
chown -R www-data:www-data /usr/share/phpmyadmin/tmp/
echo -e "\n\e[92mConfiguring MariaDB...\e[39m"
echo "CREATE USER '$DBUSER'@'localhost' IDENTIFIED BY '$DBPASS';
GRANT ALL PRIVILEGES ON *.* TO '$DBUSER'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;" > /home/LAMP.sql
mysql -u root < /home/LAMP.sql
rm /home/LAMP.sql
service apache2 restart
OWNIP=`curl ifconfig.me`
echo -e "\n\e[92mWriting login details into file...\e[39m"
echo -e "\n
########## Phpmyadmin ##########\n
# http://$OWNIP/phpmyadmin/
# Username: $DBUSER \n
# Password: $DBPASS \n
########## ## END ## ##########\n
\n" > /home/LAMP-Login-Details-README.txt
echo -e "\n\e[92mLogin details written to \e[93m/home/LAMP-Login-Details-README.txt \e[39m"
}
install_debian8() {
export DEBIAN_FRONTEND=noninteractive
apt-get install --yes --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" sudo curl >/dev/null &
show_spinner $!
apt-get install -y zip unzip curl wget gnupg2 ca-certificates lsb-release apt-transport-https systemd >/dev/null &
show_spinner $!
echo -e "\n\e[92mFixing Source list...\e[39m"
echo "deb http://deb.debian.org/debian jessie main
deb-src http://deb.debian.org/debian jessie main
## Major bug fix updates produced after the final release of the
## distribution.
deb http://security.debian.org/ jessie/updates main
deb-src http://security.debian.org/ jessie/updates main
deb http://deb.debian.org/debian jessie-updates main
deb-src http://deb.debian.org/debian jessie-updates main
" > /etc/apt/sources.list
echo 'deb http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list
echo 'deb-src http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list
cd /tmp
wget https://www.dotdeb.org/dotdeb.gpg
apt-key add dotdeb.gpg
apt-get update >/dev/null &
show_spinner $!
apt-get install --yes --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" php7.0-common php7.0-fpm php7.0-cli php7.0-json php7.0-imap php7.0-mysql php7.0-curl php7.0-imap php7.0-intl php7.0-mcrypt php-pear php7.0-gd php7.0-zip php7.0-xml php7.0-mbstring >/dev/null &
show_spinner $!
apt-get install --yes --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" apache2 libapache2-mod-php7.0 mysql-server >/dev/null &
show_spinner $!
echo -e "\n\e[92mDownloading PHPMyAdmin..\e[39m"
wget -q -N "https://files.phpmyadmin.net/phpMyAdmin/4.9.5/phpMyAdmin-4.9.5-all-languages.zip" >/dev/null &
show_spinner $!
unzip -o phpMyAdmin-4.9.5-all-languages.zip >/dev/null &
show_spinner $!
mv phpMyAdmin-4.9.5-all-languages /usr/share/phpmyadmin
chmod -R 0755 /usr/share/phpmyadmin
wget -q -N "https://backup.mirror3.deinserverhost.icu/OneClick/phpmyadmin.conf"
mv phpmyadmin.conf /etc/apache2/conf-available/
a2enconf phpmyadmin
systemctl reload apache2
mkdir -p /usr/share/phpmyadmin/tmp/
chown -R www-data:www-data /usr/share/phpmyadmin/tmp/
echo -e "\n\e[92mConfiguring MariaDB...\e[39m"
echo "CREATE USER '$DBUSER'@'localhost' IDENTIFIED BY '$DBPASS';
GRANT ALL PRIVILEGES ON *.* TO '$DBUSER'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;" > /home/LAMP.sql
mysql -u root < /home/LAMP.sql
rm /home/LAMP.sql
service apache2 restart
OWNIP=`curl ifconfig.me`
echo -e "\n\e[92mWriting login details into file...\e[39m"
echo -e "\n
########## Phpmyadmin ##########\n
# http://$OWNIP/phpmyadmin/
# Username: $DBUSER \n
# Password: $DBPASS \n
########## ## END ## ##########\n
\n" > /home/LAMP-Login-Details-README.txt
echo -e "\n\e[92mLogin details written to \e[93m/home/LAMP-Login-Details-README.txt \e[39m"
}
i=0
tput sc
while fuser /var/{lib/{dpkg,apt/lists},cache/apt/archives}/lock >/dev/null 2>&1 ; do
case $(($i % 4)) in
0 ) j="-" ;;
1 ) j="\\" ;;
2 ) j="|" ;;
3 ) j="/" ;;
esac
tput rc
echo -en "\r[$j] \e[93mWaiting for another process to finish...\e[39m"
sleep 0.5
((i=i+1))
done
echo -e "\n\e[92mPackage manager is done\e[39m"
echo -e "\e[36mPreparing LAMP installation..\e[39m"
echo -e "\e[36mChecking Operation system..\e[39m"
# CHECK OS
if [ "$VAR_A" = "x86_64" ]; then
check=`cat /etc/issue | grep -i 'Debian'`
if [ -n "$check" ]; then
apt-get update >/dev/null &
show_spinner $!
version=`cat /etc/debian_version | awk -F. '{print $1}'`
if [ $version -eq 10 ]; then
#Debian 10
echo -e "\nDebian $version \e[39m"
install_Debian9 # Currently it also works for Debian 10
clean_up
elif [ $version -eq 9 ]; then
#Debian 9 Check
echo -e "\nDebian $version \e[39m"
install_Debian9
clean_up
elif [ $version -eq 8 ]; then
#Debian 8 Check
echo "Debian $version \e[39m"
install_debian8
clean_up
fi
fi
#Debian Check End
#Ubuntu
check=`cat /etc/issue | grep -i 'Ubuntu'`
if [ -n "$check" ]; then
apt-get update >/dev/null &
show_spinner $!
version=`lsb_release -sr | awk -F. '{print $1}'`
if [ $version -eq 20 ]; then
#Ubuntu 20
echo "Ubuntu $version"
elif [ $version -eq 18 ]; then
#Ubuntu 18
echo "Ubuntu $version"
elif [ $version -eq 16 ]; then
#Ubuntu 16
echo "Ubuntu $version"
fi
fi
#CentOS
check=`cat /etc/issue | grep -i 'CentOS'`
if [ -n "$check" ]; then
echo "CentOS is not supported yet"
fi
fi
echo -e "\e[39mEverything is done.\e[39m"