bookmark_borderWordPress via Digital Ocean: Increase Upload Size

If you attempted to upload photos through the WordPress admin console you were probably disappointed to find the upload size defaulted to 2MB.

However, if your site is hosted through Digital Ocean or you have access to your own server you can quickly change this.

We can make the changes to PHP’s configuration file however, it will apply to all of your PHP sites. Alternatively, we can make the changes to an .htaccess or Apache virtual host configuration for more control.

Regardless of the approach, we are interested in three configuration directives: 1) post_max_size and 2) upload_max_filesize and 3) memory_limit. The default values are 8MB, 2MB and 128 MB respectively. You should not need to alter the memory_limit directive unless your post_max_size is close to or greater than memory_limit. Second, your post_max_size should be larger than your upload_max_filesize in order to successfully upload your files.

Now let’s log into our web servers.


Make your way over to the PHP installation folder at /etc/php/. Your path may be slightly different depending on your PHP version. Drill down to the version folder you are using and into the apache2 folder (i.e. /etc/php/7.2/apache2). Here we will find the file php.ini.

Use the following commands to locate the line numbers for these directives in php.ini.

more php.ini | grep -n "post_max_size"
more php.ini | grep -n "upload_max_filesize"
more php.ini | grep -n "memory_limit"

Now, use your favorite editor to update these directives and save your changes. Please note that php.ini uses only “M” to denote “MB”. Restart the Apache server to apply your changes.

.htaccess or Apache virtual host configuration

If you are setting your configuration through an .htaccess file change your working directory to your WordPress folder and use your favorite editor to edit your .htaccess file.

If you prefer to do your configuration through an Apache virtual host, head over to for your virtual host’s configuration file ( /etc/apache2/sites-available).

Add the following lines with your specific values, save your new configuration and restart the Apache server to apply your changes.

php_value post_max_size 12M
php_value upload_max_filesize 3M
#php_value memory_limit 128M

The max upload size in your WordPress admin console should now show your new upload limit.

If you are interested in hosting your own VM with Digital Ocean, please consider using my referral link so we can both earn Digital Ocean credit. Please visit this link to learn more about Digital Ocean’s referral program.

bookmark_borderWordPress: 404 After Changing Permalinks

Whew! This took me way longer than it should have. Long story short, I was missing the rewrite module on Apache, my Apache configuration file needed an update and my Apache virtual host setup was messed up! I’m not positive at what point I broke my virtual host setup but I knew I had made a mistake when I ran the command below and saw a backup file under my virtual hosts. Sadly, I only came across the command below after a few hours of researching the issue. Let’s blame it on the fact I had not had a morsel of food for seven hours.

apache2ctl -S

First we must verify that the rewrite module in Apache is enabled. If the module is not enabled we will not be able to run the directives under our WordPress site’s .htaccess file. If the module is already enabled on your server, you will receive a message stating so. It will also be visible under /etc/apache2/mods-enabled as rewrite.load. Run the commands below to enable the module and restart Apache.

sudo a2enmod rewrite
sudo service apache2 restart

After verifying the rewrite module is enabled, check to see if there is still a 404 error on your pages. If there isn’t, great! Else, we continue, when you change the permalink format through your WordPress admin console it inserts rewrite rules to the hidden file .htaccess in your WordPress directory. .htaccess files contain overrides or additional information about your site configuration. Versions 2.3.9+ of Apache, by default do not allow .htaccess files to override the configuration specified under /etc/apache2/apache2.conf. Apache’s main configuration file also includes any configurations you may have written for any enabled virtual hosts. Below is a snippet from the default Apache configuration file.

# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted

The AllowOverride None directive above is stating that for directory /var/www/ do not allow the server configuration to be overwritten through the use of .htaccess files. There are two reasons for this logic 1) performance gain and 2) security. WordPress’s default behavior is to edit the .htaccess file when you make changes to the permalink format so you may choose to keep .htaccess but keep in mind Apache does not recommend the use .htaccess if you have access to the main configuration file.

The AllowOverride directive accepts three different values; 1) None, 2) All, and 3) Directive Name. If you choose to keep using the .htaccess file, the third option allows for better security than simply entering All by allowing us to enter which directives can be overwritten. For the purposes of this particular issue we will be using the value FileInfo so we may make use of the rewrite module but visit the official Apache documentation for more information on the directive names available and how to use them.

Below is the code you want present in your Apache configuration file so WordPress’s .htaccess may be able to rewrite your URL’s and serve your pages.

       <Directory [YOUR_DIRECTORY_PATH]>
                Options Indexes FollowSymLinks
                AllowOverride FileInfo #Alternatively, use AllowOverride All
                Require all granted

If you would like to remove the .htaccess file and instead include your rewrite logic in your configuration file you will need to include the rewrite directives within the Directory tags as shown below.

       <Directory [YOUR_DIRECTORY_PATH]>
                Options Indexes FollowSymLinks
                AllowOverride FileInfo #Alternatively, use AllowOverride All
                Require all granted
                RewriteEngine On
                RewriteBase /
                RewriteRule ^index\.php$ - [L]
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule . /index.php [L]

After editing your configuration files make sure to restart your Apache server to make our changes active. By this point, the 404 error on your WordPress pages should be gone.

If it is not and you are making use of virtual hosts, I urge you to verify that your Apache virtual host configuration is correct. I spent quite a while with this issue because I had a larger underlying issue with my virtual host configuration. I was able to identify the issue by not resorting to making changes to apache2.conf when I felt positive the changes on my virtual host configuration file were supposed to work. My particular issue was a file I had renamed as a backup was still linked as a virtual host and was occupying the same server name as the new file I thought was the active virtual host. Both my backup and newer file had the same server name specified. I removed my backup from the server entirely and it worked. My brain was toasted.