Skip to content

Instantly share code, notes, and snippets.

@akkys77
Last active January 5, 2018 18:12
Show Gist options
  • Save akkys77/4e1046739b37fb3ac0474464aaaef117 to your computer and use it in GitHub Desktop.
Save akkys77/4e1046739b37fb3ac0474464aaaef117 to your computer and use it in GitHub Desktop.
Setup WordPress wp cli to avoid linux permission issues between cli and browser
  1. Assign Wordpress (/var/www/wordpress) folder to web server user (www-data)

    sudo chown -R www-data:www-data /var/www/wordpress
  2. Find your wp-cli installation

    which wp
  3. Add user (mylinuxuser) to visudo with web server user permissions (www-data)

    3.1 Open visudo

    sudo visudo

    3.2 Specify the permissions you want to give to your user by adding the following line

    mylinuxuser ALL=(www-data) NOPASSWD: /usr/local/bin/wp
  4. Create an alias so that wp cli always uses web server credentials

    4.1 Open your bash_aliases file

    nano ~/.bash_aliases

    4.2 Create an alias for wp so that it always executes with web server user by adding the following line

    alias wp="sudo -u www-data wp"
  5. Enjoy seamless wp updates from cli and web browser.

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