I can’t update or install WordPress plugins on localhost
I remember like once, when I just began work with WordPress on localhost, I was try install plugin and are failed, since system demanded put login, password and address of FTP server. Of course, I didn’t know this data, but to seek a solution, I haven’t had time. Since then, I never got my head round it and install plugins by manual. As time went I was need update WordPress, WooCommerce and more about dozen plugins of a project, that was install on localhost and I at once got motivation to make updating simple click “Update” button. I offer 2 way solutions of the problem, each of them checked for WordPress, that work on XAMPP.
How install/update plugins or WordPress on localhost (first way)
- Open wp-config.php and put this code:
define('FS_METHOD', 'direct'); - Change owner or group folder of the project (more info about this you can read in description of the second way, paragraph 2.4.)
How install/update plugins or WordPress on localhost (second way)
- Open file settings ProFTP server (that by default used in XAMPP):
/opt/lampp/etc/proftpd.conf - Find user/group, that use XAMPP (find string "User daemon" or "Group daemon"):
# Set the user and group that the server normally runs at.
User daemon - this is user name
#Group daemon - group by default commented, you can use it, then you could uncommented it - Find password of user (find next strings):
# daemon gets the password "xampp"
# commented out by xampp security
UserPassword daemon 2TgjxA8g179G9c - this is password. By default used password "xampp", better replace on your custom password e.g: 2TgjxA8g179G9c - Change owner or group of folder project. For example:
sudo chown daemon: -R project_folder - If change owner
sudo chown :daemon -R project_folder - If change group
sudo chown daemon:daemon -R project_folder - If change owner and group, usually enough change one thing. - Input data in field, that require Wordpress:
Host: localhost
User: daemon
Password: xampp
Some problems and their solutions
Wordpress by default has such access permissions: 755 for folders and 644 for files. It mean, that after change owner you can't edit any files, and only view.
Solutions #1: Change owner of the project folder, do update and to back out previous owner.
Solutions #2: Add current user to ProFTPD group. This way not as good as previous, because is implies change default permissions for file and folders of WordPress. In the end of develop, you can forget to change access permissions, so be vigilant used it! So, at the start need add your current Linux user inProFTPD group.
- Uncomment the line "#Group daemon" here /opt/lampp/etc/proftpd.conf
- Add current Linux user in group of daemon. Input next commands to the terminal:
id //check all groups of current user
sudo usermod -a -G daemon username //where "username" is current Linux user
id - Change permissions:
find . -type d -exec chmod 775 {} + //change access permissions for folders
find . -type f -exec chmod 664 {} + //change access permissions for files - Attention!!! After end of the project, need change access permissions on recommended WordPress Codex:
find . -type d -exec chmod 755 {} +
find . -type f -exec chmod 644 {} +
Sources: