Quick and Dirty PHP 7.0 set up on Ubuntu 14.04 with APCu

This is how I got PHP 7 and APCu running on one of the entry-level Digital Ocean droplets:

PHP 7

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php-7.0
apt-get update && apt-get purge php5-fpm && apt-get --purge autoremove && apt-get install php7.0-fpm php7.0-mysql php7.0-gd php7.0-dev

If you need additional php7.0 packages, check the list:

sudo apt-cache search php7

In my enabled nginx site configs (I'm sure there's a place to put this globally, but I only had a couple of sites, so I didn't bother researching that for now):

Replace:

fastcgi_pass unix:/var/run/php5-fpm.sock; 

With:

fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

APCu

git clone https://github.com/krakjoe/apcu

Follow the instructions for building APCu in the INSTALL file

In addition to the updates to php.ini described in the INSTALL file, update the 'extensions_dir' directive:

extension_dir = "/usr/lib/php/20151012/"

Do the same for both the FPM and CLI versions of php.ini

Restart PHP-FPM and Nginx:

sudo service php7.0-fpm restart
sudo service nginx restart

That did it for me. With APCu installed, I can continue to use APC as the driver for session and cache in my Laravel 5 apps when Memcache, Redis, etc. are overkill.

 

Using the Laravel Homestead "serve" command with Oh-My-Zsh

So I run an  "extras" script  after installing Laravel's Homestead that installs LDAP, Oracle Drivers, and Oh-My-Zsh among other things. But afterwards, I cannot run the "serve" command in the homestead VM to add new Nginx sites. I've finally figured out that the serve command is actually a bash shell alias function thingy inside .bash_aliases, so it's being ignored once I switch to Oh-My-Zsh.

Simply copying the serve function to .zshrc doesn't work due to some apparent syntax differences with bash and zsh. After digging around a bit, I've slightly modified the function to work now with zsh inside .zshrc:

Hopefully this helps someone else, or maybe someone has a better solution altogether.

Controlling Laravel Homestead VM From Any Folder in Terminal

Having a single Vagrant VM for all of my projects is nice, but I was used to controlling Vagrant from within a project's folder in Terminal and not having to go back to the central Homestead folder to run things like vagrant up or vagrant reload.

Adding these to my Oh-My-Zsh config (.zshrc) seems to do the trick:

alias devup="cd '/Users/gtaylor/Sites/Work/Homestead' && vagrant up && cd - 1> /dev/null"
alias devreload="cd '/Users/gtaylor/Sites/Work/Homestead' && vagrant reload && cd - 1> /dev/null"
alias devdown="cd '/Users/gtaylor/Sites/Work/Homestead' && vagrant halt && cd - 1> /dev/null"

I'm using these in conjunction with `alias dev='ssh vagrant@127.0.0.1 -p 2222'` from the Homestead documentation.

"Extending" Laravel's Homestead

I put off moving my existing vagrant dev VMs over to [Laravel's Homestead](http://laravel.com/docs/homestead) for a couple of reasons:

  1. It doesn't completely match my production environments (Ubuntu 14.04 instead 12.04, PHP 5.5 instead of 5.4, Nginx instead of Apache).
  2. I knew I'd need to customize the VM anyway and I already had that worked out with my existing VMs (note the plural).

Laravel Application Logs and Logrotate

Depending on usage, errors, and what you’ve chosen to log, the Laravel application log(s) can really grow after a while. With Laravel 3 and initially with Laravel 4, new log files were created every day by default, which kept them small and easy to search, but now Laravel 4 defaults to a single log file (which I prefer). Logrotate is a common utility on linux servers to handle the backup and rotation of server logs (Apache, syslogs, etc.) and it’s really simple to add additional logs/folders for Logrotate to handle. There’s a nice Digital Ocean tutorial for using Logrotate on Ubuntu 12.10, but here’s a quick and easy run through on how to use Logrotate with your Laravel logs: