Last active
April 24, 2024 16:11
-
-
Save nezamy/0173063c3904bde69485ce7a3c0332c0 to your computer and use it in GitHub Desktop.
Web Server Install
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Just Setup Script | |
#chmod +x filename.sh | |
#COLORS | |
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 | |
export DEBIAN_FRONTEND=noninteractive; | |
# Update Ubuntu | |
echo -e "$Cyan \n Updating System.. $Color_Off" | |
apt-get install software-properties-common | |
apt-get update; | |
apt-get -y upgrade; | |
apt-get -y autoremove autoclean | |
echo "Ubuntu Server 16.04 installation script for..." | |
echo "- Nginx" | |
echo "- Php7.1" | |
echo "- MariaDB" | |
echo "- PhpMyAdmin" | |
echo "- Curl, Wget, Git, Unzip, Build-essential, Python-software-properties & Composer" | |
echo "- Mongodb" | |
echo "- Node.JS, Gulp, Bower & Socket.io" | |
read -p "Continue with installation? (y/n)" CONTINUE | |
if [ $CONTINUE = "y" ]; then | |
#======================================================================================== | |
#==[ Nginx ]============================================================================= | |
#======================================================================================== | |
read -p "Install Nginx? (y/n)" NGINX | |
if [ $NGINX = "y" ]; then | |
sudo apt-get install -y nginx | |
sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.backup | |
echo "Moving default site file to /etc/nginx/sites-available/default.backup" | |
read -p "Please write site app name or domain:" SITEAPP | |
sudo cat >/etc/nginx/sites-available/$SITEAPP <<EOL | |
server { | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
charset utf-8; | |
index index.php index.html; | |
server_name _; | |
root /var/www/$SITEAPP; | |
location /phpmyadmin { | |
root /usr/share/; | |
index index.php; | |
try_files \$uri \$uri/ =404; | |
location ~ ^/phpmyadmin/(doc|sql|setup)/ { | |
deny all; | |
} | |
location ~ /phpmyadmin/(.+\.php)\$ { | |
fastcgi_pass unix:/run/php/php7.1-fpm.sock; | |
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; | |
include fastcgi_params; | |
include snippets/fastcgi-php.conf; | |
} | |
} | |
location / { | |
try_files \$uri \$uri/ /index.php?\$args; | |
} | |
location ~ \index.php\$ { | |
include snippets/fastcgi-php.conf; | |
# include fastcgi_params; | |
if ( !-f \$request_filename ) { | |
return 404; | |
} | |
fastcgi_param SERVER_NAME \$http_host; | |
fastcgi_pass unix:/run/php/php7.1-fpm.sock; | |
} | |
location ~ (\.php|\.aspx|\.asp|\.ht|\.env) { | |
deny all; | |
} | |
} | |
EOL | |
sudo cat /etc/nginx/sites-available/$SITEAPP | |
read -p "Would you like to modify the Nginx site file? (y/n)" MOD | |
if [ $MOD = "y" ]; then | |
sudo nano /etc/nginx/sites-available/$SITEAPP | |
fi | |
sudo ln -s /etc/nginx/sites-available/$SITEAPP /etc/nginx/sites-enabled/$SITEAPP | |
sudo nginx -t | |
sudo systemctl reload nginx | |
sudo systemctl restart nginx | |
read -p "Install OpenSSL & Generate SSL Cert for Nginx? (y/n)" SSL | |
if [ $SSL = "y" ]; then | |
sudo apt-get install -y openssl | |
sudo mkdir /etc/nginx/ssl | |
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt | |
sudo openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048 | |
sudo systemctl restart nginx.service | |
fi | |
fi | |
#======================================================================================== | |
#==[ PHP7 ]============================================================================== | |
#======================================================================================== | |
read -p "Install PHP7.1? (y/n)" PHP | |
if [ $PHP = "y" ]; then | |
sudo add-apt-repository ppa:ondrej/php | |
sudo apt-get update | |
sudo apt install -y php7.1 php7.1-common php7.1-fpm php7.1-cli php7.1-mcrypt php7.1-mbstring php7.1-mysql php7.1-sqlite3 php7.1-curl php7.1-zip php7.1-json php7.1-xml php7.1-gd php7.0-dev libpcre3-dev | |
sudo echo 'cgi.fix_pathinfo=0' >> /etc/php/7.1/fpm/php.ini | |
echo 'Adding cgi.fix_pathinfo=0 to /etc/php/7.1/fpm/php.ini' | |
read -p "Would you like to modify the FPM php.ini file? (y/n)" INI | |
if [ $INI = "y" ]; then | |
sudo nano /etc/php/7.1/fpm/php.ini | |
fi | |
sudo systemctl restart php7.1-fpm | |
fi | |
#======================================================================================== | |
#==[ MariaDB ]=========================================================================== | |
#======================================================================================== | |
# Generate root and WordPress mysql passwords | |
rootmysqlpass=`dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev | tr -dc 'a-zA-Z0-9'`; | |
phpmyadminpass=`dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev | tr -dc 'a-zA-Z0-9'`; | |
justmysqlpass=`dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev | tr -dc 'a-zA-Z0-9'`; | |
# Write passwords to file | |
echo -e "$Yellow \n Generated password for (root) and (just) users$Color_Off" | |
sudo echo "Root MySQL Password: $rootmysqlpass" > /root/passwords.txt; | |
sudo echo "Just MySQL Password: $justmysqlpass" >> /root/passwords.txt; | |
sudo echo "phpmyadmin MySQL Password: $phpmyadminpass" >> /root/passwords.txt; | |
read -p "Install MariaDB? (y/n)" MARIADB | |
if [ $MARIADB = "y" ]; then | |
echo -e "$Cyan \n Installing MariaDB $Color_Off" | |
sudo apt install -y mariadb-server mariadb-client | |
sudo mysql_secure_installation <<EOF | |
y | |
$rootmysqlpass | |
$rootmysqlpass | |
y | |
y | |
y | |
y | |
EOF | |
fi | |
#======================================================================================== | |
#==[ PhpMyAdmin ]======================================================================== | |
#======================================================================================== | |
read -p "Install phpMyAdmin? (y/n)" PHPMYADMIN | |
if [ $PHPMYADMIN = "y" ]; then | |
echo -e "$Cyan \n Installing phpMyAdmin $Color_Off" | |
echo "phpmyadmin phpmyadmin/dbconfig-install boolean true" | debconf-set-selections | |
echo "phpmyadmin phpmyadmin/mysql/admin-pass password $rootmysqlpass" | debconf-set-selections | |
echo "phpmyadmin phpmyadmin/mysql/app-pass password $phpmyadminpass" | debconf-set-selections | |
echo "phpmyadmin phpmyadmin/app-password-confirm password $phpmyadminpass" | debconf-set-selections | |
echo "phpmyadmin phpmyadmin/reconfigure-webserver multiselect" | debconf-set-selections | |
sudo apt-get -y install phpmyadmin | |
sudo ln -s /usr/share/phpmyadmin /var/www | |
fi | |
#======================================================================================== | |
#==[ Helpers Tools ]===================================================================== | |
#======================================================================================== | |
echo -e "$Cyan \n Installing Curl, Wget, Git, Unzip, Build-essential, Python-software-properties & Composer $Color_Off" | |
sudo apt-get install -y curl wget git unzip build-essential python-software-properties | |
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer | |
#======================================================================================== | |
#==[ Mongodb ]=========================================================================== | |
#======================================================================================== | |
read -p "Install Mongodb? (y/n)" MONGODB | |
if [ $MONGODB = "y" ]; then | |
echo -e "$Cyan \n Installing Mongodb $Color_Off" | |
sudo apt-get install libpcre3-dev | |
pecl install mongodb | |
fi | |
#======================================================================================== | |
#==[ NodeJs ]============================================================================ | |
#======================================================================================== | |
read -p "Install Node.js? (y/n)" NODE | |
if [ $NODE = "y" ]; then | |
echo "Please select a version of Node.js:" | |
echo "1. Node.js v 4.x LTS" | |
echo "2. Node.js v 6.x" | |
read -p "Which version would you like? (1/2)" NODEV | |
if [ $NODEV = "1" ]; then | |
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - | |
else | |
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - | |
fi | |
sudo apt-get install -y nodejs | |
read -p "Install Socket.io, bower & gulp? (y/n)" SIO | |
if [ $SIO = "y" ];then | |
sudo npm install -g socket.io | |
sudo npm install -g bower | |
sudo npm install -g gulp-cli | |
fi | |
fi | |
# 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" | |
# Set up database user | |
/usr/bin/mysqladmin -u root -h localhost create just; | |
/usr/bin/mysqladmin -u root -h localhost password $rootmysqlpass; | |
/usr/bin/mysql -u root -p$rootmysqlpass -e "CREATE USER just@localhost IDENTIFIED BY '"$justmysqlpass"'"; | |
/usr/bin/mysql -u root -p$rootmysqlpass -e "GRANT ALL PRIVILEGES ON just.* TO just@localhost"; | |
sudo mysql << EOF | |
update mysql.user set plugin=null where user='root'; | |
flush privileges; | |
exit | |
EOF | |
else | |
exit | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment