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.

 

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.

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.