For the past year or so I have been using rsync to deploy my sites, which has worked perfect for me until recently.
I have recently switched to using a simple post-receive hook using a bare repo on the server. I find this works a lot better for me now as it means all I need to do is “push”.
First you need to setup the repo on your server, I normally set it up in /var/git/site.com for example. This will be a bare git repo, so it will not contain any of your own code. To set this up simply run the following inside your /var/git/site.com folder:
git init --bare
This will initialize the repository, allowing you to push your code to it.
The next step is to tell git where to check your code out too. I usually use /var/www/site.com. For this, I use a very simple post-receive hook that checks the code out to the folder, and runs composer install. You would place the following in /var/git/site.com/hooks/post-receive:
I love finding little thing in PHP that i did not know before. They are generally not important, or advanced but it’s still very interesting. Here are a few i found recently:
Select a character with a string without using substr etc:
Another one i found was “__halt_compiler”, it’s one of the ones i have no real use for but interesting nonetheless. It basically stops the PHP compiler so you can just output HTML from then on without any more server resources being used.
I shall no doubt find a lot more of these, and i will have no use for any of them more than likely.
When I was in the process of setting up my new VPS, I decided I would try out mod_pagespeed (conveniently it had just came out of beta a few days earlier). It turns out, its very easy to setup and very easy to use.
First of all, you need to download the correct package over at:
Once you have downloaded it, its as simple as running:
dpkg -i mod-pagespeed-*.deb
apt-get -f install
Or for CentOS you run
yum install at # if you do not already have 'at' installed
rpm -U mod-pagespeed-*.rpm
The default install includes things such as the minification of css and js files and also the combining of css files (js can be enabled too). Inline images, css, and js is also enabled by default, which allows these types of files to be included in the main HTML layout if they are small enough to justify doing so. This will save requests to the server for more files.
As well as the defaults, i decided to enable a few none default options in the config file:
The ones i decided to enable where the following:
ModPagespeedEnableFilters inline_preview_images # Load low quality images before loading high quality ones
ModPagespeedEnableFilters resize_images # Resize the images before serving them (These are then cached in Varnish)
ModPagespeedEnableFilters insert_image_dimensions # If any image does not have width, height set, then insert them
ModPagespeedEnableFilters collapse_whitespace # Minify the HTML output of the page
ModPagespeedEnableFilters resize_mobile_images # Resize smaller images on mobile
ModPagespeedEnableFilters remove_comments # Remove comments from JS,CSS and HTML files.
Some are not 100% ready for production but the risk value of them is quite low.
From initial tests, it seems to have reduced the page load by about 1/3. Which on a small site may not be a lot, but on a big site with a lot of images etc, this could be a huge saving in bandwidth costs, and also a lot nicer experience for the user.
When you wish to login to a server without having to enter a password, all you need to do is login with SSH. However I do not know why, but it took me hours to find a simple way to do this a few years ago.
First of all, you need to generate your SSH keys using the following:
From this point, i generally just hit enter and use the defaults. You can set a password, but that can get annoying.
Now you need to copy the SSH keys to the server you wish to login to. I have found many ways to do this, but none have been as simple as the following:
You will then be asked for your password for the last time. Once this has complete, you will be able to login to the server using just: