13
Sep '19

I recently decided that (after far too long) I needed to get up-to-date with how I manage my package dependencies for one of my bigger projects. I’d been using gulp with bower components hooked into Laravel Elixir basically since I first ported the project to Laravel, and the deprecation was getting beyond a joke.

Despite there being tons of information out there on how to do achieve individual parts of the configuration, nowhere could I find a single example that would show me how to configure NPM for compiling assets to work with Laravel Mix (the version of elixir) and give me a ‘watch’ option to auto-compile new asset changes.

The first job was to rename my gulpfile.js to webpack.mix.js, and then convert the syntax to use Laravel Mix, rather than Elixir. I’m not going to go into the details of that as it’s extremely straightforward.

Removing bower was simply a case of finding the relevant packages in npm, and amending the paths in the webpack.mix.js accordingly.

The hardest part was getting NPM’s package.json setup with everything I needed. All references to gulp and laravel-elixir came out, webpack and webpack-cli went in along with npm-watch and laravel-mix. My full package.json is below:

{
  "private": true,
  "devDependencies": {
    "resolve-url-loader": "^3.1.0",
    "sass-loader": "^7.3.1",
    "webpack": "^4.39.3",
    "webpack-cli": "^3.3.8"
  },
  "dependencies": {
    "@fortawesome/fontawesome-free": "^5.10.2",
    "@storyous/responsive-bootstrap-toolkit": "^2.6.1",
    "babel-core": "^6.26.3",
    "bootstrap": "^3.4.1",
    "bootstrap-datepicker": "^1.6.4",
    "bootstrap-sass": "^3.3.7",
    "clipboard": "^2.0.1",
    "datatables": "^1.10.18",
    "datatables-responsive": "^1.0.7",
    "datatables.net": "^1.10.19",
    "datatables.net-bs": "^1.10.19",
    "datatables.net-plugins": "^1.10.19",
    "graceful-fs": "^4.0.0",
    "jquery": "^3.4.1",
    "jquery-ui": "^1.12.1",
    "jquery-ui-dist": "^1.12.1",
    "jquery-validation": "^1.19.1",
    "laravel-mix": "^4.1.4",
    "node-sass": "^4.12.0",
    "npm-watch": "^0.6.0",
    "pnotify": "^4.0.0",
    "requirejs": "^2.3.6",
    "select2": "^4.0.10"
  },
  "watch": {
    "dev": {
      "patterns": [
        "resources/assets"
      ],
      "extensions": "js,css",
      "quiet": false,
      "delay": 1000,
      "runOnChangeOnly": true
    }
  },
  "scripts": {
    "dev": "node_modules/.bin/webpack --config=node_modules/laravel-mix/setup/webpack.config.js",
    "start": "npm run dev",
    "watch": "node_modules/.bin/npm-watch"
  }
}

With packages in place the last part was to set up the script definitions to compile my assets. The definitions shown will allow the following commands:

npm run dev – Compiles all assets following the script in webpack.min.js

npm run watch dev – Launches an active task that watches all CSS and JS files in resources/assets for changes, and recompiles whenever changes are detected.

So that’s a working overview start to finish. Hopefully it helps to see the setup in its entirety. It’s a really slick system once it’s all configured, but good grief it takes some effort to get there!

11
Apr '16

If you’re trying to install or update packages via yum on a RedHat /CentOS server and you keep getting ‘Multilib’ errors along the lines of:

Protected multilib versions: openssl-1.0.1e-42.el6_7.4.x86_64 != openssl-1.0.1e-42.el6.i686

Then this means that you already have a 32bit version of a package and you’re trying to install a 64bit version (either by direct installation or as a dependency), or vice-versa. Generally these days you will be operating on a 64bit system so this issue can be very easily fixed by running the following

yum remove *.i386 *.i486 *.i586 *.i686

And then installing the 64 bit versions (these should be the defaults) of the offending packages.

I encountered this when trying to use a 64 bit CentOS image as an AWS server due to 32 bit packages being pre-installed. Good grief it took me a while to figure out!

02
Jun '14

I’ve been having a go at pulling server information and stats out of PHP as a ‘nice to have’ for an application I’m building. It turns out that you can retrieve a fair bit of information from a Linux system if you’re not afraid of wrapping a few system calls. Here’s my finished script, please feel free to use at will!

$stats = array(
    'Host Name' => exec('hostname'),
    'System Date/Time' => date('Y-m-d H:i:s')
);

$uptime_parts = explode(' ', file_get_contents('/proc/uptime'));
$uptime_raw = $uptime_parts[0];
$days = floor($uptime_raw / 86400);
$hours = ($uptime_raw / 3600) % 24;
$minutes = ($uptime_raw / 60) % 60;
$seconds = $uptime_raw % 60;

$stats['Uptime'] = $days . ' day(s), ' . $hours . ' hour(s), ' . $minutes . ' minute(s) and ' . $seconds . ' second(s)';

$load_parts = sys_getloadavg();
$load_average = $load_parts[0];

$stats['Load Average'] = $load_average;

$memory_data = preg_split('/[\r\n]/', file_get_contents('/proc/meminfo'));

if($memory_data && count($memory_data) >= 2) {
    $memory_total_parts = array_values(array_filter(explode(' ', $memory_data[0])));
    $memory_total = number_format(($memory_total_parts[1] / 1000000), 2);
    $memory_free_parts = array_values(array_filter(explode(' ', $memory_data[1])));
    $memory_free = number_format(($memory_free_parts[1] / 1000000), 2);

    $stats['Total Memory'] = $memory_total . ' GB';
    $stats['Available Memory'] = $memory_free . ' GB';
}

$stats['Total Disk Space'] = number_format((disk_total_space('/') / 1000000000), 2) . ' GB';
$stats['Available Disk Space'] = number_format((disk_free_space('/') / 1000000000), 2) . ' GB';
15
Jun '13

I often have to work with SSL Certificates on behalf of my clients – advising on which to purchase, generating keys and certificate signing requests (CSRs), installing the certificates and trying to figure out what on earth I’m meant to be doing with the CA bundles. So I decided that, for the benefit of humankind (or at least any frustrated sysadmins that happen to stumble across this blog) I’d go through the process step by step. Please not that these are the steps that have worked for me, but server environments can vary so I’m not guaranteeing this will work for everyone.

Certificate Options

  • ‘Essential Security’ certificates are the cheapest you’ll find and, while they let you have legitimate HTTPS traffic, they aren’t great for security. There are little or no checks done against the site and they are usually signed by the guys you buy them from, rather than a trusted authority.
  • ‘Trusted’ certificates generally have extra checks and are signed by a trusted authority such as Verisign, Comodo or GlobalSign
  • ‘Extra Authentication’ certificates will usually include checks on the business registering the certificate, which will give customers greater confidence in the site.
  • ‘Extended Validation’ or EV certificates have checks that follow the most rigorous guidelines, and will allow the browser to show a green address bar, along with the standard padlock symbol.

The following is information on creating keys and certificate signing requests with openssl under linux.

Generating a Key

openssl genrsa -des3 -out www.firsthouseontheleft.com.key 2048

Omit the ‘-des3′ flag if you don’t want to include a passphrase. Passphrases are worth having if you think anyone else might gain access to your certificate files, but my feeling is that on a secure server with tight access control, there is little danger in leaving it out. If anyone can gain access to your server to access these files then you have much bigger problems to deal with!

Your keys should always be at least 2048 bits long for maximum security. If an authority asks for less then I’d be very cautious about using them.

Generating a Certificate Signing Request (CSR)

openssl req -new -key www.firsthouseontheleft.com.key -out www.firsthouseontheleft.com.csr

This command will prompt you to provide the following information:

  • Country Name (2 letter code)
  • State or Province Name (full name)
  • Locality Name (eg, city)
  • Organization Name (eg, company) – This is very important if you want extra checks or extended validation
  • Organizational Unit Name – This can be left blank
  • Common Name – This is the full domain name the certificate will be used for (without the https:// bit) e.g. www.firsthouseontheleft.com
  • Email Address – Leave blank
  • A challenge password – Leave blank
  • An optional company name – Leave blank

Now you’ll have your CSR ready to go. You can run the following command to double-check that you’ve entered the correct information:

openssl req -noout -text -in www.firsthouseontheleft.com.csr

Installing the Certificate

You’ll find a lot of long-winded and technical descriptions of installation procedures online, but assuming the certificate is right, it’s just a case of putting it, your CA bundle and your key in the right place and then editing your vhost configuration file to attach them to your domain. For example, under Apache, if your certificates live in /etc/ssl/certs and your keys live in /etc/ssl/private you would need to add the following to your vhost configuration:

SSLEngine on
SSLCertificateFile /etc/ssl/certs/www.firsthouseontheleft.com.crt
SSLCertificateKeyFile /etc/ssl/private/www.firsthouseontheleft.com.key
SSLCertificateChainFile /etc/ssl/certs/www.firsthouseontheleft.com.ca-bundle

Your vhost configuration will likely be under /etc/apache2/sites-enabled or /etc/httpd/conf/extra or within the main httpd.conf file.

The CA bundle should be provided along with your certificate, or alternatively your provider might have a standard one available via their website. You don’t really need to worry about what they are, so long as you can obtain a copy and install as above.

Once the installation is complete you should be able to restart your webserver and see the SSL certificate working its magic on your site.

04
Feb '12

I know many many sites out there have tutorials on Mod Rewrite but I had to piece this together from a number of them and it seemed like a fairly common thing to want to do. If you’re using the classic controller/action/id schema for your site and want to prettify your links so that the values can be simply broken by slashes but you also want relative paths to any subfolders (for images, CSS etc) to work and you don’t want your subdomains to break then try this code in a .htaccess file in your web root. Of course you may need to change the naming of your root file and arguments.

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f                        [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d                        [NC]
RewriteRule .* -                                          [L]

RewriteRule ^([^/]+)/?$ index.php?controller=                                [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?controller=&action=                [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/([0-9]+)/?$ index.php?controller=&action=&id=   [QSA,L]