Using WP-CLI to Install WordPress

My web server is running Ubuntu 15.10, so these instructions apply to this version of Linux. YMMV.

WP-CLI is a sweet, command-line tool for managing WordPress installations. First things first, we need to install it. Best thing to do is follow the instructions on the site I just linked.

Next step is to get an empty MySQL or MariaDB database ready, preferably with a unique, restricted user attached to it. See the bottom of this post if you're not sure how to do that.

Next, create a directory for WordPress to be installed in. How you set up your files is up to you. Once it's ready, open a terminal and navigate to the directory you created.

Download the latest stable version of WordPress into the working directory:

wp core download

Next, create your wp-config.php file (replace the items in angle brackets as applicable):

wp core config --dbname=<DATABASE_NAME> --dbuser=<USER_NAME> --dbpass=<PASSWORD>

Finally, install WordPress and set up the admin user:

wp core install --url=http://<YOUR_URL> --title='<SITE TITLE>' --admin_user=<ADMIN_USER_NAME> --admin_email=<ADMIN_USER_EMAIL> --admin_password=<ADMIN_PASSWORD>

That's it! Browse to your URL and (assuming your server is correctly configured), you should see your brand new WordPress installation.

Also, just in case command-line MySQL scares you, here are the commands to create a new database with its own user:

mysql -u root -p
CREATE DATABASE <DATABASE_NAME>;
CREATE USER '<USER_NAME>'@'localhost' IDENTIFIED BY '<PASSWORD>';
GRANT ALL PRIVILEGES ON <DATABASE_NAME>.* TO '<USER_NAME>'@'localhost';
FLUSH PRIVILEGES;
exit;

Compiling nginx with ngx_cache_purge on Ubuntu 15.10

There's a PPA for 15.04 and earlier versions, but I needed nginx with the cache purge module on 15.10. Here are the steps I took:

Install nginx from the Ubuntu repository, then immediately stop the service:

sudo apt-get install nginx
sudo systemctl stop nginx

Download the latest sources for nginx and the ngx_cache_purge module and untar:

wget http://nginx.org/download/nginx-1.9.12.tar.gz
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
for filename in *.tar.gz; do tar zxf $filename; done

Install required libraries (these are the ones I needed to install; YMMV).

sudo apt-get install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev libssl1.0.0 libxml2 libxml2-dev libxslt1.1 libxslt1-dev libgd-dev libgeoip1 libgeoip-dev

