Migrate WordPress on FreeBSD from php5 to php7

PHP7 offers performance improvements that anyone hosting WordPress site will want to enjoy.  Moving a B.A.M.P. install from php5 to php7 is simple enough.

First install the packages for php7:

  • pkg install mod_php70
  • pkg install php70-mysqli
  • pkg install php70-session
  • pkg install php70-ctype
  • pkg install php70-xml
  • pkg install php70-curl
  • pkg install php70-ftp

mod_php70 is the php7 module for apache.  We also need the mysqli package (don’t forget the “i”) otherwise we will get database connection errors.  Session handles sessions funnily enough.

Your not done yet even though your site may seem to work at this point.  ctype is used by jetpack, without this your jetpack dashboard won’t work.  I forgot why I need XML as I didn’t have a guide like this one to follow…  Finally if you use auto updates from within WordPress you need curl and ftp so you can download and install updates.

Now you have everything you need.  Time to enable php7 in the apache configuration in “/usr/local/etc/apache24/httpd.conf”

Remove php5 add php7:

  • LoadModule php5_module  libexec/apache24/libphp5.so  << remove this
  • LoadModule php7_module  libexec/apache24/libphp7.so << add this

Allow php to use the mysqli extension

  • Edit /usr/local/etc/php.ini
  • extension=php_mysqli.dll << remove the semi-colon (;) from the start of this line

Restart apache and you should now be running on WordPress on Apache 2.4 and php7 under FreeBSD.

 

Arch Linux – dual boot install via VirtualBox

So I’ve replaced all the hard drives in my desktop.  I have 8x SATA ports and 4x SSD drives.  Only 4 of the ports are 6 Gb/s on this board so the plan is this

Intel (6 ports, 2x 6 Gb/s, 4x 3Gb/s, AHCI or RAID 0, 1, 10 support)

  • 6 Gb/s ports 1 and 2 in Raid 0 with 2x Silicon Power S55 drives – Win 10
  • 3 Gb/s ports, 3 and 4 for 1TB SATA 7.2K drives, port 6 for SATA DVD-RW

Marvel (2x 6 Gb/s ports, AHCI support)

  • 6 Gb/s ports 1 and 2 with 2x Silicon Power S55 drive – Arch linux using LVM for Raid 0

I decided I wanted to do the Arch install through VirtualBox after my recent experiment using VMware to make a boot USB install.  The reasons are pretty much the same so go read that one if your wondering why….

Task 1 – Get VirtualBox to talk to the hard disks directly

I mostly use VMware Workstation, so this one surprised me, in the GUI of VirtualBox at the time of writing this blog, there is no way to directly map a hard disk.  So after a bit of googling I found this blog.  There you will find out how to make a .vmdk that maps directly to a physical disk.   In my case I made 2 vmdk’s.  Next you’ll need to start VirtualBox as an administrator so it has rights to use those disks.  Create a VM that has the Arch install .ISO in the virtual CD drive, add the 2 disks you created.  I also set the machine to emulate a UEFI system and not a BIOS, then start the VM.

 

Task 2 – Install:

So we are good to get started.  As you can see in the background I’ve written out my partition scheme as its a bit complex and I have the Arch Install docs open in case we need to check anything along the way.

01 - partition 1n2

This is gdisk listing the 2 drives.  I’m formatting the disks as GPT disks (not MBR).  I can show you my partition layout as its seen in Windows 10 just by refreshing windows disk manager.  This is after writing /dev/sda and before I repeated the steps on /dev/sdb, 1G for boot, 18G for swap on each disk and 92.79GB for LVM.

03 - windows confirmation

Then comes formatting of the partitions.  As this is a UEFI system our boot partition (and boot.bkp on the other disk) need to be FAT32.  I assign sda3 and sdb3 as “physical volumes” so that I can create a volume group on them.

04 - filesystems

Creating the “Volume Group”, and then finally the “Logical Volume” as a striped disk.  What I like about this approach is the volume group has 2 disks, but I can create another partition as a mirror, so if I want to have my home directory on a mirror I can still use the same volume group.  With that in mind I’ve left some space for later.  The data alignment is supposed to help with SSD rewrite scenarios.

05 - lvm

I’m formatting the logical volume with xfs.  Its the fastest option for the workload I’m going to put on it, also it supports discard/fstrim which is important in an SSD system.

06 - root-xfs

Now we mount the disks so that we can continue the install.

07 - mounts

Install packages through pacstrap

Problem Time:

So on the face of it this worked, but it doesn’t.  Essentially its added a UEFI boot entry to the UEFI bios of the Virtual Machine and not the actual hardware we are running on.  So later we are going to have boot the USB key, mount the boot partition and run “bootctl install” again to actually add an entry to the physical hardware’s boot menu.

Carry on Regardless:

We have to edit mkinitcpio.conf, we need sd-lvm2 support in our ramdisk to start the raid that the root partition lives on.  xfs is not needed its covered by filesystems, I just did that out of habbit 🙂

I also installed  intel-ucode and some other things I’ll want later

Adding the boot entry so that the microcode update runs.  Instead of using PARTUUID we use UUID as we don’t have a single partitions UUID we can put here, instead we put the UUID of the LVM logical volume as it will be when the LVM module loads.

Before the final reboot I enabled NetworkManager and FirewallD, then reboot and test the machine boots in VirtualBox (it does).

Finalize the Install:

With that the install is done, depending on your UEFI firmware it may be bootable, mine was not yet, so I booted an arch key, mounted the root and boot partitions, then rant bootctl install again.  After this the machine would boot to windows or Linux and I could pick whichever option I preferred from the bios menu (F8 on my machine)

It should be possible while in windows to start up the VM and access your Arch Linux install.  If you have samba or FTP running in Arch you then have a nice way to share files between Windows and Linux, enjoy!

Installing Arch Linux on a USB Key for UEFI systems

Task:

Install Arch on a UEFI bootable USB drive or SD card so that it can be used on machines that have we don’t have the luxury of changing the local disk partition structure (corporate IT policy, low space, etc.)

Hardware:

So I have this 32GB USB 3.0 Key that I’m going to use, it seems to perform well enough to be usable without being frustrating.  Sure is ugly though!  I’ve ordered a nice fast SD card that will take over when it arrives.  If your UEFI firmware can read the SD card it will boot from it using the same methods.

 

I’m going to use a virtual machine for the install, you could do it on the real hardware or use Virtualbox or similar.  You don’t need it, but it does mean you don’t have to present the core OS drive to the VM so you can’t accidentally delete your Windows install.  Also you can use the host PC fully while you go through the installation process.  Finally it saves you messing about with WiFi, you can do that later which is handy, especially if you need to install a package or files before you can get WiFi working, so for me its a big benefit!

I’m using VMware Workstation 10.x.  The VM is setup is simple, some memory, some CPU’s, a local disk that we won’t use, our Arch Linux .iso is attached to the virtual CD/DVD drive, we use NAT so that our VM has network access and that about it.

After booting the .iso I’ll insert the USB Key and pass it through to the VM then, check dmesg to see what it is called.  So for this install its going to be /dev/sdb that we are working with.  If i run ‘fdisk -l’ the only disks I see are the 512MB virtual disk and the 32GB USB key, so my Windows SSD is nice and safe.  This VM can’t delete what it doesn’t know about.

Install – Disk Partitions:

First we will change the keyboard, then partition the disk as a GPT disk with a UEFI boot partition (FAT 32)

  • # loadkeys /usr/share/kbd/keymaps/i386/qwerty/uk.map.gz
  • # gdisk /dev/sdb

In gdisk I issued command o, which creates a new GPT partition table, the I created the following partitions.

  • sdb1 512M EF00 for /boot
  • sdb2 1024M 8200 for swap
  • sdb3 (all remaining space) 8300 for /

Then we create some partitions, the boot partition absolutely must be fat32 as that is what the UEFI firmware will expect to see.

  • For /boot
    • mkfs.fat -F32 /dev/sdb1
  • For swap
    • mkswap /dev/sdb2
    • (optional: if you want to use during the install) swapon /dev/sdb2
  • for /
    • mkfs.ext4 /dev/sdb3

Install – Mount and Select a Mirror: 

After mounting the partitions and selecting a mirror start the file downloads.

# pacstrap -i /mnt base base-devel

On my laptop this amounted to 222.3 Mb of download which is good as I’m using my smartphone as a WiFi hot spot for this install.  One package did fail on me for too slow data transfer so I added another mirror, that didn’t work either, so I replaced the mirrorlist file with mirrorlist.old, then after i got the file I put it back to just heanet which is my local mirror.

Make an fstab with UUID’s as we don’t know if this key is always going to be sda or sdb at least we should be able to find our paritions by UUID regardless of the system.

  • #genfstab -U -p /mnt >> /mnt/etc/fstab
  • # arch-chroot /mnt
  • # nano /etc/locale.gen
  • # locale-gen
  • # echo LANG=en_US.UTF-8 > /etc/locale.conf
  • # export LANG
  • # ln -s /usr/share/zoneinfo/Europe/Dublin > /etc/localtime
  • # echo sanlinux > /etc/hostname
  • # passwd
  • # useradd -m -G wheel,power -s /bin/bash karl
  • # passwd karl

Now we are ready to setup the boot loader, as I’m running in a VM that does not emulate UEFI it tells me “Not booted with EFI, skipping EFI variable setup” but that appears to affect nothing.

  • # bootctl install
  • # blkid -s PARTUUID -o value /dev/sdb3 >> /boot/loader/entries/arch.conf

Then use nano to edit the file so that it looks like this

  • title Arch Linux
  • linux /vmlinuz-linux
  • initrd /intel-ucode.img
  • initrd /initramfs-linux.img
  • options root=PARTUUID=the-id-that-was-in-the-file rw

Install some additional requirements, intel-ucode is for CPU microcode updates, networkmanager is my preferred way of networking, firewalld is a handy front end for iptables and bash completion is very helpful everywhere but especially with firewall-cmd.  mesa for opengl,

  • # pacman -S intel-ucode
  • # pacman -S networkmanager
  • # pacman -S firewalld
  • # pacman -S bash-completion mesa

So now the moment of truth, I rebooted windows, hit F12 a bunch of times to get a boot menu, picked the USB key and 10 seconds later I had this

Great, so I’ve one remaining issue, my WiFi card needs firmware, so I downloaded it to an SD mounted it and copied it to the right folder, job done.   Expect more arch Linux posts in the future.  Now because its Arch I need to go off and install my favorite window manager and apps.  I can’t wait for that SD card to show up so that I’ll have 64 GB to play with at reasonable speeds and no ugly USB Key!

 

Killer Wireless in Dell Inspiron 7000 2-in-1

I’m unhappy with my wireless performance on my laptop so I decided to upgrade.  If you decide to do this it is at your own risk, I’m not recommending it, just documenting my experience.

Hardware:

I’ll explain why later but for now above is the new card (Killer Wifi 1535) and the old one (Dell 1708/Broadcom 43142).  Both cards provide Wifi and Bluetooth functions.

 

Taking apart the Dell 7000 2-in-1 is quite easy with care, you have no less than 10 Philips head screws on the base, removed them, then you need to (gently) pry the plastic base lose.  There are a number of plastic tabs all around the edge , I used a plastic guitar pick to free them, if you get stuck don’t push it, just try again from the other side, take your time.

And we’re in…

Before you do anything else, remove the 2 remaining screws holding the large black battery and take it out!

Between the fan and the silver coin-cell battery you will see our WiFi card with a couple of aerials attached (black and white wires)

Lift the aerial until they detach from the card.  Unscrew the black screw holding the card in place, the card will lift up at an angle, pull it out.  The new card is a bit longer because the old one doesn’t use the full slot available to it.  I would strongly recommend attaching the aerial cables before putting the new card in.  When they are attached put the card back in at the same angle, then push it down and hold it in place while you put the black screw back in.  (Magnetic head screw-driver or an extra pair of hands might be required)

Put things back together, battery first with 2 screws, then click the plastic back on, then put the 10 screws in the base.  Its tempting to boot the notebook/tablet before putting the plastic back on but I’d advise against running this machine open!

Software:

On booting Windows 10 the device was automatically added and installed as a WiFi card using a generic driver.  But we want the official driver and the Bluetooth driver also.  Download and install them and run through the configurations.

Initial testing:

This test is on 2.4 GHz channel 1 which has the least interference at my location.  From the same location in my home previously my best download was 67 Mbps, so already I’m seeing a 37% improvement in download in typical usage, upload is limited by the broadband connection.  5 GHz easily breaks into the hundreds, so both together (more on that in a later post) should be able to get 150 – 250  Mbps in normal usage.  100 Mbps should be possible at the edges of the range where previously I would get 20 Mbps.

Finally:

The WiFi connection is faster and more stable, the Bluetooth is so much better for listening to music.  The combination of more stable network connection and Bluetooth connection means that voice calls and Skype is a far nice experience.

The old card was such a struggle to use with Linux, so I’m happy to report I’ve also had some success getting Arch Linux to work with the card, but that’s a story for later.

 

Moving from Arch Linux to FreeBSD..

..and from a local web-server to a cloud based virtual machine.

So I’ve been running this site on an old Dell D400 laptop for a while.  Arch Linux has been the operating system of choice.  This machine has performed admirably as a web server for many months now.  But its single core 1.6 Ghz processor and 5400 RPM hard disk are limiting factors for performance and expansion.  Lets migrate it to the Cloud…

First step was to select a place to host the site from.

I went with a Digital Ocean droplet, I was able to quickly sign up for a single core machine with 512Mb of RAM and 20 Gigs of SSD storage  for $5 per month ($6 with weekly backups).  The lower amount of memory was not such an issue as Arch was using maximum of around 400Mb and that is running more services that just the website.  I could pick a data-center in London and speeds to and from droplet are clearly faster than my broadband’s 240 down and 24 up.

Operating System:

I’m a big fan of Arch Linux, but at this time Digital Ocean don’t offer it and to be honest I’d never expect them too.  CentOS is a solid choice and familiar to an R.H.C.E. like me, Ubuntu is also available but while I’ve used it a lot I just don’t enjoy some of the problems that crop up and how you need to solve them.  So in the end I decided to go with FreeBSD.  The choice came down to this, I can work with that operating system faster and the base install seems to be more memory efficient which should not be a factor, but its always better to have more RAM than you think you’ll need.

Deployment:

So the droplet was created very quickly, I had to generate an ssh key and associate it with the droplet first.  Then I still had some trouble logging in.  This came down to the fact that its not very clear that you need to use that key to login as the user FreeBSD then use ‘su’ and ‘sudo’ as needed, I eventually found out through Digital Oceans blog, would be nice if it said so on the creation screens.  Once that was out of the way we quickly install our web-server/database/language stack setup each component and wrote some test pages to make everything worked.

Finally I moved across this WordPress blog in about 2 minutes, using tar, gzip and ftp and it worked pretty much straight away.  Its so nice when your planned migration even a small one like this actually goes like clockwork!

Next:

So I will be blogging more instead of maintaining the servers, next I want to see what the state of MongoDB is on FreeBSD I’ve a feeling it isn’t going to be pretty, but time will tell.

Grimes, Dublin Concert

So I took some time off work because I had days to use up before the end of March.

I went to the Grimes concert in Dublin’s Olympia Theatre, it was a weird one, the show was cut short due to technical issues.  During one of the tunes we all heard these loud bangs, Grimes went crazy on stage and stopped the song, she explained she was getting electrocuted and wanted cables changed.  Technical guy comes out and changes cables, song starts again and problems came back.  Eventually they did a song or two without this “pedal” that was causing the issues, before they decided that the pedal was a fault and could not fix it.   They did a final song without the pedal and called it a night.

I think the songs without the pedal where actually pretty damn good and the ones before the issues too, the support act “Hana” was pretty cool too.

A bit weird though, you get this really quite good show, but then you also feel like it would have been off the charts without all the problems.  It is true to say that everyone in the crowd was supportive during the issues, I heard one guy boo (there is always one) but he was quickly drowned out by 1000+ people cheering.

Also had St. Patrick’s day yesterday, kept it simple, local parade, enjoy the sunshine, home cooked dinner with the fiancée and a couple bottles of wine.

Anyway, need to get my brain out of this relaxed mood so I’ve got a FreeBSD server to deploy to serve out a WSGI/Python website.

Later…

FreeBSD, the good, the not so good, the next step

So about a week into using FreeBSD I have to say I really like it.

I went from “current” which is a stupid name for a future cutting edge version to “stable” which is the current recommended release version.

Basic tasks, editing files, starting and stopping services, network configuration changes are all straightforward and logical.

The pkg package manager is pretty cool, port works fantastically too.  It still is odd if your used to a single package manager on a system, but it works and works well.  You get odd situations, like the unbound situation.  Its part of the base system, already present, but for more than the basic config you are recommended to install the port.  So after a bit of compiling you end up with a few more config files.  I’m not sure if the compile turns on additional features but it seems a bit wasteful.  Regardless I did it and have unbound configured the way I want.

So I planned to do more testing this week, setup a NIS and LDAP server for example, but then I went and applied for a Linux/VMware job.   So I guess I need to study for that first.  Should be interesting to see how much Red Hat I’ve forgotten since May (probably not much) and how much VMware I’ve forgotten since last weeks training course (probably lots)

Wish me luck….

First Steps with FreeBSD

I’ve decided that I want to learn a bit more about the BSD’s of today’s world.

Why? Well you see in my day-to-day I encounter a lot of ESX a bit of Windows and some Linux.  But a lot of hardware like a Force 10 switch a Compellent SAN or an Equallogic SAN appears to be running BSD under the hood.  While I’m comfortable enough with those environments there is always scope to learn.

