<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Chris Violette</title>
    <description>The latest articles on Forem by Chris Violette (@pixleight).</description>
    <link>https://forem.com/pixleight</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F202904%2F94c6bfb4-3edc-452c-9cca-b1bd5f328ce4.jpg</url>
      <title>Forem: Chris Violette</title>
      <link>https://forem.com/pixleight</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pixleight"/>
    <language>en</language>
    <item>
      <title>Local Craft CMS Development with Laravel Valet 🚀</title>
      <dc:creator>Chris Violette</dc:creator>
      <pubDate>Fri, 14 Aug 2020 00:21:44 +0000</pubDate>
      <link>https://forem.com/pixleight/local-craft-cms-development-with-laravel-valet-27f8</link>
      <guid>https://forem.com/pixleight/local-craft-cms-development-with-laravel-valet-27f8</guid>
      <description>&lt;p&gt;Craft CMS is a flexible, user-friendly content management system. There are many ways to run Craft on your local machine for development (such as MAMP or Docker), but I'm going to tell you about my current favorite — Laravel Valet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Contents&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Prerequisites - Installing Homebrew, PHP, and Composer&lt;/li&gt;
&lt;li&gt;Installing Laravel Valet&lt;/li&gt;
&lt;li&gt;Installing Craft CMS&lt;/li&gt;
&lt;li&gt;
Making More Projects - Get up and running fast with future sites!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Laravel? I thought this was about Craft! 😕
&lt;/h2&gt;

&lt;p&gt;It is! Laravel Valet, while being made by the folks behind Laravel, &lt;a href="https://laravel.com/docs/7.x/valet#introduction"&gt;can support many PHP-based frameworks&lt;/a&gt; — Craft CMS included.&lt;/p&gt;

&lt;p&gt;Valet is a local development environment for Mac — sorry Windows/Linux folks. Still, check out my next article in this series to learn about adding Laravel Mix to the — erm, &lt;em&gt;mix&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Rather than running a virtual machine à la Docker, Valet runs Nginx in the background and uses your local PHP and MySQL. This keeps your development environment very lean, only using about 7MB of RAM.&lt;/p&gt;

&lt;p&gt;However, Valet isn't a replacement for an isolated container environment, just an alternative if you want some easy-to-configure basics. If you need a containerized setup, that's ok, but &lt;strong&gt;this isn't the article for you.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🏗️ Prerequisites
&lt;/h2&gt;

&lt;p&gt;This article assumes you're comfortable with Terminal (or similar) to run commands. You should also be logged in as an admin user on your computer; some of these commands will require you to enter your Mac password.&lt;/p&gt;

&lt;p&gt;It also assumes you have &lt;a href="https://brew.sh/"&gt;Homebrew&lt;/a&gt; and &lt;a href="https://getcomposer.org/"&gt;Composer&lt;/a&gt; installed. If you don't, I'll walk through the initial setup below:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 Already have Homebrew and Composer installed? Skip ahead!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Homebrew, PHP, and Composer
&lt;/h3&gt;

&lt;p&gt;These installation instructions are accurate as of this writing, but I recommend checking Homebrew and Composer documentation for current details:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.brew.sh/Installation"&gt;Homebrew&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://getcomposer.org/doc/00-intro.md"&gt;Composer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Homebrew
&lt;/h4&gt;

&lt;p&gt;To install Homebrew (a package manager for macOS), open up Terminal and run the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;/bin/bash &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://raw.githubusercontent.com/Homebrew/install/master/install.sh&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Follow the instructions that appear; the script will pause at times to explain exactly what it's doing and confirm before doing it.&lt;/p&gt;

&lt;h4&gt;
  
  
  PHP
&lt;/h4&gt;

&lt;p&gt;Once Homebrew is installed, run the following command to install PHP. As of this writing, it will install PHP 7.4.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;php
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Confirm PHP is installed with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;php &lt;span class="nt"&gt;-v&lt;/span&gt;
&lt;span class="c"&gt;# PHP 7.4.X&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Composer
&lt;/h4&gt;

&lt;p&gt;Finally, with PHP installed, run the following to install Composer, a dependency manager for PHP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;php &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s2"&gt;"copy('https://getcomposer.org/installer', 'composer-setup.php');"&lt;/span&gt;
php &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s2"&gt;"if (hash_file('sha384', 'composer-setup.php') === 'e5325b19b381bfd88ce90a5ddb7823406b2a38cff6bb704b0acc289a09c8128d4a8ce2bbafcd1fcbdc38666422fe2806') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"&lt;/span&gt;
php composer-setup.php
php &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s2"&gt;"unlink('composer-setup.php');"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Installing Valet
&lt;/h2&gt;

&lt;p&gt;Current installation instructions can be found &lt;a href="https://laravel.com/docs/7.x/valet#installation"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 &lt;strong&gt;Before installing, be sure nothing else is binding to your local machine's port 80 and 3306.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
If you are running MAMP, it may be using these ports for Apache and MySQL. Stop those servers if that's the case.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Open up Terminal and run the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;composer global require laravel/valet
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once Valet is downloaded, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;valet &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will start Valet and set it up to automatically start whenever your machine boots. Set it and forget it! 🍗&lt;/p&gt;

&lt;p&gt;You can confirm Valet is running with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;ping foo.test
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It should be responding from &lt;code&gt;127.0.0.1&lt;/code&gt;. Hit &lt;code&gt;Control+C&lt;/code&gt; to stop pinging.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Craft CMS
&lt;/h2&gt;

&lt;p&gt;Current Craft installation instructions can be found &lt;a href="https://craftcms.com/docs/3.x/installation.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Before installing Craft, we first need to make sure we have MySQL installed. From a command line, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;mysql@5.7
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once installed, you can start MySQL with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;brew services start mysql@5.7
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;While we have MySQL on the brain, let's go ahead and create a database. I like to organize my local databases by naming them &lt;code&gt;craft3_projectname&lt;/code&gt;, but you can use whatever name you like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql &lt;span class="nt"&gt;-u&lt;/span&gt; root &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"CREATE DATABASE database_name"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;No password is necessary; you should be able to connect to MySQL with just the username &lt;code&gt;root&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Finally, we're ready to install Craft. In a command line, move to a directory you'd like to download the Craft files and run the following command, where &lt;code&gt;&amp;lt;craft-directory&amp;gt;&lt;/code&gt; is the path where the project should be created.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 Valet will eventually map this project to &lt;code&gt;[dir].test&lt;/code&gt;, so it's useful to name your Craft directory accordingly. For example, &lt;code&gt;my-fun-project&lt;/code&gt; will be accessible at &lt;code&gt;http://my-fun-project.test&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;composer create-project craftcms/craft &amp;lt;craft-directory&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Composer will download &amp;amp; install Craft and a bunch of dependencies. When it's done, you should see a message like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="s2"&gt;"Welcome to Craft CMS! Run the following command
if you want to setup Craft from your terminal:

    path/to/&amp;lt;craft-directory&amp;gt;/craft setup"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Go ahead and run that command. Follow the instructions and answer the following. Values in square brackets are default, so you can just hit &lt;code&gt;return&lt;/code&gt; if they're already correct.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which database driver are you using?: &lt;code&gt;mysql&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Database server name or IP address: &lt;code&gt;127.0.0.1&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Database port: &lt;code&gt;3306&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Database username: &lt;code&gt;root&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Database password: &lt;em&gt;(blank, just hit &lt;code&gt;return&lt;/code&gt;)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Database name: &lt;code&gt;your_db_name&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Database table prefix: &lt;em&gt;leave blank, unless you need to have multiple installs on the same database&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Craft will attempt to connect to your database and then save the credentials in an &lt;code&gt;.env&lt;/code&gt; file in your project root.&lt;/p&gt;

&lt;p&gt;Now, you will be asked if you want to install Craft. Choose &lt;code&gt;yes&lt;/code&gt;, and then follow the prompts to create an initial admin user. Remember this information, you'll need it to log into the Craft admin panel.&lt;/p&gt;

