Skip to content

Instantly share code, notes, and snippets.

@ashishtz
Created March 12, 2019 04:51
Show Gist options
  • Save ashishtz/7918b2d7c757b85bc6c77991084b4293 to your computer and use it in GitHub Desktop.
Save ashishtz/7918b2d7c757b85bc6c77991084b4293 to your computer and use it in GitHub Desktop.
Shell script to install apache2, php, mysql and phpmyadmin.
#!/bin/sh
#COLORS
# Reset
Color_Off='\033[0m' # Text Reset
# Regular Colors
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[0;33m' # Yellow
Purple='\033[0;35m' # Purple
Cyan='\033[0;36m' # Cyan
# Update packages and Upgrade system
echo -e "$Cyan \n Updating System.. $Color_Off"
sudo apt-get update -y && sudo apt-get upgrade -y
## Install AMP
echo -e "$Cyan \n Installing Apache2 $Color_Off"
sudo apt-get install apache2 -y
## Install AMP
echo -e "$Cyan \n Allowing apache2 $Color_Off"
sudo sudo ufw allow in "Apache Full"
echo -e "$Cyan \n Installing PHP & Requirements $Color_Off"
sudo apt-get install libapache2-mod-php php php-common php-curl php-dev php-gd php-pear php-mysql -y
echo -e "$Cyan \n Installing MySQL $Color_Off"
sudo apt-get install mysql-server -y
echo -e "$Cyan \n Securing Mysql $Color_Off"
sudo mysql_secure_installation
echo -e "$Cyan \n Installing phpMyAdmin $Color_Off"
sudo apt-get install phpmyadmin -y
# Permissions
echo -e "$Cyan \n Permissions for /var/www $Color_Off"
sudo chown -R www-data:www-data /var/www
echo -e "$Green \n Permissions have been set $Color_Off"
# Enabling Mod Rewrite, required for WordPress permalinks and .htaccess files
echo -e "$Cyan \n Enabling Modules $Color_Off"
sudo a2enmod rewrite
# Restart Apache
echo -e "$Cyan \n Restarting Apache $Color_Off"
sudo service apache2 restart
@ashishtz
Copy link
Author

ashishtz commented Mar 12, 2019

to download a file from the server,

wget https://gist.githubusercontent.com/ashishpatel6958/7918b2d7c757b85bc6c77991084b4293/raw/shell.sh
chmod -x ./shell.sh

and run the script by $ sh shell.sh

Once the above process is complete, follow below steps,

Login to mySql

$ sudo mysql

Get list of users

mysql > SELECT user,authentication_string,plugin,host FROM mysql.user;

modify root/create a new user

modify root:
mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

create new user:
mysql > CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

Flush privileges:

mysql > FLUSH PRIVILEGES;

Check modification

mysql > SELECT user,authentication_string,plugin,host FROM mysql.user;

Exit.

mysql > exit

and your setup has been finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment