Setting Up Wordpress with WP CLI on Ubuntu 16.04

These instructions assume that PHP, Mysql / MariaDB, and Apache have already been setup on the Ubuntu 16.04 installation, and instructions for such preparation can be found here: Setting Up Apache 2.4, MariaDB, and PHP 7 with Ubuntu 16.04 on a Digital Ocean VPS.

  • Download wp cli
    • Download: curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
    • Test: php wp-cli.phar --info
    • Adjust permissions: chmod +x wp-cli.phar
    • Rename and move utility to a directory in pathsudo mv wp-cli.phar /usr/local/bin/wp
  • Create a database, database user, and assign privileges (MySQL or MariaDB)
    • Create database: mysql -u root -p -ve "create database test"
    • Create database user: mysql -u root -p -ve "create user 'test_user'@'localhost' identified by 'password'"
    • Assign privileges: mysql -u root -p -ve "grant all privileges on test.* to 'test_user'@'localhost'"
    • Flush privileges: mysql -u root -p -ve "flush privileges"
  • Install and Configure WordPress
    • Create a folder for the WordPress installation: mkdir wordpress && cd wordpress
    • Download WordPress: wp core download
    • Configure WordPress: wp core config --dbname=test --dbuser=test_user --dbpass="password"
    • Setup WordPress: wp core install --url="localhost/wp" --title="Test" --admin_user="admin" --admin_password="password" --admin_email="user@domain.com"
    • Remove sample config: rm wp-config-sample.php
    • Add define('FS_METHOD', 'direct'); to wp-config.php
    • Install plugins: wp plugin install wordpress-seo --activate
    • Install theme: wp theme install thebesttheme --activate
    • Remove default unused themes:
      • wp theme delete twentyfourteen
      • wp theme delete twentyfifteen
      • wp theme delete twentysixteen
    • Move wordpress to web root: sudo mv wordpress/ /var/www/
    • Configure permissions:
      • Assign ownership of WordPress files in the document root to system user: sudo chown -R ubuntu:www-data /var/www/wordpress/
      • Set setgid bit to cause new files to inherit group of parent directory: sudo find /var/www/wordpress/ -type d -exec chmod g+s {} \;
      • Group write access to wp-content directory: sudo chmod g+w /var/www/wordpress/wp-content
      • Group write access to wp-content/themes directory: sudo chmod -R g+w /var/www/wordpress/wp-content/themes
      • Group write access to wp-content/plugins directory: sudo chmod -R g+w /var/www/wordpress/wp-content/plugins
    • Enable VirtualHost: sudo a2ensite wordpress.conf
    • Restart Apache: sudo systemctl restart apache2.service
  • Helpful Links

Tags

 WordPress  WP-CLI  Ubuntu