Skip to content

Instantly share code, notes, and snippets.

@krasnuydyx
Last active September 16, 2017 14:38
Show Gist options
  • Save krasnuydyx/0a5bbf019f928997ca35d519cee21ecf to your computer and use it in GitHub Desktop.
Save krasnuydyx/0a5bbf019f928997ca35d519cee21ecf to your computer and use it in GitHub Desktop.
create wordpress site
#!/usr/bin/env bash
echo "Enter domain name:"
read domain_name
domain=`echo ${domain_name} | cut -d "." -f 1`
echo "Enter mysql pass:"
read mysql_pass
echo "Enter admin user name:"
read admin_user
echo "Enter admin user email:"
read admin_email
if [ ! -f /usr/local/bin/wp ]; then
echo "Installing wp-cli"
cd /usr/local/bin/
curl -s -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar && mv wp-cli.phar wp
fi
cp /etc/nginx/conf.d/main /etc/nginx/conf.d/${domain_name}.conf
sed -i "s/site_name/${domain_name}/g" /etc/nginx/conf.d/${domain_name}.conf
sed -i "s/ddiirr/${domain_name}/g" /etc/nginx/conf.d/${domain_name}.conf
wget -q -O /var/www/wordpress.tar.gz https://wordpress.org/latest.tar.gz
cd /var/www/ && tar xzf wordpress.tar.gz
mv wordpress ${domain_name}
rm -rf wordpress.tar.gz
chown -R www:www ${domain_name}
nginx -t && nginx -s reload
gen_mp=`openssl rand -base64 12`
mysqladmin -p${mysql_pass} create ${domain}db
mysql -p${mysql_pass} -e "grant all privileges on ${domain}db.* to ${domain}user@'localhost' identified by '$gen_mp'"
mysql -p${mysql_pass} -e "flush privileges"
gen_fp=`openssl rand -base64 12`
echo -e "${gen_fp}\n${gen_fp}" | pure-pw useradd ${domain}user -u 80 -g 80 -d /var/www/${domain_name} -m
cd /var/www/${domain_name}
wp_pass=`openssl rand -base64 12`
sudo -u www /usr/local/bin/wp core config --dbname=${domain}db --dbuser=${domain}user --dbpass=${gen_mp}
sudo -u www /usr/local/bin/wp core install --url=http://${domain_name} --title=${domain} --admin_user=${admin_user} --admin_password=${wp_pass} --admin_email=${admin_email}
echo "DB"
echo "name => ${domain}db"
echo "user => ${domain}user"
echo "pass => ${gen_mp}"
echo "FTP"
echo "user => ${domain}user"
echo "pass => ${gen_fp}"
echo "Site"
echo "pass => ${wp_pass}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment