Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Wordpress project - setup script
#!/bin/bash
# This setup script is to be used for new Wordpress project setup
# The file structure should be like this:
# /var/www/root-folder-project
# |_ /htdocs/
# |_ /dev/setup.sh
#
# The website will be installed in the `htdocs` folder
# if you can't execute the script, try `chmod +x ./setup.sh`
PROJECT="myp-plugin-name"
RPOJECT_ROOT="example.dev"
PROJECT_URL="http://example.dev"
WP_SITE_TITLE="My Plugin - Test site"
WP_USER="johndoe"
WP_PASSWORD="123abcd"
WP_EMAIL="johndoe@example.com"
WP_DB_NAME="database-name"
WP_DB_USER="database-user"
WP_DB_PASSWORD="database-password"
VHOST="<VirtualHost *:80>\n
ServerName ${PROJECT_URL}\n\n
# This should be omitted in the production environment\n
SetEnv APPLICATION_ENV development\n\n
DocumentRoot /var/www/${RPOJECT_ROOT}/htdocs/\n\n
ErrorLog /var/log/apache2/${PROJECT}-error_log \n
CustomLog /var/log/apache2/${PROJECT}-access_log combined \n
php_value error_log /var/log/apache2/${PROJECT}-phperror_log \n\n
php_value display_errors 1\n
php_value error_reporting 32767\n
php_value date.timezone UTC\n
php_value mbstring.language Neutral\n
php_value mbstring.internal_encoding UTF-8\n
php_value mbstring.http_input auto\n
php_value mbstring.http_output UTF-8\n
php_value mbstring.detect_order auto\n
php_value mbstring.substitute_character none\n
php_value default_charset UTF-8\n\n
<Directory /var/www/${RPOJECT_ROOT}/htdocs/>\n
EnableSendfile Off\n
Options FollowSymLinks\n
AllowOverride All\n
Allow from All\n
</Directory>\n\n
</VirtualHost>\n"
echo "Creating and enabling vhost..."
echo -e $VHOST > ./${PROJECT}.conf
sudo -s cp ./${PROJECT}.conf /etc/apache2/sites-available/
sudo -s a2ensite ${PROJECT}.conf
sudo -s service apache2 reload
#create database
echo "Creating the database..."
mysql -uroot -p1234 -e "CREATE DATABASE IF NOT EXISTS \`${PROJECT}\` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
# install WP-CLI
echo "Downloading and installing the latest version of WP-CLI..."
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
sudo -s chmod +x wp-cli.phar
sudo -s mv wp-cli.phar /usr/local/bin/wp
# downoad, configure and install Wordpress
cd ../htdocs/
echo "Downloading Wordpress..."
wp core download
echo "Configuring Wordpress..."
wp core config --dbname=${WP_DB_NAME} --dbuser=${WP_DB_USER} --dbpass=${WP_DB_PASSWORD}
echo "Installing Wordpress..."
wp core install --url="${PROJECT_URL}" --title="${WP_SITE_TITLE}" --admin_user="${WP_USER}" --admin_password="${WP_PASSWORD}" --admin_email="${WP_EMAIL}"
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment