Chcesz poprawić zabezpieczenia twojej witryny WordPress?
Hakerzy mogą wgrać złośliwe oprogramowanie na twoją witrynę internetową, próbując się do niej włamać. Wyłączenie kodu PHP w tych katalogach powstrzyma złośliwe oprogramowanie przed uruchomieniem.
W tym artykule pokażemy, jak wyłączyć wykonywanie PHP w WordPressie za pomocą pliku .htaccess.
Dlaczego warto wyłączyć wykonywanie PHP w niektórych katalogach WordPress?
Domyślnie WordPress umożliwia zapisywanie niektórych katalogów, dzięki czemu Ty i inni autoryzowani użytkownicy Twojej witryny internetowej mogą łatwo przesyłać motywy, wtyczki, obrazki i filmy.
Możliwość ta może być jednak nadużywana, jeśli dostanie się w niepowołane ręce, np. hakerów, którzy mogą wykorzystać ją do przesłania plików dostępu typu backdoor lub złośliwego oprogramowania na twoją witrynę internetową WordPress.
Te złośliwe pliki są często zamaskowane jako pliki rdzeni WordPressa. Są one w większości napisane w PHP i mogą działać w tle, aby uzyskać pełny dostęp do każdego aspektu twojej witryny internetowej.
Brzmi przerażająco, prawda?
Nie martw się. Jest na to prosta poprawka. Wystarczy wyłączyć wykonywanie PHP w niektórych katalogach, w których nie jest ono potrzebne. W ten sposób żadne pliki PHP nie będą uruchamiane wewnątrz tych katalogów.
Przyjrzyjmy się, jak poprawić zabezpieczenia WordPressa poprzez wyłączenie wykonywania PHP za pomocą pliku .htaccess.
Wyłączenie wykonywania PHP w niektórych katalogach WordPress za pomocą pliku .htaccess
Większość witryn WordPress posiada plik .htaccess w katalogu głównym.
Ten potężny plik konfiguracyjny służy do zabezpieczania hasłem obszaru administracyjnego, wyłączania przeglądania katalogów, generowania przyjaznej dla SEO struktury adresów URL i nie tylko.
Domyślnie plik .htaccess znajduje się w katalogu głównym twojej witryny internetowej WordPress, ale możesz także tworzyć i używać dodatkowych plików .htaccess wewnątrz wewnętrznych katalogów WordPress.
Aby zabezpieczyć witrynę internetową przed plikami dostępowymi typu backdoor, należy utworzyć plik .htaccess i przesłać go do katalogów /wp-includes
i /wp-content/uploads
twojej witryny.
Wystarczy utworzyć nowy plik na twoim komputerze za pomocą edytora tekstu, takiego jak Notatnik w systemie Windows lub TextEdit na komputerze Mac. Zapisz plik jako .htaccess i wklej do niego poniższy fragment kodu:
<Files *.php>
deny from all
</Files>
Teraz zapisz plik na twoim komputerze.
Następnie musisz przesłać ten plik do katalogów /wp-includes
i /wp-content/uploads
na twoim serwerze hostingowym WordPress.
Możesz go przesłać za pomocą klienta FTP lub aplikacji Menedżer plików w kokpicie cPanel twojego konta hostingowego.
Po dodaniu pliku .htaccess z powyższym kodem, zatrzyma on wszelkie skrypty PHP przed uruchomieniem w tych katalogach.
Sprawdzanie backdoorów w WordPress przy użyciu Sucuri
Korzystanie z tej sztuczki .htaccess pomaga naprawić zabezpieczenia WordPressa, ale nie poprawi witryny WordPress, która została już zhakowana.
Backdoory są sprytnie zamaskowane i mogą być ukryte na widoku.
Jeśli chcesz sprawdzić ewentualne backdoory na twojej witrynie internetowej, musisz włączyć na niej Sucuri.
Sucuri to najlepsza wtyczka do zabezpieczeń WordPress na rynku. Skanuje twoją witrynę internetową pod kątem możliwych zagrożeń, podejrzanego kodu, złośliwego oprogramowania i luk w zabezpieczeniach.
Skutecznie blokuje również większość prób włamań nawet przed dotarciem do twojej witryny internetowej, dodając zaporę między twoją witryną a podejrzanym ruchem.
Co najważniejsze, jeśli twoja witryna WordPress zostanie zhakowana, Sucuri wyczyści ją za ciebie. Aby dowiedzieć się więcej, możesz przeczytać naszą recenzję Sucuri, ponieważ korzystamy z ich usług od lat.
Możesz dowiedzieć się więcej z naszego przewodnika na temat znajdowania i poprawiania backdoorów w zhakowanej witrynie WordPress.
Przewodniki ekspertów na temat poprawy zabezpieczeń WordPressa
Teraz, gdy już wiesz, jak poprawić bezpieczeństwo twojego WordPressa poprzez wyłączenie wykonywania PHP w niektórych katalogach, możesz chcieć poznać inne techniki zabezpieczeń.
Oto niektóre z naszych najlepszych przewodników na temat poprawy zabezpieczeń WordPress:
- Najlepszy przewodnik po zabezpieczeniach WordPressa (krok po kroku)
- Jak przeprowadzić audyt zabezpieczeń WordPress (kompletna lista kontrolna)
- Jak przeskanować twoją witrynę WordPress pod kątem potencjalnie złośliwego kodu?
- Najlepsze skanery zabezpieczeń WordPress do wykrywania złośliwego oprogramowania i hacków
- Jak dodać uwierzytelnianie dwuskładnikowe w WordPress (darmowa metoda)
- Jak dodać pytania dotyczące zabezpieczeń do ekranu logowania WordPress
- Co, dlaczego i jak działają klucze zabezpieczeń WordPressa?
Mamy nadzieję, że ten artykuł pomógł ci dowiedzieć się, jak wyłączyć wykonywanie PHP w niektórych katalogach WordPress w celu zabezpieczenia twojej witryny internetowej. Możesz również dowiedzieć się, jak utworzyć darmowy biznesowy adres e-mail lub zapoznać się z naszymi typami wtyczek WordPress, które są niezbędne do rozwoju Twojej witryny.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
Syed Balkhi says
Hey WPBeginner readers,
Did you know you can win exciting prizes by commenting on WPBeginner?
Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
You can get more details about the contest from here.
Start sharing your thoughts below to stand a chance to win!
Mrteesurez says
I see this as a great form of securing a website by disabling PHP execution in folders. According to this article, only two directories are secured, what of others ? Have they secured naturally or hackers don’t need it during the attempt ?
WPBeginner Support says
Other sections of your site’s files normally require stricter access or have php files that are required to work for your site to work.
Administrator
Jiří Vaněk says
Thanks for these safety tips. I have created an htaccess file and will upload it to FTP. I have a website on my own server, so the question of security is entirely up to me. Thanks for the next step in making my WordPress a little more secure again.
Unarine Leo Netshifhefhe says
I also have this alert on my Updraft plugin where backups are not happening can this be due to htaccess?
„Backup directory could not be created…
The folder exists, but your webserver does not have permission to write to it. You will need to consult with your web hosting provider to find out how to set permissions for a WordPress plugin to write to the directory. (wp-content/updraft)”
WPBeginner Support says
That looks to be a file/folder permissions issue, you would want to reach out to your hosting provider and they can help, you can also take a look at our guide below:
https://www.wpbeginner.com/beginners-guide/how-to-fix-file-and-folder-permissions-error-in-wordpress/
Administrator
Brian Prom says
FYI: you have a typo in your code snippet for the .htaccess snippet.
Using your code snippet as is (without the closing /) breaks image loading.
WPBeginner Support says
Thank you for pointing that out, our code should be fixed
Administrator
Vitor Gonçlaves says
I’ve found some .php files in the uploads folder created by plugins. Can I assume this won’t cause a problem, or do I have to analyse each plugin individually?
WPBeginner Support says
If you reach out to your plugins they can let you know the specifics for those files.
Administrator
nirbo says
Thanks for the information
WPBeginner Support says
You’re welcome
Administrator
cliff denney says
thank you very much
WPBeginner Support says
You’re welcome
Administrator
Suman Samanta says
Great writing! You have a flair for informational writing. Your content has impressed me beyond words. I have a lot of admiration for your writing. Thank you for all your valuable input on this topic.
WPBeginner Support says
Thank you, glad you enjoy our writing
Administrator
Thato says
Guys i think i have messed up my htaccess file, my website is completely not displaying images
WPBeginner Support says
Hey Thato,
You can download your .htaccess file to your computer as a backup and then delete it from your website. Go to WordPress admin area Settings » Permalinks and click on the save changes button. This should regenerate your .htaccess file.
Administrator
Shawn Rebelo says
Do not do wp-content.
Do wp-content/uploads.
And this:
order allow,deny
deny from all
May very on servers.
Hardik says
Does it affect the uploads file to upload on webpages?
I found that after uploading this htaccess file to the folder many of images from many posts are not displaying.
Chuck Cochems says
Yeah, denying access to php files in the includes directory breaks the site because including actually obeys .htaccess restrictions.
But the restriction on the uploads directory is very smart, and this should be there .BY DEFAULT in the uploads directory, and there’s no good reason for it not to be present.
Stan says
What’s the method for IIS servers?
Thanks,
KOnnie says
ZOMG! can’t you just disable write access to /wp-includes folder?
Why fight with consequences when you can prevent the cause?
Jonathan Hodgson says
Wouldn’t this stop wordpresss being able to update the files in core updates?
Jeff Wigal says
You can also put this in your Apache virtualhost, which will accomplish the same thing:
Order allow,deny
Deny from all
anton says
how to implement this code if we have combination of lower case and upper case on file extention for example on.php on my website its work but it s not working if the file named with.PHp ,.PHP .PhP or combination of them,the backdoor script still executed
Thank you
Timothée Moulin says
You can put this in your .htaccess file
Order Deny,Allow
Deny from All
Shams says
Hi Syed,
Thanks for such an informative post and in fact it provides a great solution for saving WordPress from hackers.
Vladimir says
Hi!
I followed all your instructions in this article, but Its not working…
Thanks
Aurélien Debord says
A so useful post with such good and quick tips.
Thanks
Ramon says
I created an .htaccess file in the wp-includes folder. Site looked oke but my WYSIWYG editor in the admin pages wasn’t working. Had to remove the .htaccess file again. (WP 3.9.1)
Wes says
I also found my wp-includes folder full of php files and I can’t see how using that .htaccess file in there wouldn’t break something. I did use it in the uploads dir.
Editorial Staff says
It does break it sometimes (depending on the plugin you are using), but not all the time.
Administrator
Red says
forgive my bad english…
i followed all your instructions in this article, but when i go my dashboard to add a newpost, my post section was messed up. … i suspect the .htaccess was the problem.
when i deleted it, the post was fine.
Editorial Staff says
Which directory did you upload the .htaccess file that caused this issue?
Administrator
Chris says
I added the .htaccess file to my wp-includes and didn’t have any problems. Thanks a lot of the tips.
Brad says
I tried this in my /wp-includes/ directory, which is full of php files. Of course I could no longer access the site. Did you really mean to include the includes directory for use with the .htaccess file?
Did you maybe mean /wp-includes/images ?
Editorial Staff says
Nope. We meant /wp-includes/ folder. We have this on our wp-includes folder. If for some reason it is breaking your site, then delete the .htaccess file from your wp-includes folder.
Administrator
Brad says
Strange, my wp-includes folder has over 90 php files in it. And it does break the site. I took it back out immediately.
But I did put it in the /wp-content/uploads/ folder and its works just fine there. Thanks for responding
Alfred says
Putting an htaccess file denying access to php files in a directory full of php files does seem rather odd. I assume it’s because these files are normally only included, not executed directly. If that’s true, wouldn’t it be better to just deny access to the entire directory?