How to set up an nginx web server in 3 easy steps

How to set up an nginx web server in 3 easy steps

How to set up an Nginx Web Server in 3 easy steps Get a Server with Ubuntu Get a domain name Get WebCP.io web hosting control panel   In case you’re wondering how to set up an Nginx web server with PHP 7.2, mail, webmail, FTP, built-in optimisation and built-in security, you’re in luck. I’m going to show you exactly how it’s done. And it’s easier than you think. 1. Get a server: What I use for SoftSmart is an…

Read More Read More

Auto Loading in PHP

Auto Loading in PHP

Auto loading in PHP is the means by which to load classes (and traits and things!) without needing to specifically require the class file. On smaller projects with one or two classes and a handful of files this might not seem like a big deal, but on larger project, particularly with classes from different vendors, and in frameworks like Laravel, auto loading becomes particularly important. Our file structure To follow this PHP autoloading tutorial you should be aware of our…

Read More Read More

Using Composer Dependency Manager

Using Composer Dependency Manager

In days gone by when you wrote a project in PHP you would often write all parts of the project yourself, or you probably had code components from previous projects that you copy and pasted into your new project. You may even have gotten a third party library from the web. Of course in these days gone by you also had to figure out how to load the code into your new project. Composer Dependency Manager came along and changed…

Read More Read More

Facebook Share Button Missing Image

Facebook Share Button Missing Image

  On one of my client’s sites they have the regular social sharing icons. When a visitor clicks on the share to facebook link it populates that share with some default info, and very importantly the image. This is important to them because they run image voting sites. I was asked to see if I could fathom why the image was missing on facebook sharing. The first thing I checked was the open graph (OG) tags on the site. The…

Read More Read More

PHP Traits

PHP Traits

What are PHP traits? In genetics, traits refer to a characteristic or an attribute in your DNA. For instance, you have a trait for eye colour, or hair type. In PHP traits refer to a set of common functions which can be used by multiple classes. I think of it almost as “includes for classes” (don’t quote me on that, its just a conceptual way of looking at it). As with most programming languages, PHP is easiest learned by example,…

Read More Read More

Dependency Injection

Dependency Injection

Dependency injection is a design pattern which allows you to inject your dependencies into a class, rather than have them loaded from within that class. This blog post on PHP dependency injection will be an example based post without too much commentary from me.   Typically when we write our classes they require functionality from other classes. One way of achieving this is to include and load a new instance of the dependency within our class. Another possibility is that…

Read More Read More

Zend Opcache improves page load speed

Zend Opcache improves page load speed

Zend Opcache in PHP improves your page speed by compiling code into machine code and storing the byte code in RAM. With each subsequent hit to a resource code is served from memory rather than being compiled again. PHP is an interpreted language. What this means is that unlike languages like C / C++, PHP is not compiled once to machine code and then executed from the binary each time. With PHP, each time a page is viewed on your…

Read More Read More

PHP Queues with php-resque

PHP Queues with php-resque

If you’ve been doing PHP development for more than a week you’ll have heard about the benefits of message queues. If you’re totally new to this world and have not heard of queues you should google for more info. At its most basic though a message queue allows your application to offload long running tasks to be completed as background tasks, thus speeding up the front end for your visitors. For instance, on cutestix.co.za (a children’s photo competition site) when…

Read More Read More

WordPress errors uploading images

WordPress errors uploading images

I recently encountered a problem with WordPress image uploads. The following code was called to attach an uploaded image to a WordPress post and set it as the WordPress featured image, or post thumbnail as its called in the code.. The problem is that the code kept failing. We checked the logging of is_wp_error and found the following error: Our site uses SSL (https://), however on the server itself we use a self signed certificate. The reason for this is…

Read More Read More

Laravel belongsToMany relationship

Laravel belongsToMany relationship

There are often times when your data has a “belongsToMany” relationship. Laravel handles this relationship really beautifully! I learn best by example, so we’ll do this post as an example I’m currently working on. In our application we have multiple related websites. Each of these sites stands on its own with users being able to register individually on each site. We wanted to update this so that when a user registers on one site their details are automatically pushed to…

Read More Read More