Blog

4 common WordPress problems and how to solve them

Oftentimes as a WordPress developer going through the development process, you run into slight setbacks; small problems that you know shouldn’t be an issue but you don’t know how to solve quickly. Let’s have a look at a few such problems specific to new WordPress installations and see some of the ways you can solve them. The solutions here are best suited for novice to mid-level PHP developers.

.htaccess file

This is a file often found on the root directory of your website, which is the directory with your wp-config.php file. The purpose of this file is to apply folder specific configurations for the web server serving your website.

In WordPress, this file is used to regulate general user access to WordPress system files because users should not be able to browse sensitive files through their browser. Unfortunately, this means that a misconfigured or corrupted .htaccess file could cause the site not to load properly or give the infamous Fatal Error 500 code. A common cause of misconfiguration is when a developer moves the site from a local development environment to a production environment, or when the developer changes the folder in which the site is served from. Plugins and other third party software can also lead to corrupted .htaccess files.

A reliable solution can be found on the official WordPress site https://codex.wordpress.org/htaccess. Clearing the contents of the .htaccess file and replacing them with the following will restore the file to its basic state.

# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Take note that the ‘RewriteBase /’ line assumes that your website sits on the web server’s root, that’s to say, your website is not being served from a folder in that root. As an example, if your website files are sitting in a folder that’s in your public_html (common server root) folder and are being accessed like so: www.yoursite.com/folder, then that would have to change to ‘RewriteBase /folder’, same goes for ‘RewriteRule . /folder/index.php [L]’.

Permalinks or ‘404 page not found’

Permalinks are the convenient URL’s that link to your content on your WordPress site. Developers often face problems when they move from a local development environment to a production environment or when they change the folder from which the project is served from. Clicking on content links like posts, tag and categories leads to ‘404 not found’ error messages.

This happens because WordPress saves the web path to your website’s root in the database when you initially install it. The easiest way to change this is to open up phpmyadmin > open the wordpress database > open the wp_options table and change the ‘option_value’ on the site url row as well as the home row. Replace that value with your current web path.

Upload File Size

WordPress sets it’s file upload size according to the PHP settings on your web server. There are a number of ways to change this but we’ll look at the easiest and that is changing the PHP settings in your php.ini file. Finding the php.ini is a bit tricky as it depends on what kind of server environment you have.

If you’re hosting your WordPress site on a shared server then in most cases you’ll have to talk to support to get information on accessing the file. On the other hand if you’re hosting on a VPS and have SSH access then you can locate your php.ini file fairly easily.

To locate the php.in file, create a file in your web server root and name in findini.php. In the file paste this code and save.

<?php echo phpinfo();?>

Using a browser, navigate to www.yoursite.com/findini.php and you should see a page with details about your version of PHP. The path that you’re looking for is the one referenced by the section Loaded Configuration File. Open that file and edit the values for the lines – memory_limit, post_max_size and upload_max_filesize. The values you put there are up to you however, they should be in that order from biggest to smallest. 1 megabyte = 1M. Restart Apache and all should be in order with file uploads.

Unable to create directory error

This is another common problem after having moved to a development environment of having changed project directories. This problem is caused by an operating system’s users and permissions. A web server like apache runs its operations on the operating system as a specific user with certain permissions. As such, when a change in environment happens it’s common for these permissions to be mismatched.

The solution to this problem might be slightly different for those who are hosting their WordPress site on a shared server because they might not have access to the command line to effect some of the changes required. Shared server users might have to contact support to change anything more than file permissions. File permissions can be changed via an FTP client like Filezilla.

To fix this problem there has to be a change of file ownership as well as file permissions. To do this, log into the server via SSH. Navigate to the root of the website and enter these commands, you’ll need root access to carry these out however:

sudo chown -R www-data:www-data wp-content
sudo chmod -R 755 wp-content

This changes the file ownership to the web server user and then gives that user permission to modify the wp-content folder, which is where WordPress save uploaded content. Depending on the Linux distribution you are using the ‘www-data:www-data’ could change to ‘apache:apache’. Use of the appropriate one should fix the unable to create directory issue.

I hope that these simple to mid-level difficulty steps will help you solve some of these pesky and recurring problems that often plague WordPress development. If you feel I left out a particular common problem let me know in the comments below and I’ll try assist you.

 

Leave a Reply

Your email address will not be published. Required fields are marked *