Build nginx. The options listed here are essentially the same as what are listed in the repository build. The only differences are the addition of the ngx_cache_purge module and the removal of the --with-http_spdy_module (which doesn't work for whatever reason).

cd nginx-1.9.12
./configure --add-module=../ngx_cache_purge-2.3 --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module
make
sudo make install

You'll need to replace the Ubuntu repository version of nginx with the one you just compiled. The make install command drops it in /usr/share/nginx/sbin, but it needs to be in /usr/sbin. We'll take care of that now. Then, assuming everything went well, you can restart the nginx service.

sudo mv /usr/sbin/nginx /usr/sbin/nginx.ubuntu
sudo cp /usr/share/nginx/sbin/nginx /usr/sbin/.
sudo systemctl start nginx

You may want to prevent apt from updating nginx (so that you can do it manually). If so, the following commands are useful:

sudo apt-mark hold nginx
sudo apt-mark unhold nginx

Setting up a Minecraft Server using systemd under Ubuntu 15.10

My daughter loves Minecraft and she loves playing it with someone (usually me) even more. I decided I wanted to set up a server that would allow her to connect and play in her world whenever she wanted, and also allow for multiplayer fun. We couldn't do that on her laptop, because it just isn't powerful enough to handle serving up Minecraft, as well as playing it. Thus, after much research, I figured out how to get a Minecraft server (or several) up and running using systemd on Ubuntu 15.10, which is what my desktop runs.

NOTE: This how-to only covers how to get a basic server up and running as a service under systemd. Many related topics (such as configuring your firewall, port forwarding, Minecraft server setup, server security, etc.) are outside of the scope of this discussion. This how-to assumes that your server will only be available to your LAN. YMMV.

Here are the steps in a nutshell:

Create a minecraft user, with a home directory at /opt/minecraft.

sudo groupadd -r minecraft
sudo useradd -r -g minecraft -d "/opt/minecraft" -s "/bin/bash" minecraft
sudo mkdir /opt/minecraft
sudo chown minecraft.minecraft /opt/minecraft

Next, switch to the minecraft user to set up the server(s).

sudo su minecraft
cd ~
pwd

The last command is just to make sure that we're where we think we are (it should be /opt/minecraft).

Create at least one directory to store a Minecraft server instance. You can actually create more than one, and I will include details about that later. For now, just create one. We'll start with a creative mode server. We'll also download the Minecraft server jar.

mkdir creative
cd creative
wget https://s3.amazonaws.com/Minecraft.Download/versions/1.9/minecraft_server.1.9.jar

You may need to update that last line to grab the latest server version.

Now, run the server for the first time. This will generate a few files and exit because we haven't accepted the EULA.

java -Xms1G -Xmx1G -jar minecraft_server.1.9.jar nogui

Edit the eula.txt file to accept the EULA. Change eula=false to eula=true. You can use whatever text editor you like. Save and close the file, then relaunch the server (using the same command as above).

Now is a good time to make sure the server is running correctly. Jump into Minecraft and try to connect. Walk around a bit and make sure everything is working as it should be. (How to do this is beyond the scope of this how-to).

Go ahead and stop the server (just type stop and press <ENTER> in the terminal that you launched the server in). Next we're going to create a symbolic link to make updating this easier down the line. It also has the advantage of allowing us to run multiple versions of Minecraft server without creating new unit files. All of this will make sense in a minute.

ln -s minecraft_server.1.9.jar minecraft_server.jar

You can test the server again, if you like, just to make sure you got it right. Just run the same command as before, but use minecraft_server.jar instead of minecraft_server.1.9.jar.

Before we set up the systemd configuration, we have one other thing to do. We need to set up rcon to allow for remote administration. Open the server.properties file and change rcon.enable=false to rcon.enable=true. Save and close the file, then fire up the server again.

If you did this right, everything should still work, but you'll get an error in the console about not having an rcon password. Stop the server and open the server.properties file again. You'll notice a few lines have been added. Make note of the port number from the line rcon.port=25575 (25575 is the default port number). Also, add a password to the rcon.password= line. Make it something good, because anyone who has this will have access to your Minecraft server!

This is a good time to get your hands on a client that will let you connect to your server. Since I have an Android phone, I use (and really like) MConsole. There are a lot of other options, though, so you don't have to take my advice. Once you have the client in hand, go ahead and test it out by entering your server's IP, rcon port and rcon password. If it works, you're golden!

Finally, we'll set up the systemd unit file. Create a new text file under the /opt/minecraft parent directory called minecraft@.service. The @ sign is very important. Paste the following into this file:

[Unit]
Description=Minecraft Server %i

[Service]
WorkingDirectory=/opt/minecraft/%i
User=minecraft
Group=minecraft
Restart=always

ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx2048M -jar minecraft_server.jar nogui

ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say SERVER SHUTTING DOWN. Saving map..."15'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "save-all"15'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "stop"15'
ExecStop=/bin/sleep 2

[Install]
WantedBy=multi-user.target

What everything does here is beyond the scope of this how-to, but you may need to adjust some of this for your particular system. Using Oracle Java 8 on Ubuntu 15.10, though, this worked for me. You'll notice the reference to minecraft_server.jar. Using the symbolic link keeps us from having to update the unit file when Mojang releases a new version. Instead, we can just stop the server(s), replace the file and symbolic link, and restart the server(s). It also facilitates running multiple servers with a single unit file. As long as every server has a similar symbolic link, there's no need to reinvent the wheel for each instance.

To start the server service, we just need to create a symbolic link and start it. First, though, we'll switch back to our own user.

exit
sudo ln -s /opt/minecraft/minecraft@.service /etc/systemd/system/minecraft@.service
sudo systemctl start minecraft@creative.service

Notice that the directory name we chose for our server in the beginning, creative, appears here after the @ sign. This is important and is what allows us to use a single unit file and have multiple servers running simultaneously.

You can check on the status of your server by using the following command:

systemctl status minecraft@creative.service

Assuming everything is up and running, you can now connect to your server via rcon or jump in and start playing. Enjoy!

By the way, in order to have multiple servers going at once, all you have to do is set up your second (third, fourth, etc.) with a different port. Make sure your rcon port is also different. All of your servers should then be visible.

One final thing: to have your server start automatically when your computer starts up, copy the minecraft@.service to /lib/systemd/system/ and then enable the server as follows:

sudo cp /opt/minecraft/minecraft@.service /lib/systemd/system/.
sudo systemctl enable minecraft@creative.service

Your server should start up automatically upon reboot.

SSH to a Local Bitnami VM

I'm using a Bitnami Virtual Appliance (MEAN stack) for development purposes, and I was having a trouble connecting to it via SSH. Finally found the key. Here's what you need to do to enable

$ sudo mv /etc/init/ssh.conf.back /etc/init/ssh.conf
$ sudo start ssh

and disable

$ sudo stop ssh
$ sudo mv /etc/init/ssh.conf /etc/init/ssh.conf.back

the SSH server.

Rip a CD using VLC

VLC lets you rip CD audio, but you have to do it one track at a time. Here's a handy batch file that rips the whole CD at once. Just put this in the folder that you want the tracks ripped to and set it loose!

@ECHO OFF

setlocal ENABLEDELAYEDEXPANSION

SET /a x=0

FOR /R D:\ %%G IN (*.cda) DO (CALL :SUB_VLC "%%G")
GOTO :eof

:SUB_VLC
call SET /a x=x+1

ECHO Transcoding %1
REM Here's where the actual transcoding/conversion happens. The next line
REM fires off a command to VLC.exe with the relevant arguments:
CALL "C:\Program Files (x86)\VideoLAN\VLC\vlc" -I http cdda:///D:/ --cdda-track=!x! :sout=#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=44100}:std{access="file",mux=raw,dst="Track!x!.mp3"} vlc://quit

:eof
Rip CD with VLC.cmd

Crashplan Central “Sea” List

I'll update this as I encounter more. I couldn't find a list online, so I'm starting one. I'm adding these to the "skip" list of my web filter to keep backup running smoothly. I didn't think they changed, but I've had a couple change on me in the last couple of months, so I just keep monitoring it.

aub-sea.crashplan.com [162.222.41.101]
cea-sea.crashplan.com [162.222.40.18]
cia-sea.crashplan.com [162.222.40.38]
cjb-sea.crashplan.com [162.222.41.48]
crc-sea.crashplan.com [162.222.40.215]
cya-sea.crashplan.com [162.222.40.118]
ddb-sea.crashplan.com [162.222.41.19]
dkd-sea.crashplan.com [162.222.41.181]
dmf-sea.crashplan.com [162.222.42.177]
dnc-sea.crashplan.com [162.222.40.196]
dua-sea.crashplan.com [162.222.40.99]
epb-sea.crashplan.com [162.222.41.80]
eqa-sea.crashplan.com [162.222.40.80]
erf-sea.crashplan.com [162.222.42.203]

Cracking an Excel Protected Sheet Password

This came in handy today. Ever protected a sheet with a password, but then you couldn't remember the password? Here's a good solution (just don't use it for nefarious purposes!). I didn't come up with this. I just found it. I don't know who did, but it's clever.

Add this little VBA script and set it loose. It took about 5 seconds to unlock my locked sheet.

Sub PasswordBreaker()
    'Breaks worksheet password protection.
    Dim i As Integer, j As Integer, k As Integer
    Dim l As Integer, m As Integer, n As Integer
    Dim i1 As Integer, i2 As Integer, i3 As Integer
    Dim i4 As Integer, i5 As Integer, i6 As Integer
    On Error Resume Next
    For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
    For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
    For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
    For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
    ActiveSheet.Unprotect Chr(i) & Chr(j) & Chr(k) & _
        Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
        Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
    If ActiveSheet.ProtectContents = False Then
        MsgBox "One usable password is " & Chr(i) & Chr(j) & _
            Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
            Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
         Exit Sub
    End If
    Next: Next: Next: Next: Next: Next
    Next: Next: Next: Next: Next: Next
End Sub

EDIT: Turns out there's a faster way (6 times faster, supposedly)

Sub FindPassword()
    Dim c1 As Integer, c2 As Integer, c3 As Integer
    Dim passwd As String
    On Error Resume Next
    For c1 = 64 To 95
        For c2 = 64 To 95
            For c3 = 64 To 95
                passwd = Chr(c1) & "...." & Chr(c2) & "...." & Chr(c3)
                ActiveSheet.Unprotect passwd
                If ActiveSheet.ProtectContents = False Then
                    MsgBox "Unprotected using password: '" & passwd & "'"
                    Exit Sub
                End If
            Next
        Next
    Next
End Sub