Skip to content

Instantly share code, notes, and snippets.

@haakenlid
Last active August 29, 2015 14:17
Show Gist options
  • Save haakenlid/5aa6008f0d3b42ba3f29 to your computer and use it in GitHub Desktop.
Save haakenlid/5aa6008f0d3b42ba3f29 to your computer and use it in GitHub Desktop.
Create and activate new wordpress installations with mysql-database and nginx configuration on Ubuntu.
#! /bin/bash
randpw(){ < /dev/urandom tr -dc A-Za-z0-9 | head -c${1:-16};echo;}
MYSQL_ROOT_PW="your_root_pw_for_mysql_here"
SITE=$1
USER=${SITE/\./_}
DBNAME=$USER
PASSWORD=$(randpw)
echo "oppretter databasen $DBNAME"
mysql -u root -p$MYSQL_ROOT_PW -e "create database $DBNAME; GRANT ALL PRIVILEGES ON $DBNAME.* TO $DBNAME@localhost IDENTIFIED BY '$PASSWORD'"
cd /srv/
echo "laster ned wordpress"
wget http://wordpress.org/latest.tar.gz
echo "pakker ut filer"
tar -xzvf latest.tar.gz
rm -rf $SITE
echo "kopierer filer til /srv/$SITE"
mv wordpress/ $SITE
rm latest.tar.gz
cd $SITE
chmod -R g+rw .
echo "oppretter wordpress-konfigurasjon"
cp wp-config-sample.php wp-config.php
sed -i "s/database_name_here/$DBNAME/;s/username_here/$USER/;s/password_here/$PASSWORD/" wp-config.php
PHRASE="put your unique phrase here"
for i in {1..8}; do
sed -i "0,/$PHRASE/s/$PHRASE/$(randpw)/" wp-config.php
done
echo "define('FS_METHOD','direct');" >> wp-config.php
echo "konfigurerer nginx"
cd /etc/nginx/sites-available
sed s/DOMAIN_NAME_PLACEHOLDER/$SITE/ template | sudo tee $SITE > /dev/null
sudo ln -srf ./$SITE ../sites-enabled
sudo nginx -s reload
echo "siden er opprettet på http://$SITE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment