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.

bookmark_borderColor Swatches from Spangle call Lilli line – nano (TK Kaleidoscope Remix) Music Video

The images below are screenshots from Spangle call Lilli line’s and TK’s nano (Kaleidoscope Remix) beautiful music video. The video was filled with beautiful shades of green, blues and grays. Stormy dreams!

bookmark_borderHaProxy: Cannot Bind Socket

As a total noob in system administration, it took me a while to realize that my machine’s services might have been stopped/restarted after Digital Ocean reached out about performing an emergency droplet migration after detecting problems on the physical server where my load balancing droplet/VM was running.

This was confirmed by running the following command and noting that the last time HaProxy had been active was on Digital Ocean’s maintenance day. (Please note that I am running these commands on Ubuntu.)

systemctl status haproxy.service

With this newfound knowledge, I attempted to restart HaProxy as sudo but ran into an error. After checking the HaProxy log (located in /var/log/), I found the following error message.

"Jul 15 17:10:13 ab1 haproxy[32723]: [ALERT] 202/171013 (32723) : Starting []: cannot bind socket [000:000.000.000:80]:"

Something was already occupying/listening on port 80! After using the the netstat command and feeding its output to grep we identified the culprit…Apache! Of course…my droplet was restarted and the apache2 service is probably set to start on boot.

sudo netstat -ltnp | grep -i ":80"

Our site was up and running after stopping the Apache service and starting HaProxy.

sudo service apache2 stop
sudo service haproxy start

I was able to confirm the issue arises on booting by checking our boot log with the following command.

sudo journalctl -b

Jul 15 16:34:11 ab1 systemd[1]: Started The Apache HTTP Server.
Jul 15 16:34:11 ab1 haproxy[978]: [ALERT] 195/163411 (978) : Starting frontend http: cannot bind socket []
Jul 15 16:34:11 ab1 haproxy[978]: Proxy www-https started.
Jul 15 16:34:11 ab1 haproxy[978]: Proxy www-https started.
Jul 15 16:34:11 ab1 haproxy[978]: Proxy app-backend started.
Jul 15 16:34:11 ab1 haproxy[978]: Proxy app-backend started.
Jul 15 16:34:11 ab1 systemd[1]: haproxy.service: Main process exited, code=exited, status=1/FAILURE
Jul 15 16:34:11 ab1 systemd[1]: haproxy.service: Failed with result 'exit-code'.
Jul 15 16:34:11 ab1 systemd[1]: Failed to start HAProxy Load Balancer.

Now if we want to prevent this from happening in the future, we have to set which services we want to auto start on boot which will be the topic of an upcoming post.

Hasta la vista baby!

bookmark_borderA Closer Look At Conditionals

I once came across a .NET C# process meant to manage Active Directory accounts for a few thousand employees. The code was probably over 10 years old and in shambles. You may call it a code nightmare. However, due to time and priority constraints the team never received the time to think of a better solution.

There was a number of bad programming practices in the process that were contributing to severe performance issues. The construction of bad conditional statements illustrated below was possibly the least guilty culprit but it peaked my curiosity: just how much do repetitive/bad conditional statements impact our code? The statements I’m referring to followed the format below:

if x:
if not x:

With the exception of the process’s first run, the process was always executing double the amount of conditional statements it needed! The GIF below illustrates what’s going on under the hood when statements are formatted like above. Note the additional step in the first block when x is true. This is a completely unnecessary stop. If x is true, there is no need to check whether x is not true. The execution of all three blocks is similar when x is false, except the first and second block still have to check the condition contained in the statement increasing our execution time. Remember that else-if and else statements are similar but not always interchangeable. Else catches all statements that do not fall under if, use else-if to further refine your conditional logic. Lastly, the order of your statements matters, our GIF would look slightly different if our statements began with “if not x” rather than “if x”. We have a simple example but if your logic is complex, incorrect order of your conditional statements can lead to logical errors that can be hard to identify. A giant yikes when number crunching!

In order to calculate how much the formation of these statements impacts our execution time I wrote a short program in C++. Our program populates a vector of variable size with random numbers from 1 to 100. It then iterates through each item in the vector to check if the item is even or odd. Please note in this case the if/else-if case is rather pointless (a number is either even or odd) but demonstrates the impact when having to check an additional condition. The program was run with vector sizes of 100,000, 1 million, 5 million and 10 million. We ran the test 10 times for each of our four scenarios. Below are our results; 1) The first graph illustrates our average execution time, 2) the second shows minimum execution time and 3) the third shows maximum execution time.

The tables below demonstrate the values in milliseconds present in our graphs. I have also included the percentage increase in average execution time from if only statements to the if/else. It is interesting to observe that after 1 million items the increase in average execution time remained steady. I wonder if this execution time would hold steady in additional experimental runs and if further increasing our vector size would impact it.

100,000 Items (~42% Increase in Average Execution Time)
Minimum (ms)Maximum (ms)Average (ms)
If Only545697201964650
If/Else If462276282954435
1 Million Items (~36% Increase in Average Execution Time)
Minimum (ms)Maximum (ms)Average (ms)
If Only586051678356610965
If/Else If490740565310519148
5 Million Items (~36% Increase in Average Execution Time)
Minimum (ms)Maximum (ms)Average (ms)
If Only297413534584303.16961e+06
If/Else If236058129484972.49619e+06
10 Million Items (~35% Increase in Average Execution Time)
Minimum (ms)Maximum (ms)Average (ms)
If Only559714061813645.87011e+06
If/Else If444911051824314.83241e+06

So how much do badly formatted conditional statements impact our code? In terms of execution time, significantly so. These increases may hardly be noticed in most day to day business applications but they are essential in a computation heavy process working with millions of items. Always take an additional minute to think and write proper conditional logic. Aside, from decreasing overall execution time, it will also greatly reduce the chances of introducing a logical error. In fact, it might be a great idea to follow your logic a couple of times through manually to make sure everything is working as expected (or maybe you can even write automated tests!).