Advertisement
Guest User

wp

a guest
Feb 23rd, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.03 KB | None | 0 0
  1. if [[ $EUID -ne 0 ]]; then
  2. echo "This script must be run as root"
  3. exit 1
  4. fi
  5.  
  6. LOG=script.log
  7. ERROR=script.err
  8.  
  9. mysql_secure_installation () {
  10. echo -e "Removing Insecure Details From MySQL"
  11. mysql -u$adminuser -p$adminpass -e "DELETE FROM mysql.user WHERE User='';"
  12. mysql -u$adminuser -p$adminpass -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
  13. mysql -u$adminuser -p$adminpass -e "DROP DATABASE IF EXISTS test;"
  14. mysql -u$adminuser -p$adminpass -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';"
  15. mysql -u$adminuser -p$adminpass -e "FLUSH PRIVILEGES;"
  16. }
  17.  
  18. mysql_setup () {
  19. echo -e "${BLUE}Setting up mysql-server...${NC}"
  20. echo -e "${CAYAN}"
  21. ct=0
  22. while [ $ct -eq 0 ]
  23. do
  24. read -p "Enter User for MYSQL Admin: " adminuser
  25. echo
  26. read -sp "Enter the password for MYSQL Admin: " adminpass
  27. echo
  28. read -sp "Re-enter the password for MYSQL Admin: " re_adminpass
  29. echo
  30.  
  31. if [ $adminpass == $re_adminpass ];
  32. then
  33. echo -e "${GREEN}Password will be set for MySQL Admin.${NC}"
  34. echo "mysql-server mysql-server/root_password password $adminpass" | sudo debconf-set-selections
  35. echo "mysql-server mysql-server/root_password_again password $adminpass" | sudo debconf-set-selections
  36. ct=1
  37. else
  38. echo -e "${RED}Password did not match... Try again${NC}"
  39. fi
  40. done
  41. echo -e "${NC}"
  42. }
  43.  
  44. apt update
  45. RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' CAYAN='\033[0;36m'
  46. BLUE='\033[0;34m' HBLK='\033[1;94m' YELLOW='\033[1;93m'
  47.  
  48. echo -e "------------------------------------"
  49. echo -e "${BLUE}Checking if Nginx is installed${NC}"
  50. dpkg -l | grep nginx
  51. if [ "$?" -eq 0 ];
  52. then
  53. echo
  54. echo -e "${GREEN}NGINX is already Installed...${NC}";
  55. service nginx start
  56. echo -e "------------------------------------"
  57. else
  58. echo -e "------------------------------------"
  59. echo -e "${BLUE}Installing NGINX...${NC}"
  60. apt install nginx -y >>$LOG 2>>$ERROR
  61. service nginx start
  62. echo -e "${GREEN}Nginx is Installed.${NC}";
  63. echo -e "------------------------------------"
  64. fi
  65.  
  66. echo -e "${BLUE}Checking if Mysql is installed${NC}"
  67. dpkg -l | grep mysql-server
  68. if [ "$?" -eq 0 ];
  69. then
  70. echo
  71. echo -e "${GREEN}MySQL-Server is already Installed...${NC}";
  72. service mysql start
  73. echo -e "${CAYAN}"
  74. read -p "Enter the user name of MYSQL Admin: " adminuser
  75. read -sp "Enter the pasword of MYSQL Admin: " adminpass
  76. echo -e "${NC}"
  77. mysql_secure_installation
  78. else
  79. mysql_setup
  80. echo -e "------------------------------------"
  81. echo -e "${BLUE}Installing mysql-server... ${NC}"
  82. apt install mysql-server -y >>$LOG 2>>$ERROR
  83. service mysql start
  84. mysql_secure_installation
  85. echo -e "${GREEN}Mysql Setup is complete. ${NC}"
  86. echo -e "------------------------------------"
  87. fi
  88.  
  89. echo -e "${CAYAN}"
  90. read -p "Enter domain name: www." domain
  91. echo
  92. echo -e "Your Domain name is www.$domain "
  93. echo -e "Making entry for www.$domain"
  94. echo "127.0.0.1 $domain www.$domain" >> /etc/hosts
  95. echo -e "${NC}"
  96.  
  97. ct=0
  98. dbname="$domain"_db
  99. echo
  100. echo -e "${CAYAN}"
  101. read -p "Enter the user for $dbname database: " wpuser
  102. while [ $ct -eq 0 ]
  103. do
  104. echo -e "${CAYAN}"
  105. read -sp "Enter the password for $dbname database: " wppass
  106. echo
  107. read -sp "Re-enter the password for $dbname database: " re_wppass
  108. echo -e "${NC}"
  109. echo
  110. echo
  111. if [ $wppass == $re_wppass ];
  112. then
  113. echo -e "${GREEN}Password set for wordpress database.${NC}"
  114. mysql -u$adminuser -p$adminpass -e "CREATE DATABASE \`$dbname\`"
  115. mysql -u$adminuser -p$adminpass -e "GRANT ALL PRIVILEGES ON \`$dbname\`.* TO '$wpuser'@"localhost" IDENTIFIED BY '$wppass';"
  116. mysql -u$adminuser -p$adminpass -e "FLUSH PRIVILEGES;"
  117. ct=1
  118. else
  119. echo -e "${RED}Password did not match... Try again${NC}"
  120.  
  121. fi
  122. done
  123. echo -e "${NC}"
  124.  
  125. for i in curl php7.0-fpm php7.0-mysql mysql-client php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc;
  126. do
  127. echo -e "------------------------------------"
  128. echo -e "${GREEN}Checking if $i is installed${NC}";
  129. dpkg -l | grep $i
  130. if [ "$?" -eq 0 ];
  131. then
  132. echo -e "${GREEN}$i is Installed${NC}"
  133. echo -e "-----------------------------------"
  134. else
  135. echo -e "-----------------------------------"
  136. echo -e "${RED}$i is not Installed.${NC}"
  137. echo -e "${BLUE}Installing $i ...${NC}"
  138. export DEBIAN_FRONTEND=noninteractive
  139. apt install $i -y >>$LOG 2>>$ERROR
  140. echo -e "${GREEN}$i Package is installed..${NC} "
  141. echo -e "----------------------------------"
  142. fi
  143. done
  144. service php7.0-fpm start
  145. cat <<eof > /etc/nginx/sites-available/default
  146. server {
  147.  
  148. listen 80;
  149. listen [::]:80;
  150.  
  151. root /var/www/$domain/html;
  152. index index.php index.html index.htm index.nginx-debian.html;
  153.  
  154. server_name www.$domain $domain;
  155.  
  156. location / {
  157. try_files \$uri \$uri/ /index.php$is_args$args;
  158.  
  159. }
  160.  
  161. location ~ \.php$ {
  162. include snippets/fastcgi-php.conf;
  163. fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  164. }
  165.  
  166. location ~ /\.ht {
  167. deny all;
  168. }
  169.  
  170. }
  171. eof
  172. service nginx reload
  173. service nginx restart
  174.  
  175. echo -e "Cleaning old files and Setting up new files..."
  176. rm /etc/nginx/sites-available/$domain
  177. cp /etc/nginx/sites-available/default /etc/nginx/sites-available/$domain
  178.  
  179. #Nginx php configuration
  180. sed -i 's/^;\?cgi\.fix\_pathinfo=.*$/cgi.fix_pathinfo=0/' /etc/php/7.0/fpm/php.ini
  181. service php7.0-fpm reload
  182. service php7.0-fpm restart
  183. echo
  184. echo -e "${HBLK}Downloading wordpress...${NC}"
  185.  
  186. cd /tmp
  187. curl -O https://wordpress.org/latest.tar.gz
  188. tar xzvf latest.tar.gz
  189.  
  190. cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
  191.  
  192. rm -f /etc/nginx/sites-enabled/$domain
  193. ln -s /etc/nginx/sites-available/$domain /etc/nginx/sites-enabled/
  194.  
  195. mkdir -p /var/www/$domain/html
  196. cp -a /tmp/wordpress/. /var/www/$domain/html
  197. chown -R $USER:www-data /var/www/$domain/html
  198. find /var/www/$domain/html -type d -exec chmod g+s {} \;
  199. chmod g+w /var/www/$domain/html/wp-content
  200. chmod -R g+w /var/www/$domain/html/wp-content/themes
  201. chmod -R g+w /var/www/$domain/html/wp-content/plugins
  202. curl https://api.wordpress.org/secret-key/1.1/salt/ -o salt.txt
  203. sed -i '49,56d;57r salt.txt' /var/www/$domain/html/wp-config.php
  204.  
  205. sed -i "s/database_name_here/$dbname/" /var/www/$domain/html/wp-config.php
  206. sed -i "s/username_here/$wpuser/" /var/www/$domain/html/wp-config.php
  207. sed -i "s/password_here/$wppass/" /var/www/$domain/html/wp-config.php
  208.  
  209. service nginx restart
  210. service php7.0-fpm restart
  211.  
  212. rm /etc/nginx/sites-available/default
  213. rm /etc/nginx/sites-enabled/default
  214.  
  215. echo -e "Visit the site at ${YELLOW} www.$domain ${NC}"
  216. #echo -e "WordPress Database name:${YELLOW} $dbname ${NC}"
  217. #echo -e "WordPress Database user:${YELLOW} $wpuser ${NC}"
  218. #echo -e "WordPress Database password:${YELLOW} $wppass ${NC}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement