diff --git a/AbhishekGhosh-16-04.sh b/AbhishekGhosh-16-04.sh new file mode 100644 index 0000000..47c3564 --- /dev/null +++ b/AbhishekGhosh-16-04.sh @@ -0,0 +1,181 @@ +#!/bin/bash +#-- This file is a clone from https://github.com/AbhishekGhosh/Ubuntu-16.04-Nginx-WordPress-Autoinstall-Bash-Script +# Unfortunately the current version of this bash script is not working on DigitalOcean Droplet's due to several errors. +# Also has a customized mysql version which is called as percona MySQL +# --# + +export DEBIAN_FRONTEND=noninteractive; + +#-- User Defined Variables --# +# hostname='' #Your hostname (e.g. server.example.com) +# sudo_user='' #Your username +# sudo_user_passwd='' #your password +# root_passwd='' #Your new root password +# ssh_port='22' #Your SSH port if you wish to change it from the default +#-- UDV End --# + +install_pkg() +{ + echo "Updating packages." + sleep 1 + aptitude update + aptitude -y safe-upgrade + aptitude -y full-upgrade + echo "Adding ppa:ondrej/php repository as default PHP repository." + sleep 1 + sudo add-apt-repository ppa:ondrej/php + aptitude update + aptitude -y safe-upgrade + aptitude -y full-upgrade + echo "Installing PHP 7.0 packages." + sleep 1 + aptitude -y install screen build-essential libcurl3 libmcrypt4 libmemcached11 libxmlrpc-epi0 php7.0-cli php7.0-common php7.0-curl php7.0-fpm php7.0-gd php7.0-intl php7.0-json php7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-readline php7.0-xml php7.0-xmlrpc psmisc libmcrypt-dev mcrypt php-pear php-mysql php-mbstring php-mcrypt php-xml php-intl libmhash2 php-common + echo "Installing memcached (not php-memcached).Memchaed will be available at Port 11211 of IP 127.0.0.1 (localhost)." + echo "Memchaed will be available at Port 11211 of IP 127.0.0.1 (localhost)." + sleep 1 + aptitude -y install memcached + echo "Adding cgi.fix_pathinfo=0 to php.ini" + sleep 1 + echo "cgi.fix_pathinfo=0" >> /etc/php5/cgi/php.ini + sleep 1 + echo "Setting up OpCache and PHP memory limit" + sleep 1 + echo "opcache.memory_consumption=512" >> /etc/php/7.0/fpm/conf.d/10-opcache.ini + echo "opcache.max_accelerated_files=50000" >> /etc/php/7.0/fpm/conf.d/10-opcache.ini + echo "opcache.revalidate_freq=0" >> /etc/php/7.0/fpm/conf.d/10-opcache.ini + echo "opcache.consistency_checks=1" >> /etc/php/7.0/fpm/conf.d/10-opcache.ini + sed -i -r 's/\s*memory_limit\s+=\s+16M/memory_limit = 48M/g' /etc/php5/cgi/php.ini + echo "Installing Percona MySQL 5.7 Server and Client" + sleep 1 + gpg --keyserver hkp://keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A + gpg -a --export CD2EFD2A | apt-key add - + sudo sh -c 'echo "deb http://repo.percona.com/apt xenial main" >> /etc/apt/sources.list.d/percona.list' + aptitude update + aptitude -y safe-upgrade + aptitude -y full-upgrade + aptitude -y install percona-server-5.7 + mysql_secure_installation + echo "Installing Nginx-Extras webserver" + sleep 1 + aptitude -y install nginx-extras + echo "Restarting Nginx, PHP-FPM and MySQL." + sudo systemctl restart php7.0-fpm + service nginx restart + service mysql restart + echo "Done." +} + +config_web() +{ + echo "Using custom nginx default site settings." + echo " " >> /etc/nginx/sites-available/default + cat tmp/default.nginx >> /etc/nginx/sites-available/default + chmod +x /etc/nginx/thecustomizewindows/ + sudo chown -R root:www-data /usr/share/nginx/html + echo "Saving default my.cnf as /etc/mysql/my.bak" + sleep 1 + cp /etc/mysql/my.cnf /etc/mysql/my.bak + echo " " >> /etc/mysql/my.cnf + echo "Using custom my.cnf as temporary solution." + echo "You should optimize the my.cnf later from percona.com's wizard or using Major Hayden's Script." + echo "You will not see Error Connecting Database Error with our my.cnf" + sleep 1 + cat tmp/my.cnf >> /etc/mysql/my.cnf + echo "Restarting Nginx, PHP-FPM and MySQL." + sudo systemctl restart php7.0-fpm + service nginx restart + service mysql restart +} + +copy_site_setup_files() +{ + echo "A directory named thecustomizewindows will be created at /etc/nginx/ location." + echo "You will need to the load scripts from /etc/nginx/thecustomizewindows location for W3 Total Cache." + echo "If you rename that thecustomizewindows directory, adjust the new path via Nginx vHost file." + echo "We used our domain name thecustomizewindows name to avoid confusing with your domain name later." + echo "It has no other importance." + sleep 1 + mkdir /etc/nginx/thecustomizewindows/ + cp files/w3tc.conf /etc/nginx/thecustomizewindows/w3tc.conf +} + +create_site() +{ + local opt="" + echo -n "Creating site on nginx..." + cd /usr/share/nginx/html + rm -r /usr/share/nginx/html/* + curl -O https://wordpress.org/latest.tar.gz + tar -xzxf latest.tar.gz + rm latest.tar.gz && cd wordpress + mv * .. + cd .. + rm -r wordpress + cp /usr/share/nginx/html/wp-config-sample.php /usr/share/nginx/html/wp-config.php + rm /usr/share/nginx/html/wp-config-sample.php + sudo chown -R root:www-data /usr/share/nginx/html + sudo find /usr/share/nginx/html -type d -exec chmod g+s {} \; + sudo chmod g+w /usr/share/nginx/html/wp-content + sudo chmod -R g+w /usr/share/nginx/html/wp-content/themes + sudo chmod -R g+w /usr/share/nginx/html/wp-content/plugins + echo "done." + fi +} + +setup_wp() +{ + +PASS=`pwgen -s 40 1` +mysql -uroot </dev/null | base64 -w 0 | rev | cut -b 2- | rev | tr -dc 'a-zA-Z0-9'`; +wpmysqlpass=`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 "MySQL Passwords for this droplet " > /etc/motd.tail; +echo "-----------------------------------" >> /etc/motd.tail; +echo "Root MySQL Password: $rootmysqlpass" >> /etc/motd.tail; +echo "Wordpress MySQL Database: mwdb" >> /etc/motd.tail; +echo "Wordpress MySQL Username: mwsql" >> /etc/motd.tail; +echo "Wordpress MySQL Password: $wpmysqlpass" >> /etc/motd.tail; +echo "-----------------------------------" >> /etc/motd.tail; +echo "You can remove this information with 'rm -f /etc/motd.tail'" >> /etc/motd.tail; +# Install mysql-server +export DEBIAN_FRONTEND=noninteractive +# Update Ubuntu +apt-get update; +apt-get -y upgrade; +# Install Nginx/MySQL +apt-get -y install debconf-utils +echo mysql-server mysql-server/root_password password | sudo debconf-set-selections +echo mysql-server mysql-server/root_password_again password | sudo debconf-set-selections +sudo apt-get -y install mysql-server +sudo apt-get install -y php5-fpm php5-mysql mysql-client unzip; +echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/nginx-stable.list +sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C +sudo apt-get update +sudo apt-get -y install nginx +#start nginx +sudo service nginx start +# Download and uncompress WordPress +wget https://wordpress.org/latest.zip -O /tmp/wordpress.zip; +cd /tmp/ || exit; +unzip /tmp/wordpress.zip; +# Set up database user +/usr/bin/mysqladmin -u root -h localhost create wordpress; +/usr/bin/mysqladmin -u root -h localhost password $rootmysqlpass; +/usr/bin/mysql -uroot -p$rootmysqlpass -e "CREATE USER wordpress@localhost IDENTIFIED BY '"$wpmysqlpass"'"; +/usr/bin/mysql -uroot -p$rootmysqlpass -e "GRANT ALL PRIVILEGES ON wordpress.* TO wordpress@localhost"; +# Configure PHP +sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php5/fpm/php.ini +sed -i "s|listen = 127.0.0.1:9000|listen = /var/run/php5-fpm.sock|" /etc/php5/fpm/pool.d/www.conf; +sudo service php5-fpm restart +# Configure Nginx +mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak +cat > /etc/nginx/sites-available/default << "EOF" +server { + listen 80 default_server; + listen [::]:80 default_server ipv6only=on; + root /var/www/html; + index index.php index.html index.htm; + server_name localhost; + location / { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + try_files $uri $uri/ /index.php?q=$uri&$args; + # Uncomment to enable naxsi on this location + # include /etc/nginx/naxsi.rules + } + error_page 404 /404.html; + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_index index.php; + include fastcgi.conf; + } +} +EOF + +cat /etc/nginx/sites-available/default +# Add PHP info +echo "" > /var/www/html/info.php +# Configure Nginx sites-available +sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/wordpress +sudo rm /etc/nginx/sites-available/default +sudo rm /etc/nginx/sites-enabled/default +sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress +#Configure WordPress +cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php; +sed -i "s|'DB_NAME', 'database_name_here'|'DB_NAME', 'wordpress'|g" /tmp/wordpress/wp-config.php; +sed -i "s/'DB_USER', 'username_here'/'DB_USER', 'wordpress'/g" /tmp/wordpress/wp-config.php; +sed -i "s/'DB_PASSWORD', 'password_here'/'DB_PASSWORD', '$wpmysqlpass'/g" /tmp/wordpress/wp-config.php; +for i in `seq 1 8` +do +wp_salt=$(~`+=,.;:/?|' | head -c 64 | sed -e 's/[\/&]/\\&/g'); +sed -i "0,/put your unique phrase here/s/put your unique phrase here/$wp_salt/" /tmp/wordpress/wp-config.php; +done +cp -Rf /tmp/wordpress/* /var/www/html/.; +rm -f /var/www/index.html; +chown -Rf www-data:www-data /var/www/html; +service nginx restart; \ No newline at end of file