Monday, 26 November 2018

How to Clear Error & Access Logs on Ubuntu 16.04 Apache Server

Here is an example of the terminal commands to clear error logs and access logs. Remember to update the file paths to the location of your error/access log/s.

sudo bash -c ‘echo > /var/www/html/logs/error.log’sudo bash -c ‘echo > /var/www/html/logs/access.log’

Original Article Posted On:

Some Programming Best Practices for Productivity

Here are some of my thoughts on programming best practices to improve productivity.

YAGNI: “You Ain’t Gonna Need It”. Don’t write code that you think you might need in the future but don’t need yet. This is coding for imaginary future use cases and the code could become dead code or need rewriting because the future use case could turn out to work differently from how you imagined it.

Comments & Console Logs: When comments are used they should be used to explain why the code is there, not what it’s doing as that can be read in the code itself. Blocks of commented code shouldn’t exist in productions releases. This is also true for testing console log statements which should not make it to production releases.

Testing: Test all changes. Only if there is a very good reason should code be left untested. Lack of time is not a good reason and can end up costing more time. Possible good reasons include: genuinely un-testable (in any meaningful way), impossible to hit in practice, or covered elsewhere in a test. Code without tests is a liability.

Code is the Enemy: Code can go wrong and it needs maintenance, so try to write less code, delete code, and don’t write code you don’t need.

Write Defensively: Always think about what can go wrong, what will happen on invalid input, and what might fail, this will help you catch many bugs before they happen.

DRY: “Don’t Repeat Yourself”. If the same code is being repeated multiple times consider putting it in a reusable function. This is more important in production files and not as important in test files, keeping code and what could go wrong in the production environment to a minimum.

Correct VS Speed: Make code correct first and fast second. The top priority is to write code that works and has been confirmed with test. The second priority is the performance and speed of the code (within reason, provided it is not excessively slow code which will cause issues).

Standard Format: It is good to have a standard format (use of indentation, spaces, blank lines, comments) all developers on a project work to, in order to help improve fast readability and help reduce development time.

Original Article Posted On:

The Great Firewall of China – SSL Certificates

When Search Engine Optimising a Chinese website for the main Chinese search engine Baidu, there are benefits to having a .cn domain name and having a server located within the Great Firewall of China.

From what I understand the Chinese government censors web pages by intercepting the connection between a server and the end user. If a web page does not pass their censorship then the page could be edited or not displayed to the user.

Whilst having an SSL certificate protects users data it can stop the Chinese government from censoring individual web pages so if a page does not pass censorship then a whole website may be blocked. Therefore, you may want to consider your SSL set up carefully and whether you will force HTTPS when setting up a server within the Great Firewall of China.

Useful Article:

Original Article Posted On:

Free Website Optimisation Tools

Here is a list of some free useful Google website optimisation/analysis tools:

Here are some further free useful website optimisation/analysis tools:

Original Article Posted On:

How to Set Time Zone on Ubuntu 16.04 Apache Server

Here we’ll cover how to set the default time zone on your Ubuntu 16.04 Apache Server.

First, open your php.ini file (found within the /etc/ directory) in a plain text editor, your file path could vary but here are a couple of example of possible file paths:


Find the following line in the php.ini file. If there’s a semi-colon at the start of this line then remove the semi-colon to uncomment this.

date.timezone =

Set date.timezone equal to your continent and main city, a list of all available time zones can be found at

For Example:

date.timezone = Europe/London

Save your php.ini file and then restart Apache using the following command in terminal:

service apache2 restart

Original Article Posted On:

How to Install a Free LetsEncrypt SSL Certificate on Ubuntu 16.04 Apache Server

Here are the terminal commands to set up a free LetsEncrypt SSL certificate on Ubuntu 16.04 Apache server.

First run these commands in terminal:

sudo apt-get updatesudo apt-get install software-properties-commonsudo add-apt-repository ppa:certbot/certbotsudo apt-get updatesudo apt-get install python-certbot-apache

Now you will be able to install multiple free LetsEncrypt SSL certificates by running the following terminal command for each of the domains on your server, replacing with the domain you want an SSL certificate for.

sudo certbot –apache -d -d

If you want to force HTTPS then don’t forgot to update the .htaccess file for each website your want to force HTTPS on.

It’s also worth noting that when installing multiple LetsEncrypt SSL certificates on a server you may need to edit the following file manually to ensure each of the domains is included in this file. I’ve found when installing multiple LetsEncrypt SSL certificates on the same server it can overwrite the first entry in this file.


Useful Resources


How to Install a brought SSL Certificate on Ubuntu 16.04 Apache Server

Here are the terminal commands and steps to install a brought SSL Certificate on Ubuntu 16.04 Apache server (not LetsEncrypt).

sudo mkdir /etc/apache2/ssl
sudo mkdir /etc/apache2/ssl/private
sudo chmod 755 /etc/apache2/ssl
sudo chmod 710 /etc/apache2/ssl/private
sudo chown -R root:root /etc/apache2/ssl/
sudo chown -R root:ssl-cert /etc/apache2/ssl/private/

Now, place your SSL public certificate(s) in /etc/apache2/ssl and your SSL private key(s) in /etc/apache2/ssl/private

sudo chmod 644 /etc/apache2/ssl/*.crtsudo chmod 640 /etc/apache2/ssl/private/*.key

In /etc/apache2/sites-available update the file paths for SSLCertificateFile, SSLCertificateKeyFile, and SSLCertificateChainFile.

sudo a2enmod sslservice apache2 restart

Useful Resources: