26 August 2015

Setting up a new user in Ubuntu from scratch

Adding new users to Ubuntu is easy because of the convenience tools that exist.

Start with the command

sudo useradd -d /home/testuser -m testuser

This creates the user and sets up a default home directory.  The user doesn't have a password, but you could add one with passwd if you wanted to.

Then create a directory .ssh in their home directory.  Create a file called authorized_keys in the directory and copy in contents of the users public key into it.

Chown the .ssh directory (and file) to the user and chmod the file to 600.  The directory should be mode 700.

Make sure that /etc/sshd_config is set up to deny logging in by password.

The user should be able to login using their public key by setting up their .ssh/config on their home machine.
Host foo
HostName server.ip.address
User testuser
IdentityFile ~/.ssh/id_rsa
If you want to set them up with your custom bash stuff then remember to copy the files into their home directory and chown them.  You will need to change their shell to bash by editing /etc/passwd

If you want them to have administrative privilege on the machine you need to add them to the "sudo" group with this command :   usermod -aG sudo username.  Because you've disabled password access to the machine you'll need to add a new config file in /etc/sudoers.d that allows them to sudo without a password.  It will need to have a line like this: testuser ALL=(ALL) NOPASSWD:ALL

If you're feeling lazy you might want to use a script.  I've created one and shared it below, but I strongly suggest that you rather write your own and don't use mine for anything other than an idea.  I'm not guaranteeing that it works or even that it's particularly useful.


18 August 2015

Fixing missing msvcp110.dll in xampp on Windows

Microsoft Happiness
I need to use a Windows server to deploy a program I'm busy writing.

I kept on getting a problem with Apache starting up that prevented it from including the MS sql server pdo drivers.

The message was:
the program can't start because msvcp110.dll is missing from your computer. Try reinstalling the program to fix the problem
and this usually relates to the Visual C++ Redistributable for Visual Studio 2012 package not being installed.

I had previously installed this (it's available on the Microsoft site) but was still getting the error.

Eventually I stumbled on this topic on the Apache friends forum which advised to copy the msvcp110.dll file to both
the \xampp\apache\bin and the \xampp\php directories.

Apparently Apache wasn't able to follow the OS path to find the file.  In my case it was already in the php directory but not with the other binaries for Apache.

After copying it there Apache restarted without errors and the PDO driver for MS-SQL was enabled.

11 August 2015

Fixing broken thumbnails in Drupal

If your autoscaled images are not loading on Drupal then here are some steps to take to troubleshoot the problem.

Firstly, if you have logging enabled then visit http://yoursite.com/admin/reports/dblog to see a list of the events.

If you see events with the message "Unable to generate the derived image located at...." then check the permissions on your files directory.  This is usually /sites/default/files.

Then check that the GD library is installed for PHP.  On Ubuntu you can install it with apt-get install php5-gd

If you don't see any events then try opening the image url in a new tab on your browser to confirm that your web server is properly rewriting the request to index.php instead of trying to serve a file out of the directory.

On Nginx you should consider using location blocks like this:

   # These next locations help with thumbnails - https://www.drupal.org/node/2374961  
   location @rewrite {  
     rewrite ^/(.*)$ /index.php?q=$1 last;  
   location ~ ^/sites/.*/files/styles/ {  
     try_files $uri @rewrite;  

This makes sure that requests to locations in the styles directory are routed to index.php if the requested file does not exist in the filesystem.