When creating WordPress websites I like to do so locally (e.g. XAMPP). Working locally has allot of advantages like faster load speed, being able to load the entire project in the IDE of your choice (code suggestion for your entire project) and the ability to use versioning software (like SVN and GIT). The only problem I had was not being able to install plugins from within the plugin backend page.
Searching through the plugin repository works fine but when you try to install a plugin you’re asked to enter FTP credentials to proceed (the ‘Connection Information’ screen). And because we’re working locally, it’s most likely that we don’t have FTP access to our local server.
Of course you can download the plugin from the wordpress.org online repository and then copy the files to your local plugin directory, but you don’t have to! We can simply add the following code to our wp-config.php to let WordPress use a different filesystem method than FTP.
define('FS_METHOD', 'direct');
Setting the ‘FS_METHOD’ to ‘direct’ will also allow you to update WordPress Core and install themes from the theme repository locally. I’d love to know if this helped you or if you have a question, so please leave a comment below.
Can’t remember where I found this, but this works for me too:
if(is_admin()) {
add_filter(‘filesystem_method’, create_function(‘$a’, ‘return “direct”;’ ));
define( ‘FS_CHMOD_DIR’, 0751 );
}
What file should I open and add this code you referred?
Thanks
What file?
I think Warren is talking about your theme’s functions.php
I’ve optimized his snippet a little bit:
if ( is_admin() ) {
add_filter( 'filesystem_method', create_function( '$a', 'return "direct";' ) );
if ( ! defined( 'FS_CHMOD_DIR' ) ) {
define( 'FS_CHMOD_DIR', 0751 );
}
}
wp-config.php in WordPress installation folder.
I think you should go to C:program file/xampp/htdocs/wp and edit or add the code by means of text editor. That is open wp-config.php and add or edit.
Excelente, me sirvió perfectamente. Muchas gracias (:
Amazing, this works for me. Thanks a lot Man. God bless you more.
Perfect!
thanks it helpd me
That’s great to hear!
Thank You.
adding define(‘FS_METHOD’, ‘direct’); works..!!!!
THANK YOU!
I also get this problems but now problem solved thanks for sharing
Thank you so much, you helped me to solve the Problem to 🙂
This is a great solution. Thanks.
Hi,
I entered the line of code exactly as you said in the wp-config.php file underneath the other “defines” but when I go to download a plugin, instead of being asked for FTP credentials (as I did previously), I now get this message:
Installing Plugin: Advanced YouTube Embed With Google Analytics -like Stats, by Embed Plus 2.6
Downloading install package from http://downloads.wordpress.org/plugin/embedplus-for-wordpress.2.6.zip…
Unpacking the package…
Could not create directory. /Users/RichM/Sites/wordpress/wp-content/upgrade
Return to Plugin Installer
Do you know how I can fix this!?!? Thanks!!
i think its cause of your folder permissions. Set them all to 777 and you wont get this error again
looks like this is the root of the entire problem, if the folder permissions are correct in the first place then the configuration change is not needed on my install
thanx!!!
Plz, never ever put the file permissions on 777, this will make it accessible to the public. Make sure the user (who runs the apache service) has the read/write permissions on the wp-content folder.
you may also chown to your apache account :
chown www-data:www-data -R you_publishing_directory
Hi, thanks Baobab33. It worked for me.
I just typed
chown www-data:www-data -R /var/www/html
which is the default publishing directory for your server on ubuntu.
Update on this:
In terminal I changed the privileges for the wp-content folder and the plugins folder to 777. Plugins now install perfectly.
That works perfectly. Other approaches are all failed. Showed me the error cannot create a directory…
wordpress at localhost install plugin Failed to connect to FTP Server
thanks Richard that Did the trick for me to!
Yes. Finially. So many bad suggestions out there… You are the best, thanks!
Thanks a looooot
Thanks a ton for sharing this info .
I tried to change all defines() in my wp-config.php and when I back to my local wordpress, appears a page saying: “Error to connect the database…. It means that the user and password informations in your wp-config.php are incorrects”.
What, exactly I have to do?
Thank you for your attention guys.
You shouldn’t change all defines() in your wp-config, simply add define(‘FS_METHOD’, ‘direct’);
I did’t work :-(((
I have tried this and it’s still not working
Thanks for the easyfix!
This worked great, Barry. Thank you.
Thanks for the tip Barry, it worked beautifully.
THANKS.. wonderful solution!
thanks a lot..
Find the wp-config.php in word press folder
Put this at the bottom of the code.
define(‘FS_METHOD’, ‘direct’);
/* Allows for wordpress plugins to work on localhost */
Then open your terminal and navigate to your worpress content folder site.
Mine is:
cd Sites/wordpress/wp-content
Once there type in this code and plugins should work fine
chmod -R 777 plugins
For those of you that are frightened at the thought of using terminal, you can also navigate to your directory through finder and change the files manually to read & write in the wp-content folder.
You must first change wp-content, then “plugins”, “themes”, and there’s one more in there I can’t remember. Hope this helps!
Hi, I am a total WordPress beginner and also have the problems installing the plugins on my localhost. I already tried all your advices but absolutely don´t know where and how to change the permissions. I work on an apple system with XAMPP. Can you help me please!
How do i get to my terminal
Muchísimas gracias, muy útil tu información. Me sacó de apuros!.
After one hundred incorrect suggestions, yours worked. Thanks man!
Barry, this was such an elegant fix—thank you!
Hi Barry (and others who may want to post the fix).
When I add this line to the wp config file I no longer get the option to install or delete plugins. All I can do is active the plugins that are already installed.
Is there a work around for this, or have I done something else wrong?
this is THE BEST solution ever. thanks a many lott . .:)
Thanks for this,
I also get the error:
Could not create directory.
when updating Core or plugins.
Im not happy about changing permissions to 777 as I dont want my wordpress installation to become a spam hijacked site.
Any ideas? 755 even has issues
this solution is for a localhost install. So no spam or hacking.
Thank you so much , very helpful article.
Thanks a lot!!!!!
I lost an awful lot of time in search of a solution, and your suggestion worked just fine.
Thanks a lot! Worked like a charm 😉
I just have one question though. Do I have to remove/comment this line in wp-config.php file when I move the wordpress installation to external server (not localhost anymore)?
I would recommend you to do so, yes.
Thank you for share a nice Tips with us. It works perfectly!
Awesome!!! i’ve been looking the solution to this problem for hours!!!
Thanks a lot!!
Thanks for sharing this, highly appreciated!
Thanks a lot Barry…. this totally helped me out… I was about to do a manual installation.. 🙂
after putting in that line in wp-config and changing the permissions, i still can’t install plugins. it says it can’t create the directory. any help would be appreciated.
EDIT: i just manually put the plugin into the directory. but if someone can still fix my issue that’d be great. thanks.
Thanks man 😛
Thanks alot! Just what I was lookin for.
Thanks a lot Barry, it perfectly works on my localhost wordpress 🙂
Hi Barry. When we want to transfer the local site back to the live site after using this method,
I’m guessing we need to remove define(‘FS_METHOD’, ‘direct’); correct?
Does anything else need to be done to the wp.config file to make the live environment work properly?
Yes, remove the
define(‘FS_METHOD’, ‘direct’);
on the live website.Set WP_DEBUG to false 🙂
Hi Barry,
I run wp with wamp on localhost, i get these error when i try to install wootique and woocommerce plugin:
Fatal error: call to a member fuction get_cart_url on a non-object in c:\wamp\www\mysite .. On line 197 call stack
***
I ve searched forunms for solution to no avail, please kindly help out with a solution. Thanks
Thank you. You saved me many hours of time!
Thanks a lot !
so this issue showed up for me after moving my install to a diff DIR
after making the change you recommended i was faced with the permissions error as well. This made me realise that the FTP prompt was not because of the missing setting but because of the folder permissions. removed the setting you recommended and the corrected the folder permissions for the plug in dir and TADA all working as expected.
Thanks for taking the time to post this though as it did get me on the right path!
Terimakasih banyak atas solusinya 🙂
(thanks very much)
I LOVE YOU Man 😀 Perfectly Solved The Issue !!!!
Man, i love you!!!,
So thank you !! 🙂
Great fix, thank you !!!! It was getting really annoying to have to download unpack and copy every theme and plugin.
Worked for me. 🙂
Hi Barry,
I am a noob in wordpress and recently i am developing a site in wordpress which needs a gallery, however when i try to download the jetpack plugin i get this error: ” Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\wordpress\wp-includes\class-http.php on line 1589″
Please help!
Thanks!
Thanks a lot man!
awsome post very helpful
thank u very much.
Just…
i. Open the wp-config.php files
ii. copy & paste line: define(‘FS_METHOD’, ‘direct’);
Fixed! 🙂
Where exactly do you need to paste this code?
Now it says “Could not create directory.”
Thank you!
thank you so much barry. i had being looking for the solution a couple of days now.
Thank you Barry!
I was getting one trouble after another using several sites with xampp on mac, because wordpress wouldn’t install plugins and themes, when I did it manually some of them wouldn’t be recognized.
Great help, thanks again.
Hello 🙂 I am trying to install the plugins but I am unable to do so. I plugged in the code and now I am getting the error message that some people seem to be getting also.
I do not understand how to do the 777 code on the terminal, do you mind walking me through on how to do that please?
I need to build this site offline because there’s one currently live already.
Thank you in advance!
Hi Lorena, you know what..
i almost 4 hours try to find how can i understand “777 code on terminal”..
i hope this is work for u :
go to terminal and type this
chmod -R 777 /Applications/XAMPP/htdocs/
this is work for me
Thank you so much buddy. This is the ONLY solution that worked for me!!
Thanks dude!
Just found your post and was immensely helpful! Just a flag to errbody though — don’t leave your permissions at 777!! Major security issue. Set back to 755 after you’ve downloaded your plugins.
Thank you!!
And never do this at live servers! This is just for local host!
Dude, You’re a genius! Thanks for sharing.
<>
Very thanks this article solve my problem
Thanks, Worked 🙂
Hey a BIG THANK YOU for making my life easier!
Many thanks, very useful, worked for me fine.
Thanks your solution helped!
had the same problem
Great solution! Thanks 😉
Dude.
You rock.
Thanks a million for saving me a bundle of time.
You’re very welcome! 🙂
This was very useful!
I use my home server for testing and staging. This made everything easier.
Glad to hear I could help!
Thanks bro! It works really well!
But i have another problem, after it pass that page.
All the installation of the plugin become failed.
Do you have any idea why?
Sounds like a permission issue. Try changing the file/dir right to 777 on your local system. Remember to not do this on your live website!
Great – thanks very much! Worked a treat
i cant change permission to 777
also the server says it has SuExec
Exactly what I was looking for, thank you sir.
My problem has been solved, thank’s bro.
Cheers!! Jobs a a good’n!!
It’s not good 4 me…
chmod: Unable to change file mode on /Applications/XAMPP/htdocs/: Operation not permitted
what should I do?
Beautiful. Thank you so much!
Thank you so much!
Thanks. It worked for me.
it’s not work using wordpress 4.4.1
Excelent !!!
This is my version of this fix. Just ensuring that noone takes advantage of this unless they are administrators.
if(is_admin()) {
define(‘FS_METHOD’, ‘direct’);
}
Worked like a charm 🙂
Thank you SO much!
Spent weeks looking for this answer!
Much love <3
I had to change the owner/group owner of the files on my site for this to work (it gave me the error message ‘cannot create directory’ and I spent a lot of time searching for this solution).
In a terminal, enter:
cd insert_pathname/insert_sitename
Then enter:
sudo chown -R www-data:www-data *
You will need to enter your password.
In case you don’t know what you just did:
First line:
cd = move directory
insert_pathname = where your site is stored locally
/ = separator
insert_sitename = name of your site
Second line:
sudo = grant super user permission
chown = change the file ownership
-R = go through all sub directories
www-data = change owner
: = separator
www-data = change group ownership
* : act on all files
‘www-data’ will allow wordpress to make directories and amend files.
Hopefully that will help others!
Actually you don’t need to enter your sitename thinking about it, so the first line wold be:
cd insert_pathname/
Oh and make sure you do actually change directory (first line) before doing the second line as that will mess up the directory you are in, trust me I know this from experience!
Just started with WordPress today on localhost and immediately ran into this problem.
Thanks for sharing.
Rob.
This is also possible if they offer SEO as part of their service.
A dedicated rented machine can be rented for operating complex web applications and for the multiple sites interconnected to your business.
There are thousands of web-hosting service providers and all of them
claim to be the best.
Awesome! Worked perfectly fine. Although had to chown to _www (I’m on a Mac)
Thanks
thanks just what i needed worked perfectly
Thanks its great
Thanks! It worked.
Thanks, it did helped.
ok terimakasih, berhasil
What’s up to every one, for the reason that I am genuinely eager of reading this webpage’s post to be updated regularly.
It includes pleasant material.
I uploaded free theme from internet to my localhost and i want to upload its plugins and i face this problem,
“Warning: an unexprected error occured. something may wrong with wordpress.org or the this server’s configuration. if your continue to have problems, please try the support forums (wordpress could not establish a secure connection to wordpress.org Please contact your server administrator.) in C:\xampp\htdocs\wordpress\wp-admin\includes\plugin-install.php on line 158.
something went wrong with the plugin APl. “
I uploaded free theme from internet to my localhost and i want to upload its plugins and i face this problem,
“Warning: an unexprected error occured. something may wrong with wordpress.org or the this server’s configuration. if your continue to have problems, please try the support forums (wordpress could not establish a secure connection to wordpress.org Please contact your server administrator.) in C:\xampp\htdocs\wordpress\wp-admin\includes\plugin-install.php on line 158.
something went wrong with the plugin APl. “
Thanks for the tip Barry.
Yep Still helpful 3+ years on, a real novice might struggle to find the location of the file to edit… this is where i found it in mine:
C:\xampp\apps\wordpress\htdocs\wpconfig.php
opened with notepad:
added the following line, so I know what it is in the future:
//** File system Setting – adding the following changes the file system from ftp to direct for local hosts */
define(‘FS_METHOD’, ‘direct’);
But ultimately without your tip Barry Kooij I’d have been scratching my head for weeks so thank you
Amazing issues here. I am very satisfied
to see your post. Thanks so much and I am taking a look ahead to touch you.
Will you kindly drop me a e-mail?
Hi it’s still not work for me it appears like this :
Downloading install package from https://downloads.wordpress.org/plugin/bootstrap-shortcodes.3.4.0.zip…
Unpacking the package…
Could not create directory.
Anyone come up with solution? Thanks before
Thank for you useful solution!
Loving the info on this web site, you have done outstanding job on the posts.
Nice. its working
Glad to hear it is!
Worked. Thank you.
Awesome!
Worked here.
upgraded to wordpress 4.6.1 using ubuntu 16.04 desktop version.
just check if site folder have the right owner and permissions
sudo chown www-data:www-data /path/to/folder
sudo chmod g+w /path/to/folder
That’s great to hear and thanks for sharing the extra info!
Thank you Berry 🙂 🙂
Worked perfectly thank you!
Awesome!
You’re very welcome! 🙂
I have already installed plugins on localhost. Thanks for help!
That’s great to hear!
helps me everybody
i have a bootstrap to wordpress converted but can’t install any plugin what can do that
if need bootstrap portfolio web site go the blew link
thx bud. works out of the box, so to speak.
kinda ridiculous that WP wouldn’t address this in documentation, as most developers would work on localhost environment prior to uploading to FTP.
yours is a save in the bottom of the ninth.
nice going. thanks again.
I think this is one of the most important info for me. And i’m glad reading your article.
But should remark on few general things, The site style is ideal, the articles is really great :
D. Good job, cheers
Frustated for a couple hours. And try that’s code. It’s work.
Thanks for make my life easier.
🙂
perfecto !
Thank you so much Barry!
Everything works now thanks to your codeline in wp-config, plus I spend a lot of time trial and error giving maps write and read permissions manually.
The 777 thing I just dont understand… Which terminal, thing are people talking about??
I’m working on MacOSX version 10.6.4
If I create another database and install another wp installation in the future, is there a written rule what to do about the read and write permissions to maps? E.g. if client-map in htdocs has permissions for write and read will maps inside this map copy those privileges?
ps. love the dutch design of https://2016.netherlands.wordcamp.org
beautifully done!!
works for me too. Thanks Barry
Man that’s just groovy…THANKS A LOT, works like its charmed….
My “cannot copy …” error was due to a too long pathfile. Since modified path, it woroked. If it helps someone …
still i got this while download plugin
Installation failed: Download failed. No working transports found
Pretty cool. Thanks!
Worked for me too!!!
Thanks a lot..
I also get this problems but now problem solved
Thanks for Sharing
Worked perfectly for me.
Thanks very much
Good post, keep
No I I Did What U Reffer But I Still Getting (Internal Sever Error) Can u plzz Tell Me How To Fix This Error
Thank you so much, it really helps me!!!
Yep this made my life a little easier!
Maybe it’s good to mention where the php file is found and that you need to reload the admin page before it works.
Thanks 🙂
Helpful thanks
Hi, on occasion I get a 503 server message when I browse this site. Just a heads up, best wishes
Haven’t worked on WordPress for years, and this always annoyed me – was fine doing it from the command line, but this is just easier.
Thanks.
Tks.
thanks
thanks
I works for me!
Reply
Worked for me. Thanks a lot.
It Works.Thanks…
Oh my! Bless you! Every time I updated my plugins I got stuck during the process and just every once in a while it worked.
Adding this one line of code fixed the problem straight away! Thanks!
Happy to help!
When I originally commented I seem to have clicked on the -Notify
me when new comments are added- checkbox and from now on each time a comment is added I
get 4 emails with the same comment. There has to
be a way you can remove me from that service? Thank you!
Hey,
Please send me an email via the contact form here with the email address you’ve used with your original comment: https://www.never5.com/
Kind Regards,
Barry Kooij
Thanks a lot mate
Awesome. Thank you.
THANK YOU!!!! WORKED GREAT!
Thank’s,
For me, setting maximum execution time in php.ini helped solve the problem (initially it was set to just 30s):
max_execution_time = 120
First I got 500 Internal Server Error, but then I went to this link to see full install log and saw that max exec time was making problems:
/wp-admin/update.php?action=install-plugin&plugin=woocommerce&_wpnonce=e81b39b916
Hope it helps someone!
holy crap. it’s working for me. i have honestly considered going back to windows (now using mac) because i couldn’t get this to work, and on windows xampp this is all automatically done. wow. thanks a lot.
Works for me.
thanks
Excellent! Thanks!
Sometimes things in the comments or in the article work.. but if don’t.. then just give it what it asks for 🙂 localhost/ root/ empty password .
Thanks, work perfectly.
Thanks a lot.
I fount the solution! And of course it works like a charm!
1. Open Terminal and type: sudo nano /etc/hosts
2. Enter your Mac’s password
3. Add following line to your hosts file: 198.143.164.251 api.wordpress.org
4. Save your hosts file and restart MAMP servers.
Thanks .. worked perfectly
Thanks it really helped me!
Thank You Barry for sharing this awesome article, for a long time I was using shared hosting and this article helped me when there’s any problem while installing WordPress, so far, I have now moved to managed WordPress and using their console to install everything, but still I am hosting some blogs on shared hosting get help from this post written by you.
Thanks a lot! this works for my mac localhost
Barry, good job done!
Thanks
Thanks! It worked for me Barry
Great. Helped me a lot. It just works.
THANKS.. wonderful solution!
great! the quickest help with config I’ve ever had 😀 thanks a lot!
Thank you it works
Thanks!! It works!
Awesome issues here. I am very glad to see your post.
Thank you so much and I am having a look ahead to contact you.
Will you kindly drop me a e-mail?
This is what i am looking for. very helpful.
Thanks it works.
Thanks for informatios, its very helping.
An intriguing discussion is worth comment. I do believe that you should publish more
about this issue, it might not be a taboo matter but generally
folks don’t speak about such issues. To the next! Kind regards!!
Thanks for sharing this blog. I am curious about how can I install plugins. Now I can try with your support so that may be I do not get any error while adding.
Amazing! Thank’s!
Finally find a working method to fix plugins install issue! Thanks.
Hello! I just wanted to ask you where exactly should I place the recommended code. I’m a complete beginner in this and when I simply added it at the end of the file, it reported a mistake.
Thanks in advance!
in the top will be ok
Thank you
Bro you saved me its works like superman and batman too
thanks even it’s from 2013 its saved us
Funcionó perfectamente GRACIAS! Thank you 🙂
Master, I have a request from you: How can I remove or change the permanent link of this plugin in Page Tag Cloud? Please help me.
Great content! Super high-quality! Keep it up!