How to switch between multiple versions of PHP cli (console)?

As you probably know it’s possible to install multiple versions of PHP on one server. For web servers, simply define which PHP version you want to use in your server’s configuration file. But how to do it for PHP cli?

Continue reading “How to switch between multiple versions of PHP cli (console)?”

How to install Haproxy, Letsencrypt, Varnish cache and Nginx tutorial

Actually I won’t get into details with Varnish and Nginx configuration because it really depends on your particular case. But it should be pretty straight forward as installing default packages:

apt install varnish
apt install nginx

I’m using port 443 for SSL services, so HAProxy is using this one. It also uses HTTP port 80 and redirects that to https. Everybody knows that Haproxy is stable and quick in jobs it does and that’s load balancing and proxying traffic. In our case, we are going to use it for SSL termination and forward traffic to Varnish which is going to occupy port 6081 (default). And Nginx will use port 8080 because it’s the final destination in our setup. Varnish should cache most of the web content and hopefully put our dedicated server’s CPU at ease most of the time and leverage quite slow CPU to a large amount of RAM (128GB).

In case of traffic increase we can easily balance our traffic to other servers behind Varnish,  because Varnish can play a load-balancing role as well.

Continue reading “How to install Haproxy, Letsencrypt, Varnish cache and Nginx tutorial”

Why is Google trying to kill User Generated Content?

The core rule of capitalism is to continually look for new ways to gain capital. Profit comes before ethics, even before the future of humanity and the existence of life on the planet. Some recent-born corporations vowed not to do evil. Some still think they do not do evil. A while ago, twenty-first century tech-giants came out of nowhere — or rather, out of garages or college basements. In most cases, they began as passionate, bright, juvenile, and non-toxic minds, whose work and passion changed the planet for good. Some of them made remarkable achievements. Continue reading “Why is Google trying to kill User Generated Content?”

How to hook PHP mail() function

There are times when you may need to hook some PHP function for one reason or another. PHP makes it an easy task to accomplish using override_function which overrides built-in functions. This is useful only in the context of your own code or the code you can easily change in order to work with the aforementioned function. So, this solution might not be always at your disposal.

Specifically, let’s take a deeper look into the PHP mail function which is frequently used and misused in various scripts.

Continue reading “How to hook PHP mail() function”

PHP – How to escape only single quotes?

Escaping special characters is a usual business in programming and PHP is not an exception either. There are plenty of escaping functions in PHP and we already mentioned some of them that deal with encoding HTML entities. MySQL is also picky when it comes to special characters and it has its own sets and rules which are usually covered with escaping functions such as addslashes. However, when it comes to storing JSON in the MySQL the approach is a bit different.

Continue reading “PHP – How to escape only single quotes?”

Difference between htmlspecialchars_decode and html_entity_decode

There are quite a few similar functions in PHP. Some of them are almost identical like echo and print and some have subtle differences which are not obvious at the first glance. We can put htmlspecialchars_decode and html_entity_decode in this category. There is a lot of confusion between notions of HTML special characters and HTML entities so let’s look into the difference.

Continue reading “Difference between htmlspecialchars_decode and html_entity_decode”

PHP – Convert special character &quot to real quote

In certain situations, you could be messing with HTML special characters in a text. At first glance, you might not even notice these are existing in the text. For example, if you’re looking text in a browser these characters will look just like normal characters. But when you peak into the page source you’ll see very different representations, (&amp; for &, &quot; for “, &lt; for <, &gt for > and so on). So how do you convert it to the normal characters?

Continue reading “PHP – Convert special character &quot to real quote”

How to copy file with SCP from one server to other without password

Sometimes we will need to automate file copying between our servers. For example, our shell script might need to copy the backup from time to time and we don’t want to provide the password in the clean text format. So what we can do about this?

Continue reading “How to copy file with SCP from one server to other without password”

Multiple MySQL instances on one server

When you enter the field of multiple MySQL instances on one physical server you might run into the trouble. Lack of documentation, cryptic bugs, and insane settings is something you need to get used to. I almost quit a few times in the process and only my habit of trying unusual things when everything logical failed kept me up to the solution.

Continue reading “Multiple MySQL instances on one server”