Advertisement
th3joker

wordpress_install

May 4th, 2018
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 20.42 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Tech and Me © - 2017, https://www.techandme.se/
  4.  
  5. # Prefer IPv4
  6. sed -i "s|#precedence ::ffff:0:0/96  100|precedence ::ffff:0:0/96  100|g" /etc/gai.conf
  7.  
  8. # shellcheck disable=2034,2059
  9. true
  10. # shellcheck source=lib.sh
  11. FIRST_IFACE=1 && CHECK_CURRENT_REPO=1 . <(curl -sL https://raw.githubusercontent.com/techandme/wordpress-vm/master/lib.sh)
  12. unset FIRST_IFACE
  13. unset CHECK_CURRENT_REPO
  14.  
  15. # Check for errors + debug code and abort if something isn't right
  16. # 1 = ON
  17. # 0 = OFF
  18. DEBUG=0
  19. debug_mode
  20.  
  21. # Check if root
  22. if ! is_root
  23. then
  24.     printf "\n${Red}Sorry, you are not root.\n${Color_Off}You must type: ${Cyan}sudo ${Color_Off}bash %s/wordpress_install.sh\n" "$SCRIPTS"
  25.     exit 1
  26. fi
  27.  
  28. # Test RAM size (2GB min) + CPUs (min 1)
  29. ram_check 2 Wordpress
  30. cpu_check 1 Wordpress
  31.  
  32. # Set locales
  33. apt install language-pack-en-base -y
  34. sudo locale-gen "sv_SE.UTF-8" && sudo dpkg-reconfigure --frontend=noninteractive locales
  35.  
  36. # Show current user
  37. echo
  38. echo "Current user with sudo permissions is: $UNIXUSER".
  39. echo "This script will set up everything with that user."
  40. echo "If the field after ':' is blank you are probably running as a pure root user."
  41. echo "It's possible to install with root, but there will be minor errors."
  42. echo
  43. echo "Please create a user with sudo permissions if you want an optimal installation."
  44. run_static_script adduser
  45.  
  46. # Check Ubuntu version
  47. echo "Checking server OS and version..."
  48. if [ "$OS" != 1 ]
  49. then
  50.     echo "Ubuntu Server is required to run this script."
  51.     echo "Please install that distro and try again."
  52.     exit 1
  53. fi
  54.  
  55.  
  56. if ! version 18.04 "$DISTRO" 18.04.4; then
  57.     echo "Ubuntu version $DISTRO must be between 18.04 - 18.04.4"
  58.     exit
  59. fi
  60.  
  61. # Check if it's a clean server
  62. is_this_installed postgresql
  63. is_this_installed apache2
  64. is_this_installed nginx
  65. is_this_installed php
  66. is_this_installed mysql-common
  67. is_this_installed mariadb-server
  68.  
  69. # Create $SCRIPTS dir
  70. if [ ! -d "$SCRIPTS" ]
  71. then
  72.     mkdir -p "$SCRIPTS"
  73. fi
  74.  
  75. # Change DNS
  76. if ! [ -x "$(command -v resolvconf)" ]
  77. then
  78.     apt install resolvconf -y -q
  79.     yes | dpkg-reconfigure resolvconf
  80. fi
  81. echo "nameserver 1.1.1.1" > /etc/resolvconf/resolv.conf.d/base
  82. echo "nameserver 1.1.0.0" >> /etc/resolvconf/resolv.conf.d/base
  83.  
  84. # Check network
  85. if ! [ -x "$(command -v nslookup)" ]
  86. then
  87.     apt install dnsutils -y -q
  88. fi
  89. if ! [ -x "$(command -v ifup)" ]
  90. then
  91.     apt install ifupdown -y -q
  92. fi
  93. sudo ifdown "$IFACE" && sudo ifup "$IFACE"
  94. if ! nslookup github.com
  95. then
  96.     echo "Network NOT OK. You must have a working Network connection to run this script."
  97.     exit 1
  98. fi
  99.  
  100. # Check where the best mirrors are and update
  101. echo
  102. printf "Your current server repository is:  ${Cyan}%s${Color_Off}\n" "$REPO"
  103. if [[ "no" == $(ask_yes_or_no "Do you want to try to find a better mirror?") ]]
  104. then
  105.     echo "Keeping $REPO as mirror..."
  106.     sleep 1
  107. else
  108.    echo "Locating the best mirrors..."
  109.    apt update -q4 & spinner_loading
  110.    apt install python-pip -y
  111.    pip install \
  112.        --upgrade pip \
  113.        apt-select
  114.     apt-select -m up-to-date -t 5 -c
  115.     sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup && \
  116.     if [ -f sources.list ]
  117.     then
  118.         sudo mv sources.list /etc/apt/
  119.     fi
  120. fi
  121. clear
  122.  
  123. # Set keyboard layout
  124. echo "Current keyboard layout is $(localectl status | grep "Layout" | awk '{print $3}')"
  125. if [[ "no" == $(ask_yes_or_no "Do you want to change keyboard layout?") ]]
  126. then
  127.     echo "Not changing keyboard layout..."
  128.     sleep 1
  129.     clear
  130. else
  131.     dpkg-reconfigure keyboard-configuration
  132.     clear
  133. fi
  134.  
  135. # Update system
  136. apt update -q4 & spinner_loading
  137.  
  138. # Write MARIADB pass to file and keep it safe
  139. {
  140. echo "[client]"
  141. echo "password='$MARIADB_PASS'"
  142. } > "$MYCNF"
  143. chmod 0600 $MYCNF
  144. chown root:root $MYCNF
  145.  
  146. # Install MARIADB
  147. apt install software-properties-common -y
  148. sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
  149. sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://ftp.ddg.lth.se/mariadb/repo/10.2/ubuntu xenial main'
  150. sudo debconf-set-selections <<< "mariadb-server-10.2 mysql-server/root_password password $MARIADB_PASS"
  151. sudo debconf-set-selections <<< "mariadb-server-10.2 mysql-server/root_password_again password $MARIADB_PASS"
  152. apt update -q4 & spinner_loading
  153. check_command apt install mariadb-server-10.2 -y
  154.  
  155. # Prepare for Wordpress installation
  156. # https://blog.v-gar.de/2017/02/en-solved-error-1698-28000-in-mysqlmariadb/
  157. mysql -u root mysql -p"$MARIADB_PASS" -e "UPDATE user SET plugin='' WHERE user='root';"
  158. mysql -u root mysql -p"$MARIADB_PASS" -e "UPDATE user SET password=PASSWORD('$MARIADB_PASS') WHERE user='root';"
  159. mysql -u root -p"$MARIADB_PASS" -e "flush privileges;"
  160.  
  161. # mysql_secure_installation
  162. apt -y install expect
  163. SECURE_MYSQL=$(expect -c "
  164. set timeout 10
  165. spawn mysql_secure_installation
  166. expect \"Enter current password for root (enter for none):\"
  167. send \"$MARIADB_PASS\r\"
  168. expect \"Change the root password?\"
  169. send \"n\r\"
  170. expect \"Remove anonymous users?\"
  171. send \"y\r\"
  172. expect \"Disallow root login remotely?\"
  173. send \"y\r\"
  174. expect \"Remove test database and access to it?\"
  175. send \"y\r\"
  176. expect \"Reload privilege tables now?\"
  177. send \"y\r\"
  178. expect eof
  179. ")
  180. echo "$SECURE_MYSQL"
  181. apt -y purge expect
  182.  
  183. # Write a new MariaDB config
  184. run_static_script new_etc_mycnf
  185.  
  186. # Install VM-tools
  187. apt install open-vm-tools -y
  188.  
  189. # Install Nginx
  190. apt update -q4 && spinner_loading
  191. check_command apt install nginx -y
  192. sudo systemctl stop nginx.service
  193. sudo systemctl start nginx.service
  194. sudo systemctl enable nginx.service
  195.  
  196. # Install PHP 7.2
  197. apt install -y \
  198.         php \
  199.     php7.2-fpm \
  200.     php7.2-common \
  201.     php7.2-mbstring \
  202.     php7.2-xmlrpc \
  203.     php7.2-gd \
  204.     php7.2-xml \
  205.     php7.2-mysql \
  206.     php7.2-cli \
  207.     php7.2-zip \
  208.     php7.2-curl
  209.    
  210. # Configure PHP
  211. sed -i "s|allow_url_fopen =.*|allow_url_fopen = On|g" /etc/php/7.2/fpm/php.ini
  212. sed -i "s|max_execution_time =.*|max_execution_time = 360|g" /etc/php/7.2/fpm/php.ini
  213. sed -i "s|file_uploads =.*|file_uploads = On|g" /etc/php/7.2/fpm/php.ini
  214. sed -i "s|upload_max_filesize =.*|upload_max_filesize = 100M|g" /etc/php/7.2/fpm/php.ini
  215. sed -i "s|memory_limit =.*|memory_limit = 256M|g" /etc/php/7.2/fpm/php.ini
  216. sed -i "s|post_max_size =.*|post_max_size = 110M|g" /etc/php/7.2/fpm/php.ini
  217. sed -i "s|cgi.fix_pathinfo =.*|cgi.fix_pathinfo=0|g" /etc/php/7.2/fpm/php.ini
  218. sed -i "s|date.timezone =.*|date.timezone = Europe/Stockholm|g" /etc/php/7.2/fpm/php.ini
  219.  
  220. # Download wp-cli.phar to be able to install Wordpress
  221. check_command curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  222. chmod +x wp-cli.phar
  223. mv wp-cli.phar /usr/local/bin/wp
  224.  
  225. # Create dir
  226. mkdir $WPATH
  227.  
  228. # Create wp-cli.yml
  229. touch $WPATH/wp-cli.yml
  230. cat << YML_CREATE > "$WPATH/wp-cli.yml"
  231. nginx_modules:
  232.   - mod_rewrite
  233. YML_CREATE
  234.  
  235. # Show info about wp-cli
  236. wp --info --allow-root
  237.  
  238. # Download Wordpress
  239. cd "$WPATH"
  240. check_command wp core download --allow-root --force --debug --path="$WPATH"
  241.  
  242. # Populate DB
  243. mysql -uroot -p"$MARIADB_PASS" <<MYSQL_SCRIPT
  244. CREATE DATABASE $WPDBNAME;
  245. CREATE USER '$WPDBUSER'@'localhost' IDENTIFIED BY '$WPDBPASS';
  246. GRANT ALL PRIVILEGES ON $WPDBNAME.* TO '$WPDBUSER'@'localhost';
  247. FLUSH PRIVILEGES;
  248. MYSQL_SCRIPT
  249. wp core config --allow-root --dbname=$WPDBNAME --dbuser=$WPDBUSER --dbpass="$WPDBPASS" --dbhost=localhost --extra-php <<PHP
  250. define( 'WP_DEBUG', false );
  251. define( 'WP_CACHE_KEY_SALT', 'wpredis_' );
  252. define( 'WP_REDIS_MAXTTL', 9600);
  253. define( 'WP_REDIS_SCHEME', 'unix' );
  254. define( 'WP_REDIS_PATH', '/var/run/redis/redis.sock' );
  255. define( 'WP_REDIS_PASSWORD', '$REDIS_PASS' );
  256. define( 'WP_AUTO_UPDATE_CORE', true );
  257. PHP
  258.  
  259. # Make sure the passwords are the same, this file will be deleted when Redis is run.
  260. echo "$REDIS_PASS" > /tmp/redis_pass.txt
  261.  
  262. # Install Wordpress
  263. check_command wp core install --allow-root --url=http://"$ADDRESS"/ --title=Wordpress --admin_user=$WPADMINUSER --admin_password="$WPADMINPASS" --admin_email=no-reply@techandme.se --skip-email
  264. echo "WP PASS: $WPADMINPASS" > /var/adminpass.txt
  265. chown wordpress:wordpress /var/adminpass.txt
  266.  
  267. # Create welcome post
  268. check_command wget -q $STATIC/welcome.txt
  269. sed -i "s|wordpress_user_login|$WPADMINUSER|g" welcome.txt
  270. sed -i "s|wordpress_password_login|$WPADMINPASS|g" welcome.txt
  271. wp post create ./welcome.txt --post_title='Tech and Me - Welcome' --post_status=publish --path=$WPATH --allow-root
  272. rm -f welcome.txt
  273. wp post delete 1 --force --allow-root
  274.  
  275. # Show version
  276. wp core version --allow-root
  277. sleep 3
  278.  
  279. # Install Apps
  280. wp plugin install --allow-root twitter-tweets --activate
  281. wp plugin install --allow-root social-pug --activate
  282. wp plugin install --allow-root wp-mail-smtp --activate
  283. wp plugin install --allow-root google-captcha --activate
  284. wp plugin install --allow-root redis-cache --activate
  285.  
  286. # set pretty urls
  287. wp rewrite structure '/%postname%/' --hard --allow-root
  288. wp rewrite flush --hard --allow-root
  289.  
  290. # delete akismet and hello dolly
  291. wp plugin delete akismet --allow-root
  292. wp plugin delete hello --allow-root
  293.  
  294. # Secure permissions
  295. run_static_script wp-permissions
  296.  
  297. # Hardening security
  298. # create .htaccess to protect uploads directory
  299. cat > $WPATH/wp-content/uploads/.htaccess <<'EOL'
  300. # Protect this file
  301. <Files .htaccess>
  302. Order Deny,Allow
  303. Deny from All
  304. </Files>
  305. # whitelist file extensions to prevent executables being
  306. # accessed if they get uploaded
  307. order deny,allow
  308. deny from all
  309. <Files ~ ".(docx?|xlsx?|pptx?|txt|pdf|xml|css|jpe?g|png|gif)$">
  310. allow from all
  311. </Files>
  312. EOL
  313.  
  314. # Install Figlet
  315. apt install figlet -y
  316.  
  317. # Generate $SSL_CONF
  318. install_if_not ssl-cert
  319. systemctl stop nginx.service && wait
  320. if [ ! -f $SSL_CONF ];
  321.         then
  322.         touch $SSL_CONF
  323.         cat << SSL_CREATE > $SSL_CONF
  324. server {
  325.     listen 443 ssl http2;
  326.     listen [::]:443 ssl http2;
  327.    
  328.     ## Your website name goes here.
  329.     # server_name example.com;
  330.     ## Your only path reference.
  331.     root $WPATH;
  332.     ## This should be in your http block and if it is, it's not needed here.
  333.     index index.php;
  334.     resolver $GATEWAY;
  335.    
  336.     # certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
  337.     ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
  338.     ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
  339.     ssl_session_timeout 1d;
  340.     ssl_session_cache shared:SSL:50m;
  341.     ssl_session_tickets off;
  342.     # Diffie-Hellman parameter for DHE ciphersuites, recommended 4096 bits
  343.     # ssl_dhparam /path/to/dhparam.pem;
  344.     # intermediate configuration. tweak to your needs.
  345.     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  346.     ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
  347.     ssl_prefer_server_ciphers on;
  348.     # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
  349.     add_header Strict-Transport-Security max-age=15768000;
  350.     # OCSP Stapling ---
  351.     # fetch OCSP records from URL in ssl_certificate and cache them
  352.     ssl_stapling on;
  353.     ssl_stapling_verify on;
  354.     ## verify chain of trust of OCSP response using Root CA and Intermediate certs
  355.     # ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates;
  356.    
  357.     location / {
  358.         try_files \$uri \$uri/ /index.php?\$args;        
  359.     }
  360.    
  361.     location ~ /\\. {
  362.         access_log off;
  363.         log_not_found off;
  364.         deny all;
  365.     }
  366.     location = /favicon.ico {
  367.                 log_not_found off;
  368.                 access_log off;
  369.     }
  370.     location = /robots.txt {
  371.                 allow all;
  372.                 log_not_found off;
  373.                 access_log off;
  374.     }
  375.     location ~ \\.php$ {
  376.                 #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
  377.                 fastcgi_index index.php;
  378.         include fastcgi.conf;
  379.         include fastcgi_params;
  380.                 fastcgi_intercept_errors on;
  381.                 fastcgi_pass php;
  382.                 fastcgi_buffers 16 16k;
  383.                 fastcgi_buffer_size 32k;
  384.         fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  385.         fastcgi_param SCRIPT_NAME \$fastcgi_script_name;
  386.      }
  387.      location ~* \\.(js|css|png|jpg|jpeg|gif|ico)$ {
  388.                 expires max;
  389.                 log_not_found off;
  390.      }
  391. }
  392. SSL_CREATE
  393. echo "$SSL_CONF was successfully created"
  394. sleep 1
  395. fi
  396.  
  397. # Generate $HTTP_CONF
  398. if [ ! -f $HTTP_CONF ];
  399.         then
  400.         touch $HTTP_CONF
  401.         cat << HTTP_CREATE > $HTTP_CONF
  402. server {
  403.     listen 80;
  404.     listen [::]:80;
  405.    
  406.     ## Your website name goes here.
  407.     # server_name example.com;
  408.     ## Your only path reference.
  409.     root $WPATH;
  410.     ## This should be in your http block and if it is, it's not needed here.
  411.     index index.php;
  412.     resolver $GATEWAY;
  413.    
  414.     location / {
  415.         try_files \$uri \$uri/ /index.php?\$args;        
  416.     }
  417.    
  418.     location ~ /\\. {
  419.         access_log off;
  420.         log_not_found off;
  421.         deny all;
  422.     }
  423.     location = /favicon.ico {
  424.                 log_not_found off;
  425.                 access_log off;
  426.     }
  427.     location = /robots.txt {
  428.                 allow all;
  429.                 log_not_found off;
  430.                 access_log off;
  431.     }
  432.     location ~ \\.php$ {
  433.                 #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
  434.                 fastcgi_index index.php;
  435.         include fastcgi.conf;
  436.         include fastcgi_params;
  437.                 fastcgi_intercept_errors on;
  438.                 fastcgi_pass php;
  439.                 fastcgi_buffers 16 16k;
  440.                 fastcgi_buffer_size 32k;
  441.         fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  442.         fastcgi_param SCRIPT_NAME \$fastcgi_script_name;
  443.      }
  444.      location ~* \\.(js|css|png|jpg|jpeg|gif|ico)$ {
  445.                 expires max;
  446.                 log_not_found off;
  447.      }
  448. }
  449. HTTP_CREATE
  450. echo "$HTTP_CONF was successfully created"
  451. sleep 1
  452. fi
  453.  
  454. # Generate $NGINX_CONF
  455. if [ -f $NGINX_CONF ];
  456.         then
  457.         rm $NGINX_CONF
  458.     touch $NGINX_CONF
  459.         cat << NGINX_CREATE > $NGINX_CONF
  460. user www-data;
  461. worker_processes 2;
  462. pid /run/nginx.pid;
  463.     worker_rlimit_nofile 10240;
  464. events {
  465.     worker_connections 10240;
  466.     multi_accept on;
  467.     use epoll;
  468. }
  469.    
  470. http {
  471.     ##
  472.     # Basic Settings
  473.     ##
  474.     sendfile on;
  475.     tcp_nopush on;
  476.     tcp_nodelay on;
  477.     keepalive_timeout 65;
  478.     types_hash_max_size 2048;
  479.     server_tokens off;
  480.     client_body_timeout   10;
  481.     client_header_timeout 10;
  482.     client_header_buffer_size 128;
  483.         client_max_body_size 10M;
  484.     # server_names_hash_bucket_size 64;
  485.     # server_name_in_redirect off;
  486.     include /etc/nginx/mime.types;
  487.     default_type application/octet-stream;
  488.     ##
  489.     # SSL Settings
  490.     ##
  491.     ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
  492.     ssl_prefer_server_ciphers on;
  493.     ##
  494.     # Logging Settings
  495.     ##
  496.     access_log /var/log/nginx/access.log;
  497.     error_log /var/log/nginx/error.log;
  498.     ##
  499.     # Gzip Settings
  500.     ##
  501.     gzip on;
  502.     gzip_disable "msie6";
  503.     # gzip_vary on;
  504.     # gzip_proxied any;
  505.     # gzip_comp_level 6;
  506.       gzip_buffers 16 4k;
  507.     # gzip_http_version 1.1;   
  508.     # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
  509.     ##
  510.     # Virtual Host Configs
  511.     ##
  512.     include /etc/nginx/conf.d/*.conf;
  513.     include /etc/nginx/sites-enabled/*;
  514.     upstream php {
  515.         server unix:/run/php/php7.2-fpm.sock;
  516.         }
  517. }
  518. #mail {
  519. #   # See sample authentication script at:
  520. #   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
  521. #
  522. #   # auth_http localhost/auth.php;
  523. #   # pop3_capabilities "TOP" "USER";
  524. #   # imap_capabilities "IMAP4rev1" "UIDPLUS";
  525. #
  526. #   server {
  527. #       listen     localhost:110;
  528. #       protocol   pop3;
  529. #       proxy      on;
  530. #   }
  531. #
  532. #   server {
  533. #       listen     localhost:143;
  534. #       protocol   imap;
  535. #       proxy      on;
  536. #   }
  537. #}
  538. NGINX_CREATE
  539. echo "$NGINX_CONF was successfully created"
  540. sleep 1
  541. fi
  542.  
  543. # Generate $NGINX_CONF
  544. if [ -f "$NGINX_DEF" ];
  545. then
  546.     rm -f $NGINX_DEF
  547.     rm -f /etc/nginx/sites-enabled/default
  548.     touch $NGINX_DEF
  549.     cat << NGINX_DEFAULT > "$NGINX_DEF"
  550. ##
  551. # You should look at the following URL's in order to grasp a solid understanding
  552. # of Nginx configuration files in order to fully unleash the power of Nginx.
  553. # http://wiki.nginx.org/Pitfalls
  554. # http://wiki.nginx.org/QuickStart
  555. # http://wiki.nginx.org/Configuration
  556. #
  557. # Generally, you will want to move this file somewhere, and start with a clean
  558. # file but keep this around for reference. Or just disable in sites-enabled.
  559. #
  560. # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
  561. ##
  562. # Default server configuration
  563. #
  564. server {
  565.     listen 80 default_server;
  566.     listen [::]:80 default_server;
  567. # Let's Encrypt
  568.         location ~ /.well-known {
  569.     root /usr/share/nginx/html;
  570.             allow all;
  571.     }
  572.     # SSL configuration
  573.     #
  574.     # listen 443 ssl default_server;
  575.     # listen [::]:443 ssl default_server;
  576.     #
  577.     # Note: You should disable gzip for SSL traffic.
  578.     # See: https://bugs.debian.org/773332
  579.     #
  580.     # Read up on ssl_ciphers to ensure a secure configuration.
  581.     # See: https://bugs.debian.org/765782
  582.     #
  583.     # Self signed certs generated by the ssl-cert package
  584.     # Don't use them in a production server!
  585.     #
  586.     # include snippets/snakeoil.conf;
  587.     root $WWW_ROOT;
  588.     # Add index.php to the list if you are using PHP
  589.     index index.html index.htm index.nginx-debian.html;
  590.     server_name _;
  591.     location / {
  592.         # First attempt to serve request as file, then
  593.         # as directory, then fall back to displaying a 404.
  594.         try_files \$uri \$uri/ =404;
  595.     }
  596. }
  597. NGINX_DEFAULT
  598. echo "$NGINX_DEF was successfully created"
  599. sleep 1
  600. fi
  601.  
  602. # Enable new config
  603. ln -s "$NGINX_DEF" /etc/nginx/sites-enabled/
  604. ln -s "$SSL_CONF" /etc/nginx/sites-enabled/
  605. ln -s "$HTTP_CONF" /etc/nginx/sites-enabled/
  606. systemctl restart nginx.service
  607.  
  608. # Enable UTF8mb4 (4-byte support)
  609. databases=$(mysql -u root -p"$MARIADB_PASS" -e "SHOW DATABASES;" | tr -d "| " | grep -v Database)
  610. for db in $databases; do
  611.     if [[ "$db" != "performance_schema" ]] && [[ "$db" != _* ]] && [[ "$db" != "information_schema" ]];
  612.     then
  613.         echo "Changing to UTF8mb4 on: $db"
  614.         mysql -u root -p"$MARIADB_PASS" -e "ALTER DATABASE $db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
  615.     fi
  616. done
  617.  
  618. # Enable OPCache for PHP
  619. phpenmod opcache
  620. {
  621. echo "# OPcache settings for Wordpress"
  622. echo "opcache.enable=1"
  623. echo "opcache.enable_cli=1"
  624. echo "opcache.interned_strings_buffer=8"
  625. echo "opcache.max_accelerated_files=10000"
  626. echo "opcache.memory_consumption=128"
  627. echo "opcache.save_comments=1"
  628. echo "opcache.revalidate_freq=1"
  629. echo "opcache.validate_timestamps=1"
  630. } >> /etc/php/7.2/fpm/php.ini
  631.  
  632. # Install Redis
  633. run_static_script redis-server-ubuntu
  634.  
  635. # Set secure permissions final
  636. run_static_script wp-permissions
  637.  
  638. # Prepare for first mount
  639. download_static_script instruction
  640. download_static_script history
  641. run_static_script change-root-profile
  642. run_static_script change-wordpress-profile
  643. if [ ! -f "$SCRIPTS"/wordpress-startup-script.sh ]
  644. then
  645. check_command wget -q "$GITHUB_REPO"/wordpress-startup-script.sh -P "$SCRIPTS"
  646. fi
  647.  
  648. # Make $SCRIPTS excutable
  649. chmod +x -R "$SCRIPTS"
  650. chown root:root -R "$SCRIPTS"
  651.  
  652. # Allow wordpress to run theese scripts
  653. chown wordpress:wordpress "$SCRIPTS/instruction.sh"
  654. chown wordpress:wordpress "$SCRIPTS/history.sh"
  655.  
  656. # Upgrade
  657. apt dist-upgrade -y
  658.  
  659. # Remove LXD (always shows up as failed during boot)
  660. apt purge lxd -y
  661.  
  662. # Cleanup
  663. CLEARBOOT=$(dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e ''"$(uname -r | cut -f1,2 -d"-")"'' | grep -e '[0-9]' | xargs sudo apt -y purge)
  664. echo "$CLEARBOOT"
  665. apt autoremove -y
  666. apt autoclean
  667. find /root "/home/$UNIXUSER" -type f \( -name '*.sh*' -o -name '*.html*' -o -name '*.tar*' -o -name '*.zip*' \) -delete
  668.  
  669. # Install virtual kernels for Hyper-V, and extra for UTF8 kernel module + Collabora and OnlyOffice
  670. # Kernel 4.15
  671. #yes | apt install --install-recommends \
  672. #linux-virtual \
  673. #linux-tools-virtual \
  674. #linux-cloud-tools-virtual \
  675. #linux-image-virtual \
  676. #linux-image-extra-virtual
  677.  
  678. # Prefer IPv6
  679. sed -i "s|precedence ::ffff:0:0/96  100|#precedence ::ffff:0:0/96  100|g" /etc/gai.conf
  680.  
  681. # Reboot
  682. echo "Installation done, system will now reboot..."
  683. reboot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement