-
-
Save claudiorrrr/cde90436912a75c28bcddf8b51c3c87f to your computer and use it in GitHub Desktop.
Revisions
-
claudiorrrr revised this gist
Jan 12, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -102,8 +102,10 @@ done cat << EOF ============================================ Please run sudo certbot --nginx -d $domain -d www.$domain at the end ============================================ Files created: -
claudiorrrr revised this gist
Jan 12, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -103,7 +103,7 @@ done cat << EOF ============================================ Please run 'sudo certbot --nginx -d $domain -d www.$domain' at the end sudo certbot --nginx -d $domain -d www.$domain at the end ============================================ Files created: -
claudiorrrr revised this gist
Jan 12, 2021 . 2 changed files with 50 additions and 35 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -79,9 +79,12 @@ chown -R $WEB_USER:www-data /var/www/$domain/ ln -s $NGINX_AVAILABLE_VHOSTS/$domain.conf $NGINX_ENABLED_VHOSTS/ # SSL cat << EOF ============================================ SSL install! ============================================ EOF # install certbot + python3-certbot-nginx sudo apt install certbot python3-certbot-nginx @@ -97,10 +100,16 @@ select yn in "Yes" "No"; do esac done cat << EOF ============================================ Please run 'sudo certbot --nginx -d $domain -d www.$domain' at the end sudo certbot --nginx -d $domain -d www.$domain' at the end ============================================ Files created: - /etc/nginx/sites-available/$domain.conf - /var/www/$domain ============================================ EOF ok "Site Created for $domain" This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -68,11 +68,20 @@ if [ "$install_method" == 1 ]; then echo read -p "Install wordpress in a new directory (y/n): " new read -p "Install wordpress in a new directory (y/n): - new question " new;do # if [ "$new" == y ] ; then echo "she said yes" break read -p "Name of the wordpress directory: " dir_name mkdir -p /var/www/$dir_name cd /var/www/$dir_name elif [ "$new" == n ]; then echo "she said no" break fi done # Download the latest wordpress package using wp-cli wp core download --allow-root @@ -147,26 +156,23 @@ else ## for some reason this does not show at the end clear cat << EOF ============================================ Installation is complete. ============================================ MYSQL db/user creation completed! Database : ${dbname} User : ${dbuser} Pass : ${dbpass} ============================================ "Wordpress install completed! Domain : ${url} Email : ${admin_email} User : ${admin_name} Pass : ${admin_pass} ============================================ EOF fi done -
claudiorrrr revised this gist
Jan 11, 2021 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ # README This is a very basic repo. It consist in 2 files: 1. `addvhost.sh` 2. `wp.sh` They will help you to streamline a basic virtual host configuration in a Ubuntu machine using Nginx. Also, in case you would like to chose Wordpress, the `wp.sh` script will guide you to install it without messing around with databases, etc. It will do everything automatically. In a fresh machine, they should be used in order. ## What's next It's not perfect. Currently the code is clunky (I'm not a dev!) and I've identified some flaws (mostly at the information level - the script should be able to show what has done at the end...), but it's 100% usable. -
claudiorrrr revised this gist
Jan 11, 2021 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -143,6 +143,8 @@ else # remove zip file rm latest.tar.gz ## for some reason this does not show at the end clear echo "=========================" -
claudiorrrr revised this gist
Jan 11, 2021 . 1 changed file with 170 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,170 @@ #!/bin/bash -e clear echo "============================================" echo "WordPress Install Script" echo "============================================" # Gathering database login credentials from user input read -sp "Your mysql root password: " rootpasswd echo read -p "Database Name: " dbname read -p "Database User: " dbuser # create random password dbpass="$(openssl rand -base64 24)" echo # Create new database using provided credentials read -p "Create new database with provided credentials? (y/n): " new_db echo "Creating new MySQL database..." mysql -uroot -p${rootpasswd} -e "CREATE DATABASE ${dbname} /*\!40100 DEFAULT CHARACTER SET utf8 */;" echo "Creating new user..." mysql -uroot -p${rootpasswd} -e "CREATE USER ${dbuser}@localhost IDENTIFIED BY '${dbpass}';" echo "User successfully created!" echo "" echo "Granting ALL privileges on ${dbname} to ${dbuser}!" mysql -uroot -p${rootpasswd} -e "GRANT ALL ON ${dbname}.* TO '${dbuser}'@'localhost';" mysql -uroot -p${rootpasswd} -e "FLUSH PRIVILEGES;" echo "MySQL DB / User creation completed!" clear echo "============================================" echo "MYSQL db/user creation completed!" echo " >> Database : ${dbname}" echo " >> User : ${dbuser}" echo " >> Pass : ${dbpass}" echo "============================================" echo # Starting the Wordpress installation process # option 2 doesn't work -- need fix echo "===================================" echo "Choose Wordpress installation mode:" echo "===================================" echo echo "1. Install Wordpress using wp-cli" echo "2. Install Wordpress without wp-cli" echo read -p "Choose install method: " install_method if [ "$install_method" == 1 ]; then # Starting the Wordpress installation process using wp-cli echo "===================================" echo "Please wait while we install wp-cli" echo "===================================" curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar chmod +x wp-cli.phar # linux: sudo cp wp-cli.phar /usr/bin/wp # macos: # wp-cli.phar /usr/local/bin/wp echo "==========================" echo "Finished installing wp-cli" echo "==========================" echo read -p "Install wordpress in a new directory (y/n): " new if [ "$new" == y ] ; then read -p "Name of the wordpress directory: " dir_name mkdir -p /var/www/$dir_name cd /var/www/$dir_name fi # Download the latest wordpress package using wp-cli wp core download --allow-root # Creating wp-config file using credentials defined on lines 8-11 wp core config --dbhost=localhost --dbname=$dbname --dbuser=$dbuser --dbpass=$dbpass --allow-root chmod 644 wp-config.php # Entering details of the new Wordpress site clear echo "=======================================================" echo "Ready to install Wordpress. Just enter few more details" echo "=======================================================" read -p "Website url: " url read -p "Website title: " title read -p "Admin username: " admin_name admin_pass="$(openssl rand -base64 24)" echo read -p "Admin email: " admin_email echo read -p "Run install? (y/n): " run_wp_install if [ "$run_wp_install" == n ] ; then exit else echo "============================================" echo "A robot is now installing WordPress for you." echo "============================================" echo # Installing Wordpress site using credentials defined on lines 71-76 wp core install --url=$url --title="$title" --admin_name=$admin_name --admin_password=$admin_pass --admin_email=$admin_email --allow-root fi else # download wordpress curl -O https://wordpress.org/latest.tar.gz # unzip wordpress tar -zxvf latest.tar.gz # change dir to wordpress cd wordpress # copy file to parent dir cp -rf . .. # move back to parent dir cd .. # remove files from wordpress folder rm -R wordpress # create wp config cp wp-config-sample.php wp-config.php # set database details with perl find and replace perl -pi -e "s/database_name_here/$dbname/g" wp-config.php perl -pi -e "s/username_here/$dbuser/g" wp-config.php perl -pi -e "s/password_here/$dbpass/g" wp-config.php # set WP salts perl -i -pe' BEGIN { @chars = ("a" .. "z", "A" .. "Z", 0 .. 9); push @chars, split //, "!@#$%^&*()-_ []{}<>~\`+=,.;:/?|"; sub salt { join "", map $chars[ rand @chars ], 1 .. 64 } } s/put your unique phrase here/salt()/ge ' wp-config.php # create uploads folder and set permissions mkdir wp-content/uploads chmod 775 wp-content/uploads echo "Cleaning..." # remove zip file rm latest.tar.gz clear echo "=========================" echo "Installation is complete." echo "=========================" echo "============================================" echo "MYSQL db/user creation completed!" echo " >> Database : ${dbname}" echo " >> User : ${dbuser}" echo " >> Pass : ${dbpass}" echo "============================================" echo echo "============================================" echo "Wordpress install completed!" echo " >> Domain : ${url}" echo " >> Email : ${admin_email}" echo " >> User : ${admin_name}" echo " >> Pass : ${admin_pass}" echo "============================================" echo fi -
claudiorrrr revised this gist
Jan 8, 2021 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -43,12 +43,12 @@ server { error_log /var/www/$domain/logs/$domain.log; #error_log off; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.4-fpm.sock; } } @@ -99,6 +99,8 @@ done echo "============================================" echo "please run 'sudo certbot --nginx -d $domain -d www.$domain' at the end" echo "sudo certbot --nginx -d $domain -d www.$domain'" echo "at the end" echo "============================================" ok "Site Created for $domain" -
claudiorrrr revised this gist
Jan 7, 2021 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -42,6 +42,15 @@ server { error_log /var/www/$domain/logs/$domain.log; #error_log off; location ~ \.php$ { include snippets/fastcgi-php.conf; # # # With php7.0-cgi alone: # # fastcgi_pass 127.0.0.1:9000; # # With php7.0-fpm: fastcgi_pass unix:/run/php/php7.4-fpm.sock; } } EOF -
claudiorrrr revised this gist
Jan 7, 2021 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,9 @@ #!/usr/bin/env bash # # Nginx - new server block # Fork from: http://rosehosting.com # Edited by: claudioruiz read -p "Enter domain name : " domain read -p "Enter username : " username @@ -43,6 +45,9 @@ server { } EOF # I need to figure out how to make this creation of a file conditional # in case the user would like to avoid creating the index.html... TBD # Creating index.html file cat > /var/www/$domain/index.html <<EOF <!DOCTYPE html> -
claudiorrrr revised this gist
Jan 7, 2021 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -64,6 +64,16 @@ chown -R $WEB_USER:www-data /var/www/$domain/ # Enable site by creating symbolic link ln -s $NGINX_AVAILABLE_VHOSTS/$domain.conf $NGINX_ENABLED_VHOSTS/ # SSL echo "============================================" echo "SSL install" echo "============================================" # install certbot + python3-certbot-nginx sudo apt install certbot python3-certbot-nginx sudo ufw allow 'Nginx Full' sudo ufw delete allow 'Nginx HTTP' # Restart echo "Do you wish to restart nginx?" select yn in "Yes" "No"; do @@ -73,4 +83,8 @@ select yn in "Yes" "No"; do esac done echo "============================================" echo "please run 'sudo certbot --nginx -d $domain -d www.$domain' at the end" echo "============================================" ok "Site Created for $domain" -
claudiorrrr revised this gist
Jan 7, 2021 . 1 changed file with 6 additions and 59 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -19,83 +19,30 @@ WEB_USER=$username [ $(id -g) != "0" ] && die "Script must be run as root." #[ $# != "1" ] && die "Usage: $(basename $0) domainName" # Creating /var/www/ directory mkdir -p /var/www/$domain # Creating {public,log} directories mkdir -p /var/www/$domain/logs touch -p /var/www/$domain/logs/$domain.log # Create nginx config file cat > $NGINX_AVAILABLE_VHOSTS/$domain.conf <<EOF server { listen 80; server_name $domain www.$domain; root /var/www/$domain; charset utf-8; index index.php index.html index.htm; #access_log $WEB_DIR/logs/$domain-access.log; access_log off; error_log /var/www/$domain/logs/$domain.log; #error_log off; } EOF # Creating index.html file cat > /var/www/$domain/index.html <<EOF <!DOCTYPE html> -
claudiorrrr revised this gist
Jan 7, 2021 . 1 changed file with 58 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,61 @@ #!/usr/bin/env bash # # Nginx - new server block # http://rosehosting.com read -p "Enter domain name : " domain read -p "Enter username : " username # Functions ok() { echo -e '\e[32m'$domain'\e[m'; } # Green die() { echo -e '\e[1;31m'$domain'\e[m'; exit 1; } # Variables NGINX_AVAILABLE_VHOSTS='/etc/nginx/sites-available' NGINX_ENABLED_VHOSTS='/etc/nginx/sites-enabled' WEB_DIR='/var/www/$domain' WEB_USER=$username # Sanity check [ $(id -g) != "0" ] && die "Script must be run as root." #[ $# != "1" ] && die "Usage: $(basename $0) domainName" # Create nginx config file cat > $NGINX_AVAILABLE_VHOSTS/$domain.conf <<EOF ### www to non-www #server { # listen 80; # server_name www.$domain; # return 301 http://$domain\$request_uri; #} server { listen 80; server_name $domain www.$domain; root /var/www/$domain; charset utf-8; index index.php index.html index.htm; #access_log $WEB_DIR/logs/$domain-access.log; access_log off; error_log $WEB_DIR/logs/$domain-error.log; #error_log off; ## REWRITES BELOW ## ## INCLUDE COMMONS ## include php.conf; include errors.conf; include drop.conf; include expires.conf; } EOF # Creating {public,log} directories mkdir -p $WEB_DIR/$username/{public_html,logs} # Create nginx config file cat > $NGINX_AVAILABLE_VHOSTS/$domain.conf <<EOF ### www to non-www -
claudiorrrr revised this gist
Jan 7, 2021 . 1 changed file with 18 additions and 37 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,49 +1,29 @@ # This script should work flawlessly in Ubuntu # Create nginx config file cat > $NGINX_AVAILABLE_VHOSTS/$domain.conf <<EOF ### www to non-www #server { # listen 80; # server_name www.$domain; # return 301 http://$domain\$request_uri; #} server { listen 80; server_name $domain www.$domain; root /var/www/$domain; charset utf-8; index index.php index.html index.htm; #access_log /logs/$domain-access.log; access_log off; error_log /var/www/$domain/logs/$domain-error.log; #error_log off; ## REWRITES BELOW ## ## INCLUDE COMMONS ## include php.conf; @@ -53,30 +33,32 @@ server { } EOF mkdir -p /var/www/$domain mkdir -p /var/www/$domain/logs # Creating {public,log} directories # mkdir -p $WEB_DIR/{public_html,logs} # Creating index.html file cat > /var/www/$domain/index.html <<EOF <!DOCTYPE html> <html lang="en"> <head> <title>$domain</title> <meta charset="utf-8" /> </head> <body class="container"> <header><h1>$domain<h1></header> <div id="wrapper"><p>Hello World, it works!</p></div> </body> </html> EOF # Changing permissions chown -R $WEB_USER:www-data /var/www/$domain/ # Enable site by creating symbolic link ln -s $NGINX_AVAILABLE_VHOSTS/$domain.conf $NGINX_ENABLED_VHOSTS/ # Restart echo "Do you wish to restart nginx?" @@ -87,5 +69,4 @@ select yn in "Yes" "No"; do esac done ok "Site Created for $domain" -
runbrun created this gist
Jan 18, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,91 @@ #!/usr/bin/env bash # # Nginx - new server block # http://rosehosting.com read -p "Enter username : " username read -p "Enter domain name : " domain # Functions ok() { echo -e '\e[32m'$domain'\e[m'; } # Green die() { echo -e '\e[1;31m'$domain'\e[m'; exit 1; } # Variables #NGINX_AVAILABLE_VHOSTS='/etc/nginx/sites-available' NGINX_ENABLED_VHOSTS='/etc/nginx/conf.d' WEB_DIR='/home' WEB_USER=$username # Sanity check [ $(id -g) != "0" ] && die "Script must be run as root." #[ $# != "1" ] && die "Usage: $(basename $0) domainName" # Create nginx config file cat > $NGINX_ENABLED_VHOSTS/$domain-vhost.conf <<EOF ### www to non-www #server { # listen 80; # server_name www.$domain; # return 301 http://$domain\$request_uri; #} server { listen 80; server_name $domain www.$domain; root /home/$username; charset utf-8; index index.php index.html index.htm; #access_log $WEB_DIR/logs/$domain-access.log; access_log off; error_log $WEB_DIR/logs/$domain-error.log; #error_log off; ## REWRITES BELOW ## ## INCLUDE COMMONS ## include php.conf; include errors.conf; include drop.conf; include expires.conf; } EOF # Creating {public,log} directories #mkdir -p $WEB_DIR/$username/{public_html,logs} # Creating index.html file cat > $WEB_DIR/$username/index.html <<EOF <!DOCTYPE html> <html lang="en"> <head> <title>$domain</title> <meta charset="utf-8" /> </head> <body class="container"> <header><h1>$domain<h1></header> <div id="wrapper"><p>Hello World</p></div> <footer>© $(date +%Y)</footer> </body> </html> EOF # Changing permissions chown -R $WEB_USER:$WEB_USER $WEB_DIR/$username # Enable site by creating symbolic link # ln -s $NGINX_AVAILABLE_VHOSTS/$1 $NGINX_ENABLED_VHOSTS/$1 # Restart echo "Do you wish to restart nginx?" select yn in "Yes" "No"; do case $yn in Yes ) service nginx restart ; break;; No ) exit;; esac done ok "Site Created for $domain"