PHP 7 on Ubuntu

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.

Front-end editor for WordPress

WordPress is a great CMS(Content Management System) to manage blogs, websites of various scales, over time it has gained popularity due to fulfilling demand of its users. It has gained features like autosave and many other features of the time.

The only thing it lacks at this point is a front-end editor, for the user. The user who prefers to use front-end instead of the backend, frontend editor has many advantages.

  • Preview of the how the page would actually look
  • Structure markup depending on the design.
  • Manage media(images, videos, etc) according to the design of the page
  • Easier to handle just for the user

Is it possible to get all of this right now? Yes it is, there is a plugin for that too…Its WA-Frontend a plugin currently in active development that lets you edit pages and post from the front end, it also allows you to manage settings and you can also access the autosave in the front end with version control, this lets you preview or revert to your earlier edited history, all you have to do is install this plugin and you are ready to go to the front-end to see it in action.

Here are a few screenshots:

Thank you for reading, for more WordPress content stay tuned.


PageKit is an open source CMS (Content Management System) written in PHP, build using Symphony components and Vue.js, developed by YooTheme.

It has a very clean and easy to use admin interface inspired by Google’s Material Design, that contains customizable widgets.

It offers 3rd party developers to develop themes and plugins(extensions), plugin and theme dependencies are managed by composer, which reduces the amount of manual labor for a user, and fewer things to manage for a programmer/coder.

PageKit offers both SQLite and MySQL support, so you can choose what suits best for you.

I discovered PageKit while searching for a CMS that has a well-written codebase, uses composer to manage dependencies and can work with SQLite, you might know, I am not a big fan of MySQL if you have read my earlier posts over other CMSs.

I have been observing this project since I had discovered it, it has a higher potential than most other CMS out there, specifically CMSs that support SQLite.

According to my vision the day PageKit full fills all the common CMS requirements and reaches 1.0, it will already be a big competitor for most of the popular CMS out there.

Once PageKit has well-written documentation and stable codebase, with common feature support which is currently work in progress for the developers, it will be the CMS I would recommend everyone.

This CMS is one of the second CMS I would recommend after Grav

Leave a comment below and lets me know what you think.

Composer on Mac

Composer is a dependency manager for PHP, that lets you manage dependencies by offering install/uninstall and options like creating projects.

It manages dependencies for you, big projects like Laravel framework and CMS like Grav use it to manage dependencies.

It’s easy to install it on Mac, all you have to do is run this curl command in your Terminal.

curl -sS | php  

You will now have a composer.phar, which is executable.

You can move the file to the /usr/loca/bin directory to make it accessible from anywhere.

sudo cp composer.phar /usr/local/bin/composer  

Now when you run composer from your terminal you should get a greeting screen from Composer.

PHP: 301 Redirect

In PHP you can use header function and create 301 redirect.

Here is a sample snippet.


header('Location:', true, 301);  

The code below is an older version of this post.

header("HTTP/1.1 301 Moved Permanently");

header("Location: [](");

This will redirect the PHP page you have added this into, you can change to any domain you prefer, you can do the same to file with extensions and subdomain.

Thanks to, Christian Häusler for the tip.

Thank you for reading.

Lightweight WordPress setup

WordPress is the most popular CMS used by a large number of websites, It is written in PHP which makes it an ideal choice for most people. It offers a lot of features and a really easy to use backend.

But, it performs well until the MySQL database is small and your WordPress setup does not live on to many plugins and has permalinks set correctly.

WordPress on a small Web Server cannot handle many visitors and might fail due to MySQL database crashing which at time can be a big problem,it can occur due to lack of free memory, if there are other things that use the MySQL database it will make WordPress slow if the website get a lot of traffic.

So, I decided to write a simple post, that will let you run WordPress on a small Web Server with optimum performance.

It is recommended that you do this in a clean WordPress setup and then migrate content to the newer install rather than tweaking the current WordPress install that is running in production, It is also better to test the environment before switching it to production, because there are many factors that can make a positive or negative performance difference.

Lets do it!

We will use SQLite instead of MySQL, this is recommended if the website is just a blog or does not serve or receive thousands of requests at a time, I have not tested this in high traffic, but has been rock solid stable on the amount of views I get for my website.

You can follow this guide to install and setup WordPress with Sqlite.

You can use WP Super Cache plugin and cache WordPress, so it does not have to query the database on every request, it is recommended that you set WP Super Cache only to update when a new comment is made or when new post or page is updated.

If you are running NGINX instead of using WP Super Cache you can use the build in micro-caching of NGINX also known as FastCGI cache which will cache WordPress for a fixed amount of time, this will cache the page on the first page request and will display stale content until timeout, this can do a big performance difference and can save you a great amount of system resource because it does not query the database on every request

I have written a NGINX config that can be used as an example while configuring your WordPress with NGINX setup.

I would also recommend to keep your WordPress install as clean as possible, don’t keep plugins that you don’t require, avoid plugins that are not longer being maintained and try to use a theme or write a theme that does most of the thing with the power of PHP templating.

Thanks for reading,

Have a question? leave a comment below.