Skip to content

Instantly share code, notes, and snippets.

@niteshpurohit
Last active April 16, 2019 12:59
Show Gist options
  • Save niteshpurohit/497e822d6b63c1a6743f8089c66658ea to your computer and use it in GitHub Desktop.
Save niteshpurohit/497e822d6b63c1a6743f8089c66658ea to your computer and use it in GitHub Desktop.
ubuntu_18_lamp
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
#!/bin/bash
echo "GOT $1 $2"
sleep 4
export DEBIAN_FRONTEND=noninteractive
apt update
echo "Install Apache2"
sleep 2
apt install apache2 -y
echo "Configure Firewall"
sleep 2
ufw app list
ufw allow in "Apache Full"
ufw allow in "OpenSSH"
echo "Install MySql Server"
sleep 2
debconf-set-selections <<< 'mysql-server mysql-server/root_password password $1'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password $1'
apt install mysql-server -y
echo "Configure MySql Server"
sleep 2
cat > mysql_secure_installation.sql << EOF
UPDATE mysql.user SET Password=PASSWORD('$1') WHERE User='root';
# Kill the anonymous users
DELETE FROM mysql.user WHERE User='';
# disallow remote login for root
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
# Kill off the demo database
DROP DATABASE IF EXISTS test;
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';
# Make our changes take effect
FLUSH PRIVILEGES;
EOF
mysql < mysql_secure_installation.sql
rm mysql_secure_installation.sql
mysql "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$1';"
echo "Install PHP"
sleep 2
apt install php libapache2-mod-php php-mysql -y
wget https://gist.githubusercontent.com/niteshpurohit/497e822d6b63c1a6743f8089c66658ea/raw/64951621ee208c27a94e313a962b6dedc6bf8e44/dir.conf
rm /etc/apache2/mods-enabled/dir.conf
cp dir.conf /etc/apache2/mods-enabled/dir.conf
echo "Installing PHPMYADMIN"
sleep 2
APP_PASS="$1"
ROOT_PASS="$1"
APP_DB_PASS="$1"
debconf-set-selections <<< 'phpmyadmin phpmyadmin/dbconfig-install boolean true'
debconf-set-selections <<< 'phpmyadmin phpmyadmin/app-password-confirm password $APP_PASS'
debconf-set-selections <<< 'phpmyadmin phpmyadmin/mysql/admin-pass password $ROOT_PASS'
debconf-set-selections <<< 'phpmyadmin phpmyadmin/mysql/app-pass password $APP_DB_PASS'
debconf-set-selections <<< 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2'
echo "Installing PHPMYADMIN"
sleep 2
apt install phpmyadmin php-mbstring php-gettext -y
phpenmod mbstring
echo "Restart apache2"
systemctl restart apache2
echo "Configuring User"
adduser --disabled-password --gecos "" $2
usermod -a -G www-data $2
usermod -a -G root $2
usermod -g www-data $2
echo "Fixing known issues of PHPMyAdmin"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment