PHP 7 on Ubuntu

PHP 7 on Ubuntu Image 2

It has been quite some time since PHP 7 was released, it has major bug fixes, improved and new ways of writing syntax and many other changes you can find here.

So I decided to write a guide on how to upgrade or install and setup PHP 7.x.x on your Ubuntu based system.

This is a major update, this can break your website or web application, please test your website or web application in a development environment before applying this to your production environment.


Adding PHP 7 ppa to the local database.

sudo add-apt-repository ppa:ondrej/php-7.0

Updating the local database.

sudo apt-get update

Installing PHP 7.

sudo apt-get install php7.0 php7.0-cli php7.0-common php7.0-curl php7.0-fpm php7.0-gd php7.0-json php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-sqlite3

Now you can run `PHP -v` in the terminal to check if it has been installed successfully.

Upgrading from PHP 5 to PHP 7

This will purge PHP 5 and remove unwanted dependencies and then clean up the temporary files

sudo apt-get purge php5* && sudo apt-get --purge autoremove && apt-get clean && sudo apt-get install php7.0 php7.0-cli php7.0-common php7.0-curl php7.0-fpm php7.0-gd php7.0-json php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-sqlite3

Switching NGINX to PHP 7 from PHP 5

Edit the NGINX config to work with PHP 7 FPM, go the specific server config and change the following lines.

From this

location ~ .php$ { try_files $uri =404; 
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;

**To this**

location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

The only line changed is the `fastcgi_pass`.

From this

fastcgi_pass unix:/var/run/php5-fpm.sock;

**To this**

fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

Now all the PHP config files are moved to `/etc/php/7.x` from `/etc/php5/`.

So the path to the php.ini is now located in /etc/php/7.x/fpm/php.ini, this means any edits done to the older PHP 5 php.ini need to be re-applied because this is a fresh new in file.

You can restart PHP 7 FPM by entering this command.

sudo service php7.0-fpm restart

Thank you for reading

If you have any question leave a comment below.

When and why you should use a CDN


CDN also known as Content Delivery Network is a way to distribute web content and assets to the user depending on this geographical location, this means that the closest server to your location will serve you the content. This makes a load up time faster and reduces the load amount of active connection on the main server due to faster delivery. Here are some CDN services available Cloudflare, MaxCDN, Microsoft Azure

How CDN works

Why use CDN?

CDN deliver content faster to the user, this reduces the load up time of individual files and assets, this is achieved by having multiple copies of data distributed to servers from various locations.

Here is a simple example:

If you live in Asia and the website you are visiting is has a server located in Europe, the amount of time it would take to load up a page on the network would be longer, because of the distance between the two locations. This is not noticed when serving small files, but if you are going to download a file as big as 1GB or larger, you may notice a bit of delay before the downloader connects to the server to request the file and will have a network delay while fetching the content, this is still fine if the file you have requested is not requested by other users, but if there are a large number of people downloading the same file from the same server, it might take a longer time, because the individual server has its own limit to handle requests.

So now lets see how a CDN can help out.

A CDN will copy the same files to multiple servers located in different locations like Asia, Europe, America and depending on the user’s location, it will serve the file, So if you live in Asia, the server located in Asia will serve you the file by detecting the location, while accepting the request made by you. This reduces the delay because the distance in the network is shorter and there are multiple servers to server content based on location, so now if a visitor from Europe downloads the same file it will retrieve the file from the server located in Europe and serve it to the user. This lets websites like Google, YouTube and many other websites serve content to a larger audience from various location with a shorter delay.

But, when do I need a CDN?

When your website is large and has to serve content to a large audience of various location is a short amount of time. So if you have a blog that gets a good number of views and has graphical right content and the server can handle it without a pain and if there is no noticeable delay in content served to the user, you really don’t need a CDN. Only if you have a lot of traffic, which might delay the web content served to a large number visitors, or if you have a sudden rush of traffic to every new blog post, that can not be handled instantly by the server instantly, that is when you might need a CDN.

Everything at once

CDN are good for serving content faster to a visitor depending on their location, this is good for websites that have a large number of visitors and can have large amounts of delay, which might make them lose visitors and can crash the servers, It does not make any sense to have a CDN for a website that gets a decent amount of traffic that can be handled by the server without any pain and does not have large amount data to be served for every request

Thank you for reading,

If you have any questions feel free to leave a comment below.

The image used in the post is by Wikipedia

Good Bootstrap practices


Bootstrap is a CSS(Cascading Style Sheets) library developed by Twitter that lets you create responsive websites with easy to understand naming convention and well-designed grid system.

It has gained popularity due to its easy of use and pre-processor support, here are some good practices that will make your Bootstrap powered environment clean and easy to manage and maintain.

Use PreProcessors

Bootstrap offers Less based builds, these builds let you choose what modules you require and are needed to be enabled and helps you override the style sheets with writing lesser lines of the stylesheet.

Things like colors of text and background color of elements classes like navbar can be changed by changing the information stored in the variables.

Use of PreProcessors can make your Bootstrap lighter and have a cleaner code base, that is not bloated by the defaults.

Use scripts depending on the structure and modules

What I mean to say is if you website does not contain large amount of Bootstrap, then don’t use the <code class="highlighter-rouge">bootstrap.min.js instead use the individual module files in development and later minify them to one file in production, so if you have a bootstrap based drop-down menu, you don’t have to use the complete bootstrap javascript library and only use the <code class="highlighter-rouge">dropdown.js with its helper files.

This will make your website lighter and less bloated with things that are not going to be used and the client has a smaller file to render.

These are all the major steps I take while developing a website with Bootstrap.

Thank you for reading,

If you have any question feel free to leave a comment below.

Typora Markdown editor


Typora is a free cross-platform Markdown editor for Mac/Windows/Linux), it currently in beta stage and under active development. You might be thinking not another Markdown editor, with keyboard shortcuts and side panel preview and custom CSS options. Typora is a WYSIWYG (WhatYouSeeIsWhatYouGet) editor, this means you would not have a separate preview panel to the side for preview, this is a great way for writing content, because your source editor is your preview editor, that updates as you are typing, so you have more screen space for writing and focus while typing will be on the same window and not a separate panel. As the video below

It is one of the best Markdown editors I have ever used till date.

It has many other features similar to the other Markdown editors like Mou

  • Custom theme
  • Font customization
  • Window style(how the app should appear)
  • Word count

It is a great editor for a writer who wants to edit and view the preview in the same place and wants to have a larger amount of screen space used for editing area. Thank you for reading, if you have any question feel free to leave a comment below.