scottgruber.me

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.

Airplane taking off behind LAX

Background

Around 1999, I used to visit my friend and play around on 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 beginning of the web was an exciting time and it’s not so different different today. Our project today, twenty years later, is to setup a new development environment. And install 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 structure content. It is worth while to demo the competition and check out the alternatives. Plus for me it’s fun to tinker and play.

Note: At 2018 WordCamp LAX and Roy Sivan showed Gutenberg Object Plugin an innovative solution to save Gutenberg data as clean array. I posted my notes and installed it on Pantheon.io.

The purpose of this plugin is to save Gutenberg (New WordPress Editor) data as an array in the database which is accessible via the REST API… While the new UI for the WordPress Editor is amazing, the data as it is stored lends a lot to be desired with HTML comments as a basis for data.

the new systems show the viable ways to separate content from presentation and help developers. So much to explore. If only we could escape the pull of the big giants. Well today we can.

Laravel setup 9

Setup

Content Management Systems and Laravel Valet Links

Toolkit

Although this isn’t rocket science, some tools will help.

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.

Laravel setup 8

Install PHP

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

brew install php
brew services start php

Pretty 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.

Now when I ran php -v the results were PHP 7.3.2

Moving in the right direction. Next step was to install MySQL.

Laravel setup 7

Install MySQL

Once more, we turn to brew to install MySQL. Here’s those command.

brew install mysql

And wait while brew does its magic.

Then run.

brew services start mysql

And after a few nanoseconds, I saw this:

We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot
To have launchd start mysql now and restart at login:
  brew services start mysql
Or, 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

Change 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 happens because MySQL 8.0.4 changed its default authentication mechanism from mysqlnativepassword to cachingsha2password. 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.

Kind 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.

mysql --help | grep cnf

which resulted in:

order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

This version /usr/local/etc/my.cnf is the one we’re looking for since it had this text.

Default Homebrew MySQL server config

So I open with nano.

nano /usr/local/etc/my.cnf

and pasted the following line to load the older plugin.

default-authentication-plugin=mysql_native_password

and restarted mysql

brew services restart mysql

Last fix was to alter a couple of users I already had created in MySQL so they would use the older authentication protocol.

ALTER USER 'username'@'localhost'
IDENTIFIED WITH mysql_native_password
BY 'password';

FLUSH PRIVILEGES;

OK. That was kind of confusing, but found a fix. 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.

Laravel setup 6

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!

Securing Sites With TLS

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 in

~/.config/valet/Nginx 
craftcms-site.test
perchrunway-site.test
statamic.test

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

valet unsecure craftcms-site

Laravel setup 5

Installing Craft 3

Installation Instructions | Craft 3 Documentation and a very helpful article by Jalen Davenport.

composer create-project craftcms/craft ~/Sites/craftcms-site
Installing craftcms/craft (1.0.39)

Bunch of stuff downloads, while I went to sleep.

After waking up, feeding Ms. Fuzzy B Kitty and making myself a cup of fresh coffee I woke up the computer from its slumber, opened iTerm and saw:

   ______ .______          ___       _______ .___________.
  /      ||   _  \        /   \     |   ____||           |
 |  ,----'|  |_)  |      /  ^  \    |  |__   `---|  |----`
 |  |     |      /      /  /_\  \   |   __|      |  |
 |  `----.|  |\  \----./  _____  \  |  |         |  |
  \______|| _| `._____/__/     \__\ |__|         |__|

     A       N   E   W       I   N   S   T   A   L   L
               ______ .___  ___.      _______.
              /      ||   \/   |     /       |
             |  ,----'|  \  /  |    |   (----`
             |  |     |  |\/|  |     \   \
             |  `----.|  |  |  | .----)   |
              \______||__|  |__| |_______/

Generating a security key ... done (**************************)

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.

So, MySQL it is.

I created a database, created a user with the privileges Check on Craft site for user permissions to set.

I ran the setup wizard, created a user and logged into my first Craft CMS site over with SSL using Laravel Valet at https://craftcms-site.test Woo hoo!

Show Photo Welcome to Craft CMS

OK then! Next up is Statamic. With no database it should be easier right?

Laravel setup 4

Installing Statamic

https://docs.statamic.com/installing

composer global require statamic/cli

And got this result.

$ 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!

Laravel setup 3

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.

I created a MySQL database, created a user and opened my browser to http://perchrunway.test/perch/setup. 404 err or. No joy.

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

Fortunately, the Perch community is generous (like 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.

Ryan’s instructions to install was straightforward. Copy his custom drive to
Valet’s drivers folder here /Users/{your_username}/.valet/Drivers.

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.

From the iTerm in the Drivers folder I now have two files it looks something like this:

$ ~/.config/valet/Drivers 
$ PerchRunwayValetDriver.php
$ SampleValetDriver.php

I went back to and ran Perch Runways’ setup http://perchrunway.test/perch/setup, created a new user, logged in and was in. To add SSL, don’t forget to run valet secure perchrunway in the site’s root folder. To finish delete the setup folder. Perch will show a message on your diagnostics. and that’s about it.

Here is what it looks like from the command line for all three sites

 ~/.config/valet/Nginx
» ls -la
.keep
craftcms-site.test
perchrunway-site.test
statamic.test
Laravel setup 2

Next steps

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.