Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpataki/d597478c433a219b17b5 to your computer and use it in GitHub Desktop.
Save danielpataki/d597478c433a219b17b5 to your computer and use it in GitHub Desktop.
Site Creation Automation
echo Making site $1 directory...
mkdir /var/www/html/$1
echo Creating apache configuration file...
sudo touch /etc/apache2/sites-available/$1.conf
echo Writing configuration file...
echo "<VirtualHost *:80>
ServerName $1.$2
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/$1
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html/$1>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>" > /etc/apache2/sites-available/$1.conf
echo Activating site
sudo a2ensite $1
echo Reloading Apache
sudo service apache2 reload
if [ -n "$3" ]
then
echo Downloading and installing WordPress
cd /var/www/html/$1
sudo -u vagrant wp core download
sudo -u vagrant wp core config --dbuser=root --dbpass=root --dbname=$1
sudo -u vagrant wp db create
sudo -u vagrant wp core install --url=$1.$2 --title=$1 --admin_user=danielpataki --admin_password=yourpassword --admin_email=youremail@email.com
sudo -u vagrant wp plugin delete hello akismet
fi
echo All Done
@danielpataki
Copy link
Author

Site Creation Automation On A Vagrant Box

This is a script I made for myself that allows me to create a virtual host with an optional WordPress site working in about 5 seconds. You invoke the bash script like this:

sudo bash make_site.sh mysite local yes

The three parameters are:

  • The name of the site
  • The TLD of the site
  • Wether or not you want the WordPress install

The result of this command will be a website at mysite.local with WordPress installed and running. There are a few things to note before running this script:

  • It will create the folder for the website at /var/www/html/website_name. If you have a different setup, change the folder in line 2, the DocumentRoot on line 12 and the Directory directive on line 17.
  • You must have WP-CLI installed for the WordPress install to work.
  • If you do not want the WordPress install just omit the third parameter. Setting it to no or false will not work.

The script does the following things:

  • Creates a directory for the site
  • Adds a config file for the site
  • Enables the site and restarts the server
  • Optionally installs WordPress
    • The user and password for the database is set to root because that's what it is on my Vagrant box. Change this on line 37 if needed
    • The database name is the same as the site name. Change this on line 37 if needed
    • Change the details of your admin user on line 39
    • The Hello Dolly And Akismet plugins are removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment