Installing Craft CMS, Statamic and Perch Runway on Laravel Valet

A long time ago one of my favorite things to do on the web was to explore content management systems. It still is.

Background

Around 1999, I used to visit my friend and play around on PC computers. We’d install scripts like Francisco Burzi’s phpnuke just for the fun of it. View source and installing programs was how I learned to build websites. The web in those day was an exciting time. Today is no different. Twenty years later, I’m still excited about the web. Tonight let’s setup a new development environment and try out a few modern content management systems.

Today, alternatives to Drupal and WordPress have never looked better. To escape the orbit of WordPress and its tangled web of backwards compatible code. To keep structured content and avoid Drupal complexity. It is possible. Of course there is beauty and utility in the big planets. Each has its place and purpose. Yet life and real innovation is happening on smaller worlds. These alternative tools help writers create rich media experiences and inform the UI designs in more popular tools. Drupal Gutenberg and WordPress Gutenberg give editors new tools to share stories. Yet, so far Gutenberg has fallen short on accessibility and structured content. It is worth while to demo the competition and check out the alternatives. Plus for me it’s fun to tinker and play.

Composer Optional but recommended. Composer is like npm the package manager for JavasScript, but PHP.

We’ll use brew to install PHP, MySQL and composer to install Craft and Statamic. If you need to get that setup first please go here, here and here

Back yet? OK. Super. Let‘s takeoff.

Install PHP

Pretty easy to install PHP. I only needed to run this command:

brew install php

brew services start php

That was easy. To test, run command php -v Hmm. PHP 7.1.9. What happened? I thought brew installed 7.3 the latest version. Oh yea, I remember. macOS Mojave includes PHP 7.19. I could use that, but since this is an experiment I figure what the hell. Lets try the latest version of PHP circa February 2019. What could go wrong?

To point to PHP 7.3 I added PATH=/usr/local/Cellar/php/7.3.2/bin:$PATH to my bash .profile file.

Boot up nano, my terminal text editor of choice, open the file nano ~/.profile and paste in the path and save. To activate, restart iTerm or reload your bash file by entering source ~/.profile from the command line and hit return.

MySQL is configured to only allow connections from localhost by default

To connect run: mysql -urootTo have launchd start mysql now and restart at login: brew services start mysqlOr, if you don't want/need a background service you can just run: mysql.server start==> Summary/usr/local/Cellar/mysql/8.0.15: 267 files, 234.6MB

Please do change your the root user’s password.

MySQL version 8 almost caused a big crash and burn. Apparently, it has a new authentication plugin for database connections that isn’t widely supported yet. Stack Overflow to the rescue. Although I found many posts Alexander Diachenko explained what was going on and offered a solution.

The error happened because MySQL 8.0.4 changed its default authentication mechanism from mysql_native_password to caching_sha2_password. One of the ways to fix the issue is to run mysqld with additional option:

mysqld --default-authentication-plugin=mysql_native_password

In short, for now MySQL 8 isn’t really usable out of the box with most existing client implementations.

Bit of a drag but not a deal breaker. I needed to up find my.cnf file. How to do that? With a little grep magic on the command line. Thanks to a Carpentries Unix Shell workshop I could use a little grep magic.The Carpentries teach foundational coding and data science skills to researchers worldwide. A fantastic group offering free lessons on python, Git, R programming to increase digital literacy among researchers.

OK. That was kind of scary, but made it. You may decide to not go with bleeding edge versions of PHP and MySQL and that’s ok but I learned some new tricks. Onward.

Install Laravel Valet

For almost five years I’ve been using MAMP Pro to run my local server. I’m comfortable with it, but for the sake of exploration, and to make things more difficult I decided to install laravel valet. Once I got it running I see why its so popular. One benefit is I can run multiple hosts concurrently.

Of course Laravel Valet is optional and Craft, Statamic and Perch Runway can run with MAMP. Skip this section if you don’t want to venture into Laravel land, but since Statamic recommends running it, and you’ve made it this far already I think you’re an adventurous developer type so why not?

Back to the terminal and run the following command composer global require laravel/valet . After it finishes downloading run valet install command. This will configure and install Valet and DnsMasq, and register Valet’s daemon to launch when your system starts.

There is no need to run valet start or valet install ever again once the initial Valet installation is complete. Although knowing some of these commands will help.

valet start

valet stop

valet restart

valet link - used to serve a single site in a directory and not the entire directory. I prefer park

valet park - any project you create in your parked directory will be served with the http://folder-name.test convention.

I want to run more than one host on my computer so I’ll need to use valet park.

Create a new directory on your Mac by running mkdir ~/Sites or if you already have it just cd ~/Sites and run valet park. This command will register your current working directory as a path that Valet should search for sites.

That’s all there is to it.

Now, any Laravel project I create within my “parked” directory will automatically be served using the http://folder-name.test convention. Cool!

Secure Sites

By default, Valet serves sites over plain HTTP. However, if you would like to serve a site over encrypted TLS using HTTP/2, use the secure command.

For example, if your site is being served by Valet on the craftcms-site.test domain, you should run the following command to secure it:

valet secure craftcms-site which creates configuration files.

craftcms-site.testperchrunway-site.teststatamic.test

To “unsecure” a site and revert back to serving its traffic over plain HTTP, use the unsecure command like so.

Welcome to Craft CMS! Run the following command if you want to setup Craft from your terminal:

~/Sites/craftcms/craft setup

Looking good. Now run the command craft setup

$ Which database driver are you using? [mysql,pgsql,?]:

and had to make a choice: use MySQL or PostgresSQL.

I haven’t used Postgres before so I’ll save that for another day. At the moment, I have enough to learn with Craft, Twig, Laravel Valet (might as well see what that’s about and not use MAMP.) and keeping some time left over for my mental and physical health. Plus after that trouble with the caching_sha2_password MySQL 8.0 I wasn’t going to play around with fire twice.

$ Using version ^1.0 for statamic/cli$ ./composer.json has been updated$ Loading composer repositories with package information$ Updating dependencies (including require-dev)$ Your requirements could not be resolved to an installable set of packages.$ friendsofphp/php-cs-fixer v2.4.0 requires php ^5.6 || >=7.0 <7.2 -> your PHP version (7.3.2) does not satisfy that requirement.$ Installation failed, reverting ./composer.json to its original content.

Oh well. Looks like I’ll need to wait to use composer to install Statamic until php-cs-fixer supports PHP 7.3. (Note php-cs-fixer v.2.4.1 does support PHP 7.3, but the brew repository hasn’t updated it at the time of this writing.

Guess this is what happens when living on the edge. I’m still happy. I’ve got Laravel Valet installed and can run Craft CMS over https. I’ll explore it first, and then try out Statamic in the near future.

Wait. Wait. Hold your horses. I got an idea.

Instead of using composer how about if I just download the zip file and follow the instructions on the Statamic site.

Download the latest version of Statamic. Like Craft and Perch it is free for local development.

Unzip files into your root folder

Run the Trailhead Installer. Statamic has a little tool that will check your environment for all the necessary requirements, file permissions, locales, and help you get your first User created.

head to~/Sites/statamic-site/installer.php follow the instructions and after that’s done delete installer.php

Run valet secure statamic-site and login to the Control Panel at https://yoursite.test/cp and voilà now we have Statamic running over SSL.

Now both Craft and Statamic are installed.

What’s next? How about installing my favorite CMS Perch Runway!

Installing Perch Runway

I downloaded a free trial version of Perch Runway to run locally and copied it to my ~/Sites folder. Remember I have Laravel Valet parked looking for any sites with a .test domain so the server is ready to go.

Out of the box, Laravel Valet supports for Craft, WordPress, Statamic and many others, including Drupal and WordPress, but it does require a custom driver for Perch Runway.

Fortunately, the Perch community is generous (like so many communities on the web) and Ryan Gittings, a percher from the UK posted a custom driver he wrote. In the perch community, developers are called perchers and we like to perchify a site. I owe him a beer, coffee or some kind of tip. Follow him on twitter. Or join the Perchology slack community.

Note: I compared Ryan’s custom driver to the SampleValetDriver.php provided by Laravel and decided to put back the isStaticFile function in case I need to run plain html static files. I forked his repo to my GitHub account.

In the Drivers folder I now have two files it looks something like this:

Next step

Now that I’ve got Craft, Statamic and Perch Runway served locally on Laravel my first thought would be do a compare and contrast and share what I learn about each cms. Including WordPress and SquareSpace I’ll have a roundup of best tools to take your site to the future and beyond.

Thank you for reading. If this setup doesn’t work on your mac or you have any comments reach me on Twitter.