As an aside I’ve noticed very low memory usage on a fresh FreeBSD install, so given say 4 VM’s with 256MB of RAM each I think you could quite easily provide all the required services (DHCP, DNS, LDAP, NFS) in a small amount of space and based on usage even drop the memory for each machine even lower.  Yea sure I could just buy a bigger SO-DIMM for my laptop but then what would I learn.

So I’ve started with one VM with 2x CPU’s and 512MB of RAM lets see what basics we can learn.

  1. Logging in as a user would not let me switch to root.  Solution, use vim to edit /etc/groups and add the user to the group wheel.
  2. What IP should I be connecting my ssh session too, ifconfig comes up with the goods

    [email protected]:~ # ifconfigem0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM> ether 00:0c:29:00:c3:e0 inet 192.168.193.137 netmask 0xffffff00 broadcast 192.168.193.255 nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL> media: Ethernet autoselect (1000baseT <full-duplex>) status: active

  3. How to update, issuing the command “freebsd-update fetch” returns an error about Fetching public key from updateX.freebsd.org failed.  So lets have a look at /etc/freebsd-update.conf shows everything is fine and also I can ping the server.  A quick google tells me that i’m running bsd-current which is effectively a future release.  People running bsd-stable (this should be called current but its called stable) can use freebsd-update.  So I’ll revisit this after I’ve had a chance to digest http://www.bsdnow.tv/tutorials/stable-current
  4. I selected dhcp when I installed, I want a fixed address now, so add a line like this ifconfig_em0=”inet 192.168.193.50 netmask 255.255.255.0″ and comment out the line ifconfig_em0=”DHCP” by placing a hash in front of it.  Then restart the interface with service netif restart and reconnect your ssh client to the new address.
  5. I can’t get on the internet now, so in rc.conf I also had to add my gateway defaultrouter=”192.168.193.2″ and also issue service routing restart  for the change to take effect.
  6. How do I install software?  pkg search mariadb, pick the package you want and pkg install  mariadb100-server, you can leave out the version number
  7. How do i find what the service is called and start it?  service -l lists all init scripts.  One on this list is called mysql-server, so service mysql-server onestart will get it going (just once), if we want to be able to issue start|stop|restart and also have it come up at boot we need to go to rc.conf and set mysql_enable to YES.   So with use vim /etc/rc.conf and add a line like this mysql_enable=”YES”
  8. We reboot with reboot, and shutdown with poweroff
  9. Checking everything works as it should after the reboot and it does

I have to say apart from the updates (my fault for going with Current and not Stable) this is all very straightforward and logical to this point.  Next on my todo list it to try out other services like apache, nfs, etc and see how small the test environment footprint could be.

Arch Linux: moving from php5 to php7

So as per usual I issued a pacman -Syu, then did a reboot to check everything is as it should be and well it wasn’t.   Apache was no longer starting as it was claiming that line 155 in the config file was wrong.

155 LoadModule php5_module modules/libphp5.so

I remember reading that arch had moved from php5 to php7 so this made sense.  I changed the line to the following

155 LoadModule php7_module modules/libphp7.so

That worked out as expected, the server was happy to boot up now, however on my homepage I got a warning that mysql support is not enabled in php.  So next we changed /etc/php/php.ini to removed the semicolon infront of

877 extension=mysqli.so

Restart apache, job done..

Arch Linux: Rolling distro fun

Arch Linux is great, change is great, except when you don’t know what has changed and why.

Case in point, my home server is up 100+ days, I update and reboot.  My web access is gone and SSH doesn’t work either.  When I regained physical access, I see both services are failed as they could not bind to the network card, that’s funny because samba, ftp and NFS all managed fine.  Why?

As I’m running systemd I was able to figure out the following with a few ‘systemctl status something.service’ commands.  sshd and apache come up before the network card, they retry but fail.  5 seconds later the network is up, so when I restart the services manually all works as expected.

Fixing it was a bit more messy.  Both systemd scripts are small and simple both specify ‘After=network.target’ that target doesn’t give away much.  I’m using NetworkManager so I changed both to ‘After=NetworkManager.service’.

Result, the services http/SSH start later but still too soon.  Appears NetworkManager has started but not completed its job yet.

Try again:

‘After=NetworkManager-wait-online.service’

This “service” starts when network manager completes its startup, so telling SSH and http that they start after this will ensure the network is up.

Fixed! until the next update 🙂