Reset File Permissions with PHP

Recently I transferred a WP – WordPress site and I was getting server response 500.

Looking at the error log in cPanel I could see that WordPress was complaining about files being globally writable.

So pretty much the whole site was down after being transfered, I’m not sure why it happened with this site since my other site transfered just fine without any issues, maybe it has a different version of wordpress?  But I feel like it would have to be how I compressed and extracted the zip of the site?

I found a solution on Dan Massey’s blog: http://blog.danmassey.net/?p=391
Unfortunately hostgator is having a melt down right now and delivering automated responses for their support, so they wont fix my SSH issue right now : (.

# cd /web_site_root
# find ./ -type d -exec chmod 755 {} \;
# find ./ -type f -exec chmod 644 {} \;

So I had to take things into my own hands.  I was actually afraid how long it would take to do this to a WordPress install because WordPress is constructed of so many files that would make any FTP transfer get on its knees and cry.  Amazingly this process is extremely quick.  This works great for resetting a web server’s default file permissions to all files and folders recursively.

foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.')) as $filename)
{
if (is_dir($filename))
chmod($filename, 0755);
else
chmod($filename, 0644);
}
echo "Directory and File Permissions Reset";

This entry was posted in Interesting Finds and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Leave your thoughts...

You must be logged in to post a comment.