Skip to content

Instantly share code, notes, and snippets.

@dbtlr
Last active September 19, 2018 20:17
Show Gist options
  • Save dbtlr/629432ece8bd6061748d05e2d9f845aa to your computer and use it in GitHub Desktop.
Save dbtlr/629432ece8bd6061748d05e2d9f845aa to your computer and use it in GitHub Desktop.
#!/bin/bash -e
clear
echo "============================================"
echo "WordPress Install Script"
echo "============================================"
echo "Domain Name: "
read -e DOMAIN_NAME
echo "Database Name: "
read -e DATABASE_NAME
echo "Database User: "
read -e DATABASE_USER
echo "Database Password: "
read -s DATABASE_PASS
echo "run install? (y/n)"
read -e run
if [ "$run" == n ] ; then
exit
fi
echo "============================================"
echo "A robot is now installing WordPress for you."
echo "============================================"
LOG_PATH="/var/www/$DOMAIN_NAME/logs"
ROOT_PATH="/var/www/$DOMAIN_NAME/public"
sudo mkdir -p $ROOT_PATH
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
mv wordpress/* $ROOT_PATH
# Clean Up
rm -rf wordpress latest.tar.gz
sudo mysql -u root -p "create database $DATABASE_NAME;
create user $DATABASE_USER@localhost;
set password for $DATABASE_USER@localhost= password(\"$DATABASE_PASS\");
grant all privileges on $DATABASE_NAME.* to $DATABASE_USER@localhost identified by '$DATABASE_PASS';
flush privileges;"
cd $ROOT_PATH
sudo cp wp-config-sample.php wp-config.php
sudo perl -pi -e "s/database_name_here/$DATABASE_NAME/g" wp-config.php
sudo perl -pi -e "s/username_here/$DATABASE_USER/g" wp-config.php
sudo perl -pi -e "s/password_here/$DATABASE_PASS/g" wp-config.php
sudo 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
sudo mkdir wp-content/uploads
sudo chmod 775 wp-content/uploads
sudo chown -R www-data:www-data $ROOT_PATH
sudo certbot certonly --webroot -w /var/www/default -d $DOMAIN_NAME
sudo echo "
server {
listen 80;
server_name $DOMAIN;
return 301 https://$DOMAIN\$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name $DOMAIN;
ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
root $ROOT_PATH;
index index.php index.html index.htm;
error_log $LOG_PATH/error.log;
access_log $LOG_PATH/access.log;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location / {
try_files $uri $uri/ /index.php;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
root $ROOT_PATH;
}
}
" > /etc/nginx/sites-available/$DOMAIN_NAME
sudo ln -s /etc/nginx/sites-available/$DOMAIN_NAME /etc/nginx/sites-enabled/$DOMAIN_NAME
sudo systemctl reload nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment