{
    "componentChunkName": "component---src-templates-blog-post-js",
    "path": "/blog/wordpress-the-command-line-and-you/",
    "result": {"data":{"markdownRemark":{"html":"<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/5d4a00913fd4b094e9d67fdd7f934299/8e1fc/wordpress-article.jpg\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 100%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAUABQDASIAAhEBAxEB/8QAGQABAQADAQAAAAAAAAAAAAAAAAQCAwUG/8QAFgEBAQEAAAAAAAAAAAAAAAAAAAID/9oADAMBAAIQAxAAAAHl1X7t8fPLFJcRQH//xAAZEAADAQEBAAAAAAAAAAAAAAABAgMSABD/2gAIAQEAAQUCCljSBUdIYZ3UTeODo+//xAAWEQADAAAAAAAAAAAAAAAAAAAAEBH/2gAIAQMBAT8BK//EABURAQEAAAAAAAAAAAAAAAAAABEg/9oACAECAQE/AWP/xAAfEAABAwMFAAAAAAAAAAAAAAABAAIRECExAxIiMlH/2gAIAQEABj8CgC6kbj7ajdR+YvKdy7BRKya//8QAGxABAQEBAAMBAAAAAAAAAAAAAREAMSFRcZH/2gAIAQEAAT8hvc+gY39RM0wqGISxWl4W4h8vi8yvf21feq9Xf//aAAwDAQACAAMAAAAQ9zC+/8QAFxEBAAMAAAAAAAAAAAAAAAAAAREgIf/aAAgBAwEBPxAZ2n//xAAYEQEAAwEAAAAAAAAAAAAAAAABABARIf/aAAgBAgEBPxBe8hjf/8QAHRABAQACAgMBAAAAAAAAAAAAAREAITFBYYGxkf/aAAgBAQABPxAonFLHBbMqmBnP3K635MooysNkDXqTFwCzobZ19mXbs1pL1zgSIHpeU5X7iiofLn//2Q=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"WordPress on Command Line\"\n        title=\"WordPress on the Command Line\"\n        src=\"/static/5d4a00913fd4b094e9d67fdd7f934299/1c72d/wordpress-article.jpg\"\n        srcset=\"/static/5d4a00913fd4b094e9d67fdd7f934299/a80bd/wordpress-article.jpg 148w,\n/static/5d4a00913fd4b094e9d67fdd7f934299/1c91a/wordpress-article.jpg 295w,\n/static/5d4a00913fd4b094e9d67fdd7f934299/1c72d/wordpress-article.jpg 590w,\n/static/5d4a00913fd4b094e9d67fdd7f934299/a8a14/wordpress-article.jpg 885w,\n/static/5d4a00913fd4b094e9d67fdd7f934299/8e1fc/wordpress-article.jpg 900w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<h3><strong>Wordpress, the Command Line, and You</strong></h3>\n<pre><code>“What the hell is a wordpress?” is a question you’re definitely not asking yourself right now if you’ve ever even thought about making a website. Everyone and their mama in the web design world knows about Wordpress. It’s open source, it’s fast and easy, insert-percentage-here of the web runs on it, it’s awesome/terrible/flexible/slow, yadda yadda, etc etc, you’ve heard all of this before.\n\n\n\nWhat about the command line? That’s probably a different story. Far less people know the command line than Wordpress; and probably half of those people that know about it are also intimidated by it. \n\n\n\nDoes that group include you? Do you have no problem installing plugins, customizing themes, or managing Wordpress databases, but get weak in the knees and need to run to the restroom at the thought of typing into that black hole box of potential doom?\n\n\n\nDon’t be afraid :)\n</code></pre>\n<p><strong>The command line offers a million ways for you to speed up, automate, and generally make your workflow and life easier.</strong></p>\n<pre><code>“But I’m a web developer, not a server administrator; why should I learn the command line? Why should I even read the rest of this dumb article?”\n\n\n\nI’m glad you asked. The answer is: WP-CLI. \n\n\n\nShort for WordPress CommandLine Interface, WP-CLI has been developed for years, with Github showing its first release back in 2011, but it hasn’t been receiving the attention it deserves.\n\n\n\nHere’s a quick list of some of the things you can do with WP-CLI:\n</code></pre>\n<blockquote>\n<p><em><strong>Download and install Wordpress</strong></em></p>\n<p><em><strong>Generate or edit a wp-config file</strong></em></p>\n<p><em><strong>(Auto)Update one or multiple Wordpress installations</strong></em></p>\n<p><em><strong>Download, install, and update plugins</strong></em></p>\n<p><em><strong>Delete themes</strong></em></p>\n<p><em><strong>Make website+database backups</strong></em></p>\n<p><em><strong>Debug plugin conflict issues</strong></em></p>\n<p><em><strong>Build custom plugins</strong></em></p>\n<p><em><strong>Run custom php with or without loading Wordpress</strong></em></p>\n<p><em><strong>Run commands remotely to edit Wordpress</strong></em></p>\n<p><em><strong>Batch Update Serialized wp_options Settings</strong></em></p>\n<p><em><strong>Delete Wordpress transients</strong></em></p>\n</blockquote>\n<p>...Basically, anything you can do as an admin on Wordpress in your browser, you can do with WP-CLI, and much much more.</p>\n<p>Most web hosts should offer WP-CLI with their Wordpress hosting package. But in case they don’t, here’s how you can install it and get started, using the recommended Phar build! (if you’re using Composer, you can find instructions here )</p>\n<p><strong>First, make sure your server has some basic requirements. You’ll need to have:</strong></p>\n<p>PHP 5.3.2 or later.</p>\n<p>WordPress 3.4 or later.</p>\n<p>A Unix-like operating system (OS X, Linux, FreeBSD, Cygwin)</p>\n<p>Next, download the WP-CLI.phar file using curl or wget:</p>\n<p><code> curl -O <a href=\"https://raw.githubusercontent.com/WP-CLI/builds/gh-pages/phar/WP-CLI.phar\">https://raw.githubusercontent.com/WP-CLI/builds/gh-pages/phar/WP-CLI.phar</a> </code></p>\n<p><strong>Test it out by running:</strong></p>\n<p><code> php WP-CLI.phar --info </code></p>\n<p>To be able to just type <code>wp</code> the file needs to be in your PATH and executable. Run:</p>\n<p><code> chmod +x WP-CLI.phar </code></p>\n<p><code> sudo mv WP-CLI.phar /usr/local/bin/wp </code></p>\n<p>Now try running <code> wp --info </code></p>\n<p>You should get the same output as the first command we tried.</p>\n<p><strong>To add bash word completion, run:</strong></p>\n<p><code>  wget <a href=\"https://github.com/WP-CLI/WP-CLI/raw/master/utils/wp-completion.bash\">https://github.com/WP-CLI/WP-CLI/raw/master/utils/wp-completion.bash</a></p>\n</code> \n<p>Then add to your user’s bash profile (which can be any variation of .bashrc, .profile, .bash_profile, etc):</p>\n<p><code> source /path/to/wp-completion.bash </code></p>\n<p>Don’t forget to change that to your actual path!</p>\n<p><strong>Lastly, run:</strong></p>\n<p><code> source ~/.profile </code> to get it completions working</p>\n<p>BAM! Wp-cli is now installed* :)</p>\n<p>*In order for you to use WP-CLI without issue, the user you used to install WP-CLI must be the user that owns the root directory and subdirectories of where wordpress is installed, or you must be able to run commands as the user that does. Alternatively, you can do everything as root user; WP-CLI will caution against this, but will allow you to run wp commands by adding --allow-root flag to the end of any of your commands. Be careful!</p>\n<p><strong>Here’s a quick list of some useful commands:</strong></p>\n<p>Download and install the latest version of wordpress. Make sure to change the path to your actual path!</p>\n<p><code>  wp core download --path=/var/www/website_rootdirectory </code></p>\n<p>Create a new WP config file. Change db_name and the path to your desired values. After running this you will be prompted to enter the db password you’d like to use.</p>\n<p><code>  wp config create --dbname=db_name --dbuser=root --prompt=db_pass --path=/path/to/wp_install </code></p>\n<p><strong>Create your database based on your wp-config file</strong></p>\n<p><code> wp db create </code></p>\n<p>Install Wordpress using your wp-config file and your database</p>\n<p><code> wp core install --url=wpdemo.codestaff.io --title=\"WP-Cli Demo\" --admin_user=admin --admin_password=password --admin_email=<a href=\"mailto:codestaff@demo.com\">codestaff@demo.com</a>  </code></p>\n<p><strong>Install a plugin:</strong></p>\n<p><code> wp plugin install plugin_name </code></p>\n<p>You can also search for plugins by replacing “install” with “search” in the above command</p>\n<p><strong>Update all your plugins:</strong></p>\n<p><code> wp plugin update --all  </code></p>\n<p>Load and execute arbitrary PHP code</p>\n<p><code> wp eval-file /path/to/filename </code></p>\n<p>You can add the flag --skip-wordpress to load and execute without loading wordpress</p>\n<p><strong>Activate, deactivate, or check the status of Wordpress’ maintenance mode:</strong></p>\n<p><code> wp maintenance-mode activate</p>\n<p>wp maintenance-mode deactivate</p>\n<p>wp maintenance-mode status</code></p>\n<p>Import an image and set it to be a post’s featured image. Replace the images path, post id and your desired title</p>\n<p><code> wp media import ~/Downloads/image.png --post_id=123 --title=\"my post’s featured picture\" --featured_image </code></p>\n<p>Troubleshoot a frontend plugin issue/conflict without manually disabling all of them! Run the first three commands separately, then run the final one as a bash loop. It will run through and activate each plugin one at a time; from here you can easily find which plugin is causing you trouble</p>\n<p><code> wp plugin deactivate --all </code></p>\n<p><code> wp plugin list --status=inactive --field=name </code></p>\n<p><code> wp plugin list --status=inactive --field=name > pluginlist </code></p>\n<p><code> while read -r PLUGIN; do</p>\n<p>echo \"Activating ${PLUGIN}\"</p>\n<p>wp plugin activate ${PLUGIN}</p>\n<p>read -p \"Press Enter to continue\" &#x3C;/dev/tty</p>\n<p>done &#x3C; pluginlist </code></p>\n<p>That’s just a quick list of some useful commands, we’ll compile a comprehensive list for you to play with soon. You can also check out WP-cli documentation here. What can YOU do with WP-CLI?</p>","frontmatter":{"title":"Wordpress, the Command Line, and You","description":"How to use WordPress on the Command Line 2019. This quick tutorial will show to navigate the Command line on WordPress. ","seotitle":"Wordpress, the Command Line, and You","seodescription":"WordPress can be intimidating on the Command line. ","featuredimage":{"childImageSharp":{"gatsbyImageData":{"layout":"constrained","backgroundColor":"#282868","images":{"fallback":{"src":"/static/c968999ce876a5f7da5886675104a87d/d588e/wordpress.jpg","srcSet":"/static/c968999ce876a5f7da5886675104a87d/9542a/wordpress.jpg 105w,\n/static/c968999ce876a5f7da5886675104a87d/5c446/wordpress.jpg 209w,\n/static/c968999ce876a5f7da5886675104a87d/d588e/wordpress.jpg 418w","sizes":"(min-width: 418px) 418px, 100vw"},"sources":[{"srcSet":"/static/c968999ce876a5f7da5886675104a87d/20fdf/wordpress.webp 105w,\n/static/c968999ce876a5f7da5886675104a87d/48086/wordpress.webp 209w,\n/static/c968999ce876a5f7da5886675104a87d/68e5a/wordpress.webp 418w","type":"image/webp","sizes":"(min-width: 418px) 418px, 100vw"}]},"width":800,"height":800}}}}}},"pageContext":{"slug":"/wordpress-the-command-line-and-you/","previous":{"fields":{"slug":"/how-to-use-install-npm-packages-without-sudo-on-linux-and-macos/"},"frontmatter":{"title":"How to Use Install npm packages without sudo on Linux and MacOS","subtitle":"NPM Packages without SUDO Permissions on Linux and MacOS","featuredpost":true}},"next":{"fields":{"slug":"/reactjs-interview-study-questions/"},"frontmatter":{"title":"ReactJS Interview Study Questions","subtitle":"Nail your ReactJS Interview with this quick Guide for 2019","featuredpost":true}}}},
    "staticQueryHashes": []}