&lt;p&gt;For Site URL, &lt;code&gt;http://&amp;lt;craft-directory&amp;gt;.test&lt;/code&gt;. Replace &lt;code&gt;&amp;lt;craft-directory&amp;gt;&lt;/code&gt; with the name of directory in which you installed Craft.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Finally&lt;/strong&gt;, Craft will create all the tables and initial data. Now, just one last step remains...&lt;/p&gt;

&lt;h2&gt;
  
  
  Connecting Valet to Craft
&lt;/h2&gt;

&lt;p&gt;There are two commands Valet has for serving your sites: &lt;code&gt;park&lt;/code&gt; and &lt;code&gt;link&lt;/code&gt;. First, I'll cover the &lt;code&gt;link&lt;/code&gt; command, useful for one-off projects.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;valet link&lt;/code&gt; 🔗
&lt;/h3&gt;

&lt;p&gt;Move to the directory you installed Craft in (what we've been calling &lt;code&gt;&amp;lt;craft-directory&amp;gt;&lt;/code&gt; so far) and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;valet &lt;span class="nb"&gt;link&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;That's it.&lt;/em&gt; Your site is now live at &lt;code&gt;http://&amp;lt;craft-directory&amp;gt;.test&lt;/code&gt;. Valet just created a symbolic link in &lt;code&gt;~/.config/valet/Sites&lt;/code&gt; and pointed it to the current directory.&lt;/p&gt;

&lt;p&gt;If at any point you need to remove this link, run &lt;code&gt;valet unlink &amp;lt;craft-directory&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;valet park&lt;/code&gt; 🚘
&lt;/h3&gt;

&lt;p&gt;If you're like me, you probably have several sites currently in some form of development, and it's handy to have them all in one place. With &lt;code&gt;valet park&lt;/code&gt;, any directory you add to a "parked" directory will be served at &lt;code&gt;http://directory-name.test&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;If I wanted my &lt;code&gt;~/Sites&lt;/code&gt; directory to be home to all my current projects, all I need to do is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/Sites
valet park
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;Done.&lt;/strong&gt;&lt;/em&gt; No need to run &lt;code&gt;valet link&lt;/code&gt; every time you make a new project, just create a new project directory and it does the linking for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  More Projects
&lt;/h2&gt;

&lt;p&gt;Next time you need to install a new Craft project, all you need to do is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Move to your parked projects directory&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; ~/Sites

&lt;span class="c"&gt;# Create a new database&lt;/span&gt;
mysql &lt;span class="nt"&gt;-u&lt;/span&gt; root &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"CREATE DATABASE new_db_name"&lt;/span&gt;

&lt;span class="c"&gt;# Install Craft&lt;/span&gt;
composer create-project craftcms/craft &amp;lt;new-site-name&amp;gt;

&lt;span class="c"&gt;# Setup Craft, filling in database credentials&lt;/span&gt;
&lt;span class="c"&gt;# with username root and no password&lt;/span&gt;
&amp;lt;new-site-name&amp;gt;/craft setup
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;&amp;lt;new-site-name&amp;gt;&lt;/code&gt; will automatically be served at &lt;code&gt;http://&amp;lt;new-site-name&amp;gt;.test&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 If you didn't park a directory for multiple sites, move into the &lt;code&gt;&amp;lt;new-site-name&amp;gt;&lt;/code&gt; directory and run &lt;code&gt;valet link&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Laravel Valet is currently my favorite way to work on Craft CMS project. Being able to drop a project in my parked sites directory and &lt;em&gt;just have it work&lt;/em&gt; is so useful to me. No more starting and stopping MAMP or Docker, no big virtual server images clogging up my hard drive, just a fast, lean development environment.&lt;/p&gt;

&lt;p&gt;Have you been using Valet? Is Docker or MAMP more your style? Or have you made the leap to Craft's new similar tool, &lt;a href="https://getnitro.sh/"&gt;Nitro&lt;/a&gt;? Let me know what you think! &lt;/p&gt;




&lt;p&gt;Coming up next, I'll show you how I use Laravel Mix and Tailwind CSS to make frontend development a breeze. Stay tuned...&lt;/p&gt;

</description>
      <category>craftcms</category>
      <category>laravel</category>
      <category>laravelvalet</category>
      <category>macos</category>
    </item>
  </channel>
</rss>
