Skip to content

Instantly share code, notes, and snippets.

@karthikax
Last active February 13, 2018 20:08
Show Gist options
  • Save karthikax/9ef40da7c907e947a4b7b67a1ccce967 to your computer and use it in GitHub Desktop.
Save karthikax/9ef40da7c907e947a4b7b67a1ccce967 to your computer and use it in GitHub Desktop.
One click LAMP Set up
#!/bin/bash
# @todo: NOT WORKING PROPERLY
MYSQL_PASSWORD="KarthikMSQL&398"
DATABASE_NAME="wpkart"
SERVER_NAME="karthikbhat.net"
sudo apt-get -y install apache2
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQL_PASSWORD}"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_PASSWORD}"
sudo apt-get -y install mysql-server
sudo apt-get -y install expect
SECURE_MYSQL=$(expect -c "
set timeout 3
spawn mysql_secure_installation
expect \"Enter password for user root:\"
send \"$MYSQL_PASSWORD\r\"
expect \"Would you like to setup VALIDATE PASSWORD plugin?\"
send \"n\r\"
expect \"Change the password for root ?\"
send \"n\r\"
expect \"Remove anonymous users?\"
send \"y\r\"
expect \"Disallow root login remotely?\"
send \"y\r\"
expect \"Remove test database and access to it?\"
send \"y\r\"
expect \"Reload privilege tables now?\"
send \"y\r\"
expect eof
")
echo "${SECURE_MYSQL}"
mysql -u "root" -p"$MYSQL_PASSWORD" -e "CREATE DATABASE ${DATABASE_NAME};"
[ -f bak.sql ] && mysql -u "root" -p"$MYSQL_PASSWORD" ${DATABASE_NAME} < bak.sql || echo "No mysql backup file"
sudo apt-get -y install php libapache2-mod-php php-mcrypt php-mysql php-mbstring php-gettext
# Apache configuration
sudo chown -R www-data:www-data /var/www
sudo sed -i '11i\\tServerName ${SERVER_NAME}' /etc/apache2/sites-available/000-default.conf
sudo sed -i '21i\
<Directory "/var/www/html">\
Options FollowSymLinks\
DirectoryIndex index.php\
AllowOverride All\
Require all granted\
</Directory>\
' /etc/apache2/sites-available/000-default.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
sudo rm -f /var/www/html/index.html
# Install phpmyadmin manually if needed
#!/bin/bash
sudo apt-get -y remove --purge apache2 mysql-server php libapache2-mod-php php-mcrypt php-mysql
sudo apt-get -y remove --purge phpmyadmin
sudo apt-get -y remove --purge expect
sudo apt-get -y purge mysql-server mysql-client mysql-common mysql-server-core-5.7 mysql-client-core-5.7
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt-get autoremove -y
sudo apt-get autoclean -y
sudo apt autoremove -y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment