<?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>DEV Community: Nick Frostbutter</title>
    <description>The latest articles on DEV Community by Nick Frostbutter (@nickfrosty).</description>
    <link>https://dev.to/nickfrosty</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%2F721037%2F2dafe3e2-5ca8-4c43-82bc-5216e127c988.jpeg</url>
      <title>DEV Community: Nick Frostbutter</title>
      <link>https://dev.to/nickfrosty</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nickfrosty"/>
    <language>en</language>
    <item>
      <title>How to derive Solana addresses</title>
      <dc:creator>Nick Frostbutter</dc:creator>
      <pubDate>Thu, 12 Jan 2023 05:00:00 +0000</pubDate>
      <link>https://dev.to/nickfrosty/how-to-derive-solana-addresses-3e06</link>
      <guid>https://dev.to/nickfrosty/how-to-derive-solana-addresses-3e06</guid>
      <description>&lt;p&gt;Every public address on the &lt;a href="https://nick.af/tags/solana"&gt;Solana blockchain&lt;/a&gt; uses a string of characters between 32 and 44 characters long. Each of these address follow the BIP44 standard and therefore use the base-58 character set.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://nick.af/articles/derive-solana-addresses"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GET27IQM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tz92xn25rm648vyo88ze.jpg" alt="how Solana addresses are derived" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These seemingly random string of letters and numbers are known as your "Public Key" (or &lt;code&gt;pubkey&lt;/code&gt; for short), and are the addresses that people can share freely across the internet. It's your "wallet address".&lt;/p&gt;

&lt;p&gt;These public address have a very specific set of one-way relationships that prevent any derived address from computing the secret that derived itself. Hence one-way. This one way relationship is one of the core fundamentals of most cryptography and all blockchains.&lt;/p&gt;

&lt;p&gt;It is how us common folk on the internet can have true digital ownership and provenance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Base-58 character set
&lt;/h3&gt;

&lt;p&gt;Solana public addresses and transactions function on the base-58 character set. Essentially meaning, there are only 58 possible characters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;including uppercase A-Z, &lt;strong&gt;excluding&lt;/strong&gt; uppercase &lt;code&gt;O&lt;/code&gt; and &lt;code&gt;I&lt;/code&gt; (as in &lt;code&gt;Oscar&lt;/code&gt; and &lt;code&gt;India&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;lowercase letters A-Z, &lt;strong&gt;excluding&lt;/strong&gt; lowercase &lt;code&gt;l&lt;/code&gt; (as in &lt;code&gt;letter&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;digits 1-9, (which does &lt;strong&gt;NOT&lt;/strong&gt; include &lt;code&gt;0&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These specific letters are &lt;strong&gt;excluded&lt;/strong&gt; from the base-58 character set since they can very easily be mistaken for other characters. And if the wrong character is used, then the blockchain address is completely different!&lt;/p&gt;

&lt;h2&gt;
  
  
  How are Solana addresses derived?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;mnemonic phase -&amp;gt; private key -&amp;gt; public key (aka your wallet's address)&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;For most people (not programs) the process to get a public address on the blockchain involved installing a web based "browser wallet" like Phantom or Solflare. Which then will generate a random list of words called your &lt;strong&gt;"mnemonic phrase"&lt;/strong&gt; which is then used to derive (or &lt;strong&gt;compute&lt;/strong&gt; ) a public address, in the form of one-way cryptography.&lt;/p&gt;

&lt;p&gt;Below I will break down each of these steps:&lt;/p&gt;

&lt;h2&gt;
  
  
  Mnemonic phrases
&lt;/h2&gt;

&lt;p&gt;Public addresses on the Solana blockchain are most commonly derived from a &lt;code&gt;mnemonic phrase&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For most people, they will commonly use a &lt;code&gt;mnemonic phrase&lt;/code&gt; that is a randomly generated list of words and is usually 12 or 24 words longs. For Solana, this phrase contains very specific words from the &lt;a href="https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md"&gt;BIP39 wordlist&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The very specific combination of these words &lt;strong&gt;AND&lt;/strong&gt; their specific order will allow the blockchain to &lt;strong&gt;"derive"&lt;/strong&gt; (or &lt;strong&gt;"compute"&lt;/strong&gt; ) a Private key using the &lt;a href="https://en.wikipedia.org/wiki/EdDSA#Ed25519"&gt;Ed25519 algorithm&lt;/a&gt;. This private key can then be used to derive a public key, giving us a &lt;code&gt;keypair&lt;/code&gt; (aka combination of a Private key and a Public key.)&lt;/p&gt;

&lt;p&gt;In theory, the mnemonic phrase is used to essentially makes it easier for a human to read than a random string of characters, like a Private key. Thus making it easier for a human to write down this phrase, &lt;strong&gt;without mistakes&lt;/strong&gt; , than a random character string.&lt;/p&gt;

&lt;h2&gt;
  
  
  Private keys
&lt;/h2&gt;

&lt;p&gt;The derived Private key (or "secret key") is the special key that is the &lt;strong&gt;ONLY&lt;/strong&gt; key that will be able to &lt;strong&gt;sign&lt;/strong&gt; a transaction for its corresponding Public key, and therefore prove it own the public address.&lt;/p&gt;

&lt;p&gt;A private key can always derive it's "child" public keys (and yes that is multiple, more on that in a moment), but a public key cannot derive its private key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Derivation path
&lt;/h2&gt;

&lt;p&gt;One of the most commonly misunderstood portion of generating a blockchains addresses is the &lt;code&gt;derivation path&lt;/code&gt;. This special piece of information is what allows a single Private key to &lt;a href="https://docs.solana.com/wallet-guide/paper-wallet#hierarchical-derivation"&gt;derive multiple&lt;/a&gt; Public keys that are impossible to tell they came from the same Private key. Only the owner of the Private key can tell.&lt;/p&gt;

&lt;p&gt;These derivation paths are essentially a sequence that looks like this:&lt;/p&gt;

&lt;p&gt;Sequence: &lt;code&gt;m/&amp;lt;PURPOSE&amp;gt;/&amp;lt;COIN_TYPE&amp;gt;/&amp;lt;ACCOUNT&amp;gt;/&amp;lt;CHANGE&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;each section is separated by a single &lt;code&gt;/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;m&lt;/code&gt; notes the root or "master" key&lt;/li&gt;
&lt;li&gt;each of the other elements after &lt;code&gt;m&lt;/code&gt; should be a zero or positive integer&lt;/li&gt;
&lt;li&gt;each element may also end in a single &lt;code&gt;'&lt;/code&gt;, noting it is "hardened"

&lt;ul&gt;
&lt;li&gt;you can read more &lt;a href="https://github.com/satoshilabs/slips/blob/master/slip-0010.md"&gt;here&lt;/a&gt; about it, but it is not really necessary&lt;/li&gt;
&lt;li&gt;just know that Solana uses hardened elements and will enforce this automatically, regardless of if the &lt;code&gt;'&lt;/code&gt;s are included.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With only specifying a derivation path of the &lt;code&gt;m/&amp;lt;PURPOSE&amp;gt;/&amp;lt;COIN_TYPE&amp;gt;&lt;/code&gt;, like the one used by the Solana CLI, only the "root key" can be derived. Specifying the &lt;code&gt;&amp;lt;ACCOUNT&amp;gt;/&amp;lt;CHANGE&amp;gt;&lt;/code&gt; will enable deriving multiple Public keys from the same Private key.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can learn more about about the CLI with this guide on &lt;a href="https://nick.af/articles/intro-to-solana-cli"&gt;how to use the Solana CLI&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Derivation paths on Solana
&lt;/h3&gt;

&lt;p&gt;The "standard" derivation paths used on the Solana blockchain are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;m/44'/501'&lt;/code&gt; used by the Solana CLI to generate a "root key", and&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;m/44'/501'/0'/0'&lt;/code&gt; used by most web based or browser based wallets (like Phantom and Solflare)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These Solana derivation paths segments basically mean this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;44'&lt;/code&gt; - (required) uses the &lt;a href="https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki"&gt;BIP44&lt;/a&gt; standard&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;501'&lt;/code&gt; - (required) the identifier for coin type of the Solana blockchain&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;0'&lt;/code&gt; - (optional) define the account ID to derive. This is the value that browser wallets (like Phantom and Solflare) will change to enable users to generate new Public addresses on the fly, all while still using their single mnemonic phrase.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;0'&lt;/code&gt; - (optional) an additional number that is basically always set to &lt;code&gt;0&lt;/code&gt; for addresses that will be public&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Public keys and wallet addresses
&lt;/h2&gt;

&lt;p&gt;The Public key (aka &lt;code&gt;pubkey&lt;/code&gt;) that is derived from a private key, using derivation path, is the public address that people have come to know as their "wallet address". This address will allow anyone on the blockchain to transfer tokens or otherwise interact with their account, securely.&lt;/p&gt;

&lt;h3&gt;
  
  
  Vanity addresses
&lt;/h3&gt;

&lt;p&gt;Normally, a public Solana address appears as a random string of letters and numbers (like discussed above). But, there is a common technique used to try to generate addresses that start with certain characters in a row (like a word). These addresses are called &lt;a href="//./solana-vanity-addresses.md"&gt;Vanity Addresses&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>solana</category>
      <category>blockchain</category>
      <category>base58</category>
    </item>
    <item>
      <title>24 things I learned deploying to Vercel</title>
      <dc:creator>Nick Frostbutter</dc:creator>
      <pubDate>Tue, 22 Mar 2022 05:00:00 +0000</pubDate>
      <link>https://dev.to/nickfrosty/24-things-i-learned-deploying-to-vercel-26n</link>
      <guid>https://dev.to/nickfrosty/24-things-i-learned-deploying-to-vercel-26n</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fvercel%2Fvercel-the-first-time-thumb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fvercel%2Fvercel-the-first-time-thumb.jpg" title="24 things I learned deploying to Vercel" alt="24 things I learned deploying to Vercel"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Recently, a friend turned me onto Vercel. Well, I guess it has been a few months now.&lt;/p&gt;

&lt;p&gt;And I am loving it. But, like everything in life, it is not without it’s hiccups.&lt;/p&gt;

&lt;p&gt;Both on the side of &lt;strong&gt;the platform&lt;/strong&gt; having things that may work sub-optimally, &lt;strong&gt;and me as a new user&lt;/strong&gt; to their platform trying to get acquainted and learning the ropes.&lt;/p&gt;




&lt;h3&gt;
  
  
  Quick background on Vercel
&lt;/h3&gt;

&lt;p&gt;It’s a wonderful platform to automatically deploy your projects from a git repo.&lt;/p&gt;

&lt;p&gt;Create an account, you connect your git repo, and push changes. Vercel handles the rest.&lt;/p&gt;

&lt;p&gt;In the end, Vercel is basically a really fancy layer built on top of Amazon’s AWS platform. You can even use "serverless functions" built on top of AWS lambda functions. Giving your code very high scalability, right out of the box.&lt;/p&gt;

&lt;h3&gt;
  
  
  How does Vercel work?
&lt;/h3&gt;

&lt;p&gt;They have a fairly comprehensive continuous deployment (CD) pipeline, Vercel automates the creation of unique builds for every commit to your git repo. Production, staging, or "preview" commits.&lt;/p&gt;

&lt;p&gt;With each &lt;code&gt;git commit&lt;/code&gt; you make, Vercel will automatically build your project and create a unique url to access each individual build. Turning every single git repo commit into a fully functional "preview" deployment.&lt;/p&gt;

&lt;p&gt;Anyone on your team can access, use, and review your app from these unique urls. Even password protect the build urls.&lt;/p&gt;

&lt;p&gt;Once satisfied with your project changes, you simply &lt;code&gt;git commit&lt;/code&gt; or merge into to your "production" branch. Vercel will automatically build and make it available on your primary/production domain.&lt;/p&gt;




&lt;p&gt;With that intro aside, here are &lt;strong&gt;24&lt;/strong&gt; this I learned deploying my first project to Vercel (in no particular order):&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PS: I am not affiliated with Vercel, other than as a happy user.&lt;/p&gt;

&lt;p&gt;(but I would not mind a job offer 😇)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  #1. Almost too easy to use...
&lt;/h2&gt;

&lt;p&gt;The ease of use of using Vercel is just wonderful. Once you get setup* and your git repo connected, deploying your web app is stupid simple. Just &lt;code&gt;git commit&lt;/code&gt; and &lt;code&gt;git push&lt;/code&gt; and you are golden.&lt;/p&gt;

&lt;h2&gt;
  
  
  #2. Took me a bit to get a green build
&lt;/h2&gt;

&lt;p&gt;Yeah... it did take me a bit of time to get properly setup with a successful build. I banged my head against the wall for a long time while trying to get my first project working.&lt;/p&gt;

&lt;p&gt;I suspect at least some of this was user error (I do dumb things sometimes, who doesn't), some of it due to me using NuxtJS (which is not Vercel's best supported framework), and some due to the platform itself.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PS: To their full credit, multiple awesome people from Vercel did reach out to me on Twitter (&lt;a href="https://twitter.com/steph_dietz_" rel="noopener noreferrer"&gt;@steph_dietz_&lt;/a&gt; and &lt;a href="https://twitter.com/gudmundur" rel="noopener noreferrer"&gt;@gudmundur&lt;/a&gt;) after me publicly talking about some of my struggles. So that was awesome!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  #3. auto deployments = wonderful
&lt;/h2&gt;

&lt;p&gt;Each &lt;code&gt;git commit&lt;/code&gt; you make, Vercel will automatically build your project and create a unique url to access each individual build. Turning each repo commit into a "preview" deployment.&lt;/p&gt;

&lt;p&gt;Anyone on your team can access, use, and review your app from these unique urls.&lt;/p&gt;

&lt;p&gt;Once satisfied with your project changes, you simply &lt;code&gt;git commit&lt;/code&gt; or merge into to your "production" branch, and Vercel will automatically build and make it available on your primary/production domain.&lt;/p&gt;

&lt;p&gt;Then, after the successful build, Vercel's github bot will attach the link to the specific build url to view the preview or production build of that repo or PR. Very handy when others in your organization want to use GitHub for bug tracking.&lt;/p&gt;

&lt;h3&gt;
  
  
  #4. Deleting old builds?
&lt;/h3&gt;

&lt;p&gt;As your project grows, the list of Vercel builds you have in your dashboard will grow.&lt;/p&gt;

&lt;p&gt;At first, I could not find a way to manually clear the list of builds on the dashboard. Sad. I would have expected the option as part of the dropdown attached to each build.&lt;/p&gt;

&lt;p&gt;But after more exploring, I found it. You can delete builds. But you have to go to the specific page for that build. From this page, and this page only, you can use the options dropdown to delete this specific build.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to the specific build page&lt;/li&gt;
&lt;li&gt;click the 3 dot style "more options" dropdown in the top left corner&lt;/li&gt;
&lt;li&gt;then you can delete the build&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;My opinion:&lt;/strong&gt;&lt;br&gt;
Users should be able to select the option from the project dashboard page. Where it lists out all of the recent builds anyway. Just add the same delete option to the more options menu.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To me, it seems like a better user experience. Plus, it would require at least 3 less page requests to delete a build. And that is just more efficient 😁&lt;/p&gt;

&lt;h2&gt;
  
  
  #5. vercel-build command
&lt;/h2&gt;

&lt;p&gt;In your &lt;code&gt;package.json&lt;/code&gt; file, you can define the &lt;code&gt;vercel-build&lt;/code&gt; command to trigger any commands or build steps for each of the serverless functions that are built on Vercel.&lt;/p&gt;

&lt;p&gt;This come in super handy when you have a certain package that may need to generate a configuration as part of the build, like Prisma for example. See the Prisma section below...&lt;/p&gt;

&lt;h2&gt;
  
  
  #6. "zero config" option
&lt;/h2&gt;

&lt;p&gt;While Vercel has a "&lt;a href="https://vercel.com/guides/upgrade-to-zero-configuration" rel="noopener noreferrer"&gt;zero config&lt;/a&gt;" option (or at least that's what they used to call it).&lt;/p&gt;

&lt;p&gt;You can create a &lt;code&gt;vercel.json&lt;/code&gt; file in the root of your repo, then use that to define almost all of your project settings. Including routes, headers, and env variables. Quite nifty.&lt;/p&gt;

&lt;p&gt;But, it seems like the good people of Vercel are moving away from this config file and trying to encourage developers to use the Vercel dashboard. Normally, I would be all for that. The dashboard is pretty great, and certainly very wholesome.&lt;/p&gt;

&lt;h3&gt;
  
  
  #7. Nuxt on Vercel
&lt;/h3&gt;

&lt;p&gt;But, and this is a big butt: to use NuxtJS on Vercel, you have to define your project with a &lt;code&gt;vercel.json&lt;/code&gt; file. At least to use &lt;a href="https://nuxtjs.org/docs/concepts/server-side-rendering/" rel="noopener noreferrer"&gt;NuxtJS SSR&lt;/a&gt; (which is kind of the whole reason Nuxt exists).&lt;/p&gt;

&lt;p&gt;The only way that seems to work to deploy a Nuxt SSR app to vercel is using this "&lt;a href="https://github.com/nuxt/vercel-builder" rel="noopener noreferrer"&gt;vercel-builder&lt;/a&gt;" project from the Nuxt community.&lt;/p&gt;

&lt;p&gt;And on top of this, the built in "&lt;em&gt;auto generate your API routes with Vercel from the 'api' folder&lt;/em&gt;" thing that Vercel markets also does not seem to work with Nuxt. So in order to create a serverless API for a Nuxt app, I have to manually define each of the API routes in my &lt;code&gt;vercel.json&lt;/code&gt; file. Annoying, but not the end of the world.&lt;/p&gt;

&lt;p&gt;PS: If anyone wants to talk about this, feel free to each out. I am more than happy to talk. Either to help guide you in getting your Nuxt app working on Vercel, or helping people make the process better. DM me on Twitter: &lt;a href="https://twitter.com/nickfrosty" rel="noopener noreferrer"&gt;@nickfrosty&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #8. env vars up the wazoo
&lt;/h2&gt;

&lt;p&gt;To add on to the different types of deployments Vercel can do (e.g. production, staging, etc), you can also specify specific env vars for each build type.&lt;/p&gt;

&lt;p&gt;For example, in your production app you want to use your production "live mode" Stripe API keys to process your payments. Great. But on the staging app, you want to use the "test mode" keys to not monkey up your actual Stripe data. No problem.&lt;/p&gt;

&lt;p&gt;Also by default, there are tons of env vars that are auto generated for each build. Some of them very useful, some of them less useful for me. But hey, they are available if you need them.&lt;/p&gt;

&lt;p&gt;You can read all about them on the Vercel env variable docs: &lt;a href="https://vercel.com/docs/concepts/projects/environment-variables" rel="noopener noreferrer"&gt;https://vercel.com/docs/concepts/projects/environment-variables&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PS: Although you can set custom env vars for each build type, I did not see a easy way to copy the env variable names between build types. So you will have to manually add them for each build type.&lt;/p&gt;

&lt;p&gt;Kind of annoying, but I can easily live with it. Especially since I only needed to set them up the one time.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  #9. Are you using Axios on Vercel?
&lt;/h3&gt;

&lt;p&gt;When using Axios (at least with Nuxt), you will likely need to specify the &lt;code&gt;API_URL&lt;/code&gt; env variable. Without it, the Nuxt SSR request will fail (like those made via &lt;code&gt;nuxt-auth&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;From your Vercel project dashboard, navigate to your project settings -&amp;gt; environment variables page. For each of your build environments (e.g. production, staging, etc): add a new env variable names &lt;code&gt;API_URL&lt;/code&gt; with a value of the base url you are using for the project.&lt;/p&gt;

&lt;p&gt;For example: if your app's API is located at "&lt;a href="https://my.other.link/api" rel="noopener noreferrer"&gt;https://my.other.link/api&lt;/a&gt;" -&amp;gt; your &lt;code&gt;API_URL&lt;/code&gt; should be "&lt;a href="https://my.other.link/" rel="noopener noreferrer"&gt;https://my.other.link/&lt;/a&gt;".&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PS: Doing this will also solve a problem with &lt;code&gt;nuxt-auth&lt;/code&gt; on Vercel that appears to log the user out after any page refresh (aka not navigating by the client side rendering). I struggles for hours (maybe days) on this problem.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  #10. All serverless functions = scale to infinity?
&lt;/h2&gt;

&lt;p&gt;With the way that Vercel works, it seems like every single portion of your app will run on serverless functions (aka AWS lambdas). So in theory, your app code can scale to infinity. Which is super cool.&lt;/p&gt;

&lt;p&gt;Honestly, I am not sure if all of the customer apps (or the entire platform) run on top of these serverless functions, but I would not be surprised.&lt;/p&gt;

&lt;p&gt;At least for me using NuxtJS, all of my code for &lt;a href="https://other.link" rel="noopener noreferrer"&gt;other.link&lt;/a&gt; is running on top of these serverless functions. At first, I did need to make some specific and calculated coding techniques to make my API run on these functions.&lt;/p&gt;

&lt;p&gt;The biggest reason is because the serverless functions are limited to 50MBs (zipped) after their build is complete. Making them lightweight enough to run and "cold start" on the AWS lambdas. And I am pretty sure this 50MB is an AWS specific limit, not necessarily Vercel.&lt;/p&gt;

&lt;p&gt;If you writing Node js code for your project, read this Vercel doc:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://vercel.com/docs/runtimes#official-runtimes/node-js/node-js-request-and-response-objects" rel="noopener noreferrer"&gt;https://vercel.com/docs/runtimes#official-runtimes/node-js/node-js-request-and-response-objects&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  #11. Serverless functions and databases...
&lt;/h2&gt;

&lt;p&gt;While the whole "serverless" architecture is very interesting to me, there is one big problem with it. Databases. Specifically database connections. Let me explain:&lt;/p&gt;

&lt;p&gt;Each serverless function is basically a separate instance of your web app, or at least a portion of it. If that function makes a database connects to your database and makes a request, it is likely leaving that connection open. This way it can more easily connect again and get database records when needed.&lt;/p&gt;

&lt;p&gt;But as the traffic to your app/website start to die off, these stateless serverless functions will turn off. Often not properly closing the database connections. If your site has frequent traffic spikes, then you may very quickly reach your database's connection limits. Forcing your database to a halt. Big problem.&lt;/p&gt;

&lt;p&gt;From the research I have done, the best solutions to these known stale connection issues is using "connection pools". If you are using &lt;a href="https://www.prisma.io/" rel="noopener noreferrer"&gt;Prisma.io&lt;/a&gt; like me, I think there is some database connection pooling support built in (awesome). Postgres fans could try pgBounce (but I'm a MySQL kinda guy).&lt;/p&gt;

&lt;p&gt;But if you are handing all your connections yourself, it might get hairy quick.&lt;/p&gt;

&lt;p&gt;Right now, there are some VERY cool "serverless database" solutions coming out. Including &lt;a href="https://fauna.com/" rel="noopener noreferrer"&gt;Fauna DB&lt;/a&gt; and &lt;a href="https://planetscale.com/" rel="noopener noreferrer"&gt;PlantScale&lt;/a&gt;. I am planning on using PlanetScale for an upcoming project where I think scaling might become an issue for me: my &lt;a href="https://log.fm" rel="noopener noreferrer"&gt;custom podcast playlist&lt;/a&gt; app.&lt;/p&gt;

&lt;h2&gt;
  
  
  #12. Vercel CLI
&lt;/h2&gt;

&lt;p&gt;What kind of world would we live in in our hosting platforms did NOT have their own CLI. All the cool, hip platforms do. Vercel is no different.&lt;/p&gt;

&lt;p&gt;Here are some of my high level thoughts on the Vercel CLI:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;fairly simple and easy to use&lt;/li&gt;
&lt;li&gt;you can link your terminal and git repo to a Vercel project (visible in the Vercel dashboard) directly from the CLI.&lt;/li&gt;
&lt;li&gt;push your current project's code to be build on Vercel (without making a full &lt;code&gt;git commit&lt;/code&gt;), you know, to test thing.

&lt;ul&gt;
&lt;li&gt;by default, the CLI will create a development build for testing. But you can the CLI build directly to production with the &lt;code&gt;--prod&lt;/code&gt; flag. Very handy for hot fixes.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;after the build is complete, you will get clickable links to view the build on your domain&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  #13. I have had some issue with the Vercel CL though
&lt;/h3&gt;

&lt;p&gt;When running &lt;code&gt;vercel dev&lt;/code&gt;, if the vercel cli does not have access to your current working directory, then it may fail to actually build/launch your app locally. Makes sense I guess.&lt;/p&gt;

&lt;p&gt;When this failure happens:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the CLI fails to create the &lt;code&gt;node_modules_prod&lt;/code&gt; directory&lt;/li&gt;
&lt;li&gt;which for some reason also deletes all the all the dev dependencies for your project from the ‘node_modules’ directory (weird, but okay I guess)&lt;/li&gt;
&lt;li&gt;and then it removes the dev dependencies from your package.json file. (again, super weird)&lt;/li&gt;
&lt;li&gt;all of these will likely result in a LOUD failure of your build command, and your local project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The real problem lies in this: since it deletes all the dev dependencies, you will have to reinstall them and add them back to your package.json...good thing we all use git right?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I was getting the listing of all my dev dependencies from my git changelog, since these changes were now all pending commits&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  #14. Build caches for speed!
&lt;/h2&gt;

&lt;p&gt;The Vercel deployment/build system is pretty nice. It has a built in caching system that tries to make your builds faster by caching the &lt;code&gt;node_modules&lt;/code&gt; folder after your first build. And yes, it does make the builds noticeably faster. Often by several minutes.&lt;/p&gt;

&lt;p&gt;But it does have some limitations/drawbacks:&lt;/p&gt;

&lt;h3&gt;
  
  
  #15. Random failed/success builds?
&lt;/h3&gt;

&lt;p&gt;Sometimes my builds will fail, sometimes they will pass. All from the same git commit. My only guess is that this is an issue with the Vercel build cache.&lt;/p&gt;

&lt;p&gt;If you run into this sort of problem, check out these articles (they helped me): - &lt;a href="https://stackoverflow.com/a/66841372/17609674" rel="noopener noreferrer"&gt;https://stackoverflow.com/a/66841372/17609674&lt;/a&gt;- &lt;a href="https://stackoverflow.com/a/61101087/17609674" rel="noopener noreferrer"&gt;https://stackoverflow.com/a/61101087/17609674&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  #16. Old caches cause problems
&lt;/h3&gt;

&lt;p&gt;When you push an update to your repo, Vercel will try to use the cached &lt;code&gt;node_modules&lt;/code&gt; build files. Makes sense. Caching.&lt;/p&gt;

&lt;p&gt;But this will always be from an older build. Which means it will likely use the older version of some packages or generated artifacts from packages. Like Prisma (see the Prisma section below)&lt;/p&gt;

&lt;p&gt;This can become problematic and give errors if you have a npm package that needs to generate new code each build, or only for some builds when you make certain updates.&lt;/p&gt;

&lt;p&gt;For most cases, I recommend adding that particular build step into the &lt;code&gt;vercel-build&lt;/code&gt; script command to ensure it gets built every time. This will result in your builds taking longer though.&lt;/p&gt;

&lt;p&gt;Or, you can also manually force the build without the cache from the Vercel dashboard (only for git repo pushes) or via the Vercel cli using &lt;code&gt;vercel -f&lt;/code&gt; or &lt;code&gt;vercel -f --prod&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;PS: If you use Prisma and Vercel, read the dedicated Prisma section at the bottom 👇&lt;/p&gt;

&lt;h2&gt;
  
  
  #17. npm vs yarn
&lt;/h2&gt;

&lt;p&gt;Vercel will try to auto detect if you like using &lt;strong&gt;npm&lt;/strong&gt; or &lt;strong&gt;yarn&lt;/strong&gt; for your package manager.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if your repo has a &lt;code&gt;package-lock.json&lt;/code&gt;, it will use npm&lt;/li&gt;
&lt;li&gt;if not, then yarn&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So if you want to use npm, like me, then make sure your &lt;code&gt;package-lock.json&lt;/code&gt; file is committed with git.&lt;/p&gt;

&lt;p&gt;This may not matter for your project, but it also might &lt;em&gt;really&lt;/em&gt; matter. Here is why:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NPM does &lt;strong&gt;NOT&lt;/strong&gt; allow installing global packages, permission denied.&lt;/li&gt;
&lt;li&gt;yarn &lt;em&gt;does&lt;/em&gt; allow installing global packages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you need to force the Vercel build engine to install a certain non-native dependency, like "bcrypt" (see below), then you will most likely need to install it as a global dependency. But you can only do that with yarn. At least as far as I can tell.&lt;/p&gt;

&lt;h2&gt;
  
  
  #18. Don't use bcrypt with Vercel
&lt;/h2&gt;

&lt;p&gt;Don’t use bcrypt. Just don't.&lt;/p&gt;

&lt;p&gt;It is not a native javascript library. So it will add lots of bloat to your project. Often making your builds fail.&lt;/p&gt;

&lt;p&gt;I have been using the "scrypt" library that is built into Node. It is native, fast, and secure.&lt;/p&gt;

&lt;p&gt;If you are already set on using it for an older project, switch to the "bcryptjs" npm package. Without using the javascript version, you will need to make some VERY hacky solutions to get it to work. And honestly, it is not worth the hassle.&lt;/p&gt;

&lt;p&gt;Trust me. I tried it for my first project. Not worth it.&lt;/p&gt;

&lt;h2&gt;
  
  
  #19. Error logging in Vercel
&lt;/h2&gt;

&lt;p&gt;Vercel does allow your projects to kick out errors and will "catch" then. In fact, each build will get their own error/warnings log. With one big caveat:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Vercel error logs are only visible if you are already viewing the logs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By default, you will only be able to see any of your console &lt;code&gt;log&lt;/code&gt;, &lt;code&gt;warn&lt;/code&gt;, and &lt;code&gt;error&lt;/code&gt; logs if you are actively viewing the specific builds logs page. They are _ &lt;strong&gt;ONLY&lt;/strong&gt; _ realtime logs.&lt;/p&gt;

&lt;p&gt;You can setup Vercel to send all your logs to a separate logger service, like LogRocket. But they you will likely need to pay for another service. Which is obviously unfortunate.&lt;/p&gt;

&lt;h3&gt;
  
  
  #20. console.log sometimes does not appear (sometimes?)
&lt;/h3&gt;

&lt;p&gt;When you need to break into troubleshooting or debugging via the &lt;code&gt;console.log&lt;/code&gt; method, you might miss some logs.&lt;/p&gt;

&lt;p&gt;I have noticed that if any serverless function (or my NuxtJS app) sends any data to the console using &lt;code&gt;console.log&lt;/code&gt;, then it may not get picked up by the realtime function logs. Specifically if my code triggers a log event closer to the beginning.&lt;/p&gt;

&lt;p&gt;My best guess is that based on how the serverless functions are spun up from their "cold start" state, the Vercel logging catcher system is not spun up fast enough to catch the early ones. Sounds strange right?&lt;/p&gt;

&lt;p&gt;My workaround: use &lt;code&gt;console.warn&lt;/code&gt; instead of &lt;code&gt;console.log&lt;/code&gt;. Every &lt;code&gt;warn&lt;/code&gt; log seem to get captured by the Vercel realtime logs, no problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  #21. Vercel and PrismaJS
&lt;/h2&gt;

&lt;p&gt;I really like Prisma. And I really like Vercel. But... they seem to work kinda strangely together.&lt;/p&gt;

&lt;p&gt;Yes Vercel can support Prisma JS. But, I have run into several hiccups while trying to do so.&lt;/p&gt;

&lt;p&gt;If you are not familiar with Prisma JS, here is a quick snapshot of how it works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;turn a MySQL or Postgres database into a GraphQL style interface&lt;/li&gt;
&lt;li&gt;you define your database schema in your &lt;code&gt;prisma.schema&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;create a "migration" file of each database change (allowing you to track database changes via git)&lt;/li&gt;
&lt;li&gt;after a migration, you need to "generate" a new "PrismaClient" (basically just a fancy type-safe adapter for your database)&lt;/li&gt;
&lt;li&gt;you can make database calls like this: &lt;code&gt;const user = await prisma.user.findUnique({where: {id:1} });&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Prisma is super great to use. But...&lt;/p&gt;

&lt;h3&gt;
  
  
  #22. Vercel/Prisma cache issues...
&lt;/h3&gt;

&lt;p&gt;When you update your schema, you must generate a new "PrismaClient". Normally not a problem, except when the Vercel build cache comes into play.&lt;/p&gt;

&lt;p&gt;The Vercel build cache seems to save a copy of your &lt;code&gt;node_modules&lt;/code&gt; folder after the most recent build (creating a cache of it). But, when Prisma generates its client (via the &lt;code&gt;prisma generate&lt;/code&gt; command) the client gets stored in the &lt;code&gt;node_modules&lt;/code&gt; folder. Which is cached.&lt;/p&gt;

&lt;p&gt;The problem is here: if you push a schema change to your app (via git), the app gets deployed to Vercel. Who will use the current build cache (and therefore the old PrismaClient) in the new deployment of your app. So your app tries to use any of the updates database schema fields or tables, the older cached version of the client will not find them. Kicking and error and making your app not work. Sad.&lt;/p&gt;

&lt;p&gt;This is obviously a problem for Prisma/Vercel users (like myself).&lt;/p&gt;

&lt;p&gt;So this is what I have found works, you have two options:&lt;/p&gt;

&lt;h3&gt;
  
  
  #23. Option 1: what the PrismaJS team recommends
&lt;/h3&gt;

&lt;p&gt;The wonderful people over at PrismaJS recommend adding the &lt;code&gt;prisma generate&lt;/code&gt; command into your &lt;code&gt;vercel-build&lt;/code&gt; command (in your &lt;code&gt;pacakge.json&lt;/code&gt; file).&lt;/p&gt;

&lt;p&gt;So every time your code is deployed, the newest PrismaClient will be generated. Good day right? Well....&lt;/p&gt;

&lt;p&gt;This method will force the Vercel builder to run this command for every single one of your serverless functions it builds. Including each of your serverless API routes. Which add up quickly.&lt;/p&gt;

&lt;p&gt;So in result, your builds will take WAY longer. Since it will generate the client multiple times in the same build. This is fine if you are making regular changes to your database schema. But be honest, how often do you update your database schema vs how often do your commit new code to your app???&lt;/p&gt;

&lt;p&gt;I don't use this method.&lt;/p&gt;

&lt;h3&gt;
  
  
  #24. Option 2: what I think works the best
&lt;/h3&gt;

&lt;p&gt;After making database changes and updating my &lt;code&gt;prisma.schema&lt;/code&gt; file, I know I need to generate a new PrismaClient the next time I push to Vercel (either for production or staging environments).&lt;/p&gt;

&lt;p&gt;Before committing my production ready code to the production git branch, I use the Vercel CLI to publish to production first. Why? Because the Vercel CLI can force regenerate the build cache. And push to production.&lt;/p&gt;

&lt;p&gt;I run this command: &lt;code&gt;vercel -f --prod&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then after that build is complete, I push to git. This does create another complete "production" build in Vercel, but I usually go in and cancel it.&lt;/p&gt;

&lt;p&gt;While still being a bit subpar, I personally think this is the best option. Mainly because this only becomes an inefficient solution when you have made a database schema change. Which after the first bit of work on a project is not that often.&lt;/p&gt;

&lt;p&gt;PS: I have talked with a Vercel developer advocate about this before, and he understand that it is suboptimal. And they are going to look into ways to make it better 😁 Go Vercel!&lt;/p&gt;




&lt;h2&gt;
  
  
  Some useful reads from the web
&lt;/h2&gt;

&lt;p&gt;As I have journey around the Vercel platform (and the internet trying to figure things out), I have collected these very useful resources for people using Vercel. I hope they help you too:&lt;/p&gt;

&lt;h3&gt;
  
  
  Official posts and docs from the people of Vercel:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://vercel.com/docs/cli" rel="noopener noreferrer"&gt;https://vercel.com/docs/cli&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vercel.com/docs/concepts/projects/environment-variables" rel="noopener noreferrer"&gt;https://vercel.com/docs/concepts/projects/environment-variables&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vercel.com/docs/runtimes#official-runtimes/node-js" rel="noopener noreferrer"&gt;https://vercel.com/docs/runtimes#official-runtimes/node-js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vercel.com/docs/runtimes#advanced-usage/advanced-node-js-usage" rel="noopener noreferrer"&gt;https://vercel.com/docs/runtimes#advanced-usage/advanced-node-js-usage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vercel.com/guides/using-express-with-vercel" rel="noopener noreferrer"&gt;https://vercel.com/guides/using-express-with-vercel&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Assorted other places around the web
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/nuxt/vercel-builder" rel="noopener noreferrer"&gt;https://github.com/nuxt/vercel-builder&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/nuxt/vercel-builder/blob/main/examples/basic/vercel.json" rel="noopener noreferrer"&gt;https://github.com/nuxt/vercel-builder/blob/main/examples/basic/vercel.json&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/a/62751586/17609674" rel="noopener noreferrer"&gt;https://stackoverflow.com/a/62751586/17609674&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/geekculture/deploy-express-project-with-multiple-routes-to-vercel-as-multiple-serverless-functions-567c6ea9eb36" rel="noopener noreferrer"&gt;https://medium.com/geekculture/deploy-express-project-with-multiple-routes-to-vercel-as-multiple-serverless-functions-567c6ea9eb36&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/a/6064205/17609674" rel="noopener noreferrer"&gt;https://stackoverflow.com/a/6064205/17609674&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.logrocket.com/serverless-deployments-vercel-node-js/" rel="noopener noreferrer"&gt;https://blog.logrocket.com/serverless-deployments-vercel-node-js/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arunas.dev/nuxt-js-with-an-express-js-api-server-running-on-now-sh/" rel="noopener noreferrer"&gt;https://arunas.dev/nuxt-js-with-an-express-js-api-server-running-on-now-sh/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  So the real question: is Vercel worth it?
&lt;/h2&gt;

&lt;p&gt;In short, yes.&lt;/p&gt;

&lt;p&gt;After my few odd months of using Vercel, including testing and deploying my first production app to Vercel (this &lt;a href="https://other.link" rel="noopener noreferrer"&gt;url shortener&lt;/a&gt; service), I have to say: Vercel is great.&lt;/p&gt;

&lt;p&gt;The platform is well built, the docs and developer experience is great, and the people of Vercel often reach out and try their best to help when users run into issues. (like I said early, several different employees reached out trying to help me already)&lt;/p&gt;

&lt;p&gt;The biggest downside for me: NuxtJS. The support for Nuxt is a bit lacking on Vercel, both in documentation and out of the box support. Which I guess is understandable, considering Vercel runs/supports the competing javascript framework NextJS.&lt;/p&gt;

&lt;p&gt;But in the end, I am a very happy user of Vercel. And plan to be for the foreseeable future.&lt;/p&gt;

&lt;p&gt;And who knows, maybe I will work there one day... ✌&lt;/p&gt;




&lt;p&gt;This article was originally posted to my personal site at &lt;a href="https://frostbutter.com/articles/vercel-the-first-time/" rel="noopener noreferrer"&gt;frostbutter.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vercel</category>
      <category>nuxt</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>Fix PHP fatal error "allowed memory size of"</title>
      <dc:creator>Nick Frostbutter</dc:creator>
      <pubDate>Fri, 28 Jan 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/nickfrosty/fix-php-fatal-error-allowed-memory-size-of-1n1e</link>
      <guid>https://dev.to/nickfrosty/fix-php-fatal-error-allowed-memory-size-of-1n1e</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8XSnul4n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/php-errors/php-memory-limit-thumbnail-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8XSnul4n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/php-errors/php-memory-limit-thumbnail-1.png" alt="Fix PHP fatal error" title="Fix PHP fatal error" width="880" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This fatal error occurs when your web app or website is using too much memory. Plain and simple. Just like a local application running on your computer, your website takes some amount of memory to run. So at your site runs on your hosting provider's servers, you are using up some of that server's memory, known as RAM.&lt;/p&gt;

&lt;p&gt;Once your website has reached the PHP memory limit that is set in your server's PHP configuration file, usually 8MB by default, you run out of your available memory limit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Fixes for "fatal error allowed memory size of"
&lt;/h2&gt;

&lt;p&gt;There are a couple of quick fixes for the PHP "fatal error allowed memory size of" error message. The basic gist of these different fixes: your website needs &lt;strong&gt;MORE&lt;/strong&gt; memory and need to be more efficient. Maybe both.&lt;/p&gt;

&lt;h2&gt;
  
  
  Raise the PHP memory limit with code
&lt;/h2&gt;

&lt;p&gt;The quickest and easiest way to fix the memory limit error is to raise your PHP memory limit. By default, the &lt;a href="https://www.php.net/manual/en/configuration.file.php"&gt;php.ini configuration file&lt;/a&gt; sets the memory limit to a whopping 8MB. This is usually enough for most websites, but not always.&lt;/p&gt;

&lt;p&gt;If you don't have access to the server configuration files, like most people, you can add a single line of PHP code to your website to boost the memory limit of php. Just add the line of code below to any and all pages that are giving you the "php fatal error allowed memory size" error message. And adjust the amount of memory you need to get the website back up and running again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; 
  &lt;span class="nb"&gt;ini_set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"memory_limit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"16M"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Raise the PHP memory limit for server via config files
&lt;/h2&gt;

&lt;p&gt;Alternatively, if you want to boost your memory limit for the entire web server then you can update the php.ini configuration file. Browse over to your web server's php directory and find the php.ini file.&lt;/p&gt;

&lt;p&gt;Browse around in the config file, with some Ctrl + F action, and locate the "memory_limit" setting. It will likely be set to "8MB". Just boost that sucker up to the amount needed to clear the fatal error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DnyNK0IQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/php-errors/php_memory_limit-config-setting.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DnyNK0IQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/php-errors/php_memory_limit-config-setting.png" alt="Raise the PHP memory limit using the php.ini config file" width="880" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; &lt;em&gt;You want to keep the memory limit as low as needed to clear the "allowed memory size" error. It will help your site run faster since it will take up the least memory needed to successfully operate.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Set PHP memory limit in WordPress
&lt;/h2&gt;

&lt;p&gt;If you are using a &lt;a href="https://frostbutter.com/articles/tag/wordpress"&gt;WordPress&lt;/a&gt; website, don't worry. You can also raise your PHP memory limit on WordPress too. Just need to make an update to the wp-config.php file for your website.&lt;/p&gt;

&lt;p&gt;Browse on over to the script using your preferred FTP client, or directly from a cPanel file manager. Once you get it, load up the wp-config.php file into a text editor.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YSFyZr6d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/php-errors/php_memory_limit-wordpress-wp-config-file.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YSFyZr6d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/php-errors/php_memory_limit-wordpress-wp-config-file.png" alt="update the wp-config.php file to raise the memory limit for WordPress" width="880" height="421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You need to add this one line of code into the WordPress config file. (I recommend adding it right after the similar line of code that sets the &lt;code&gt;WP_DEBUG&lt;/code&gt; setting.)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;  &lt;span class="nb"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_MEMORY_LIMIT'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'256M'&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This line of code will tell WordPress to set the PHP memory limit specifically for your WordPress website. After you add the new line of code, save your changes and upload the &lt;code&gt;wp-config.php&lt;/code&gt; file back where you found it.&lt;/p&gt;

&lt;p&gt;You can learn more about the WordPress configuration file from the official WordPress website.&lt;/p&gt;

&lt;h2&gt;
  
  
  Still not Enough Memory Limit??
&lt;/h2&gt;

&lt;p&gt;If you are still getting the "&lt;em&gt;php fatal error allowed memory size of&lt;/em&gt;" error message then your website has a much bigger problem. You for sure need to look into making your website more efficient and taking up less resources.&lt;/p&gt;

&lt;p&gt;For those web developers, you need to figure out when the fatal error message started happening. What changed? Did you push an update to your site? Update some plugins? Install new services or code?&lt;/p&gt;

&lt;p&gt;Try to backtrack in your code, if able, back to the most recent stable version. Then take a good comb though the newer code and see if you can find that &lt;strong&gt;memory leak!&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;This article was originally posted to my personal site at &lt;a href="https://frostbutter.com/articles/fix-php-fatal-error-allowed-memory-size-of"&gt;frostbutter.com&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Create a custom Laravel Valet driver</title>
      <dc:creator>Nick Frostbutter</dc:creator>
      <pubDate>Thu, 20 Jan 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/nickfrosty/create-a-custom-laravel-valet-driver-1op0</link>
      <guid>https://dev.to/nickfrosty/create-a-custom-laravel-valet-driver-1op0</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Flaravel%2Fcreate-a-custom-laravel-valet-driver-hide-php-extensions.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Flaravel%2Fcreate-a-custom-laravel-valet-driver-hide-php-extensions.jpg" title="Create a custom Laravel Valet driver" alt="Create a custom Laravel Valet driver"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Valet is the best! I mean it. Perfect for the a solid, lightweight, and minimal development environment. You can link your project's directory then browse to the project using a ".test" domain. So clean.&lt;/p&gt;

&lt;p&gt;The problem that I faced was that I don't use Laravel. A sin for a php developer I know. So in order to be able to use Valet style ".test" domains for my custom web apps, I must create a custom Valet driver for your app. Luckily, if you write it once (or use mine) then you will be set until Valet or Laravel changes a bunch. So basically, forever 🤞&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Valet driver?
&lt;/h2&gt;

&lt;p&gt;Just a single class. Specifically a custom class that extends the " &lt;strong&gt;LaravelValetDriver&lt;/strong&gt;" class. The goal of these custom drivers enables developers to use Valet for other web apps or CMS that are not natively supported in Valet.&lt;/p&gt;

&lt;p&gt;You can use these drivers to specifically handle the routes needed for your web app on your local dev environment to speed up and betterify (real word) your dev life.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to save your custom Valet driver?
&lt;/h2&gt;

&lt;p&gt;Really you have a few options. Most of the default drivers that come with Valet are stored inside of the local default folder at &lt;em&gt;~/.config/valet/Drivers&lt;/em&gt;. This is where you can save all of your custom, reusable drivers. They will be automatically loaded by Valet when pages are rendered. No more setup needed.&lt;/p&gt;

&lt;p&gt;You can also add the unique driver into your web app's working directory. Say you are building you app in your &lt;em&gt;C:\xampp\htdocs\mysweetapp&lt;/em&gt;. You place the custom driver inside the root of your apps folder. It However, it must be named " &lt;strong&gt;LocalValetDriver.php&lt;/strong&gt;". When you link this folder to Valet, it will automatically use this local driver for your site " &lt;strong&gt;mysweetapp&lt;/strong&gt;".&lt;/p&gt;

&lt;p&gt;For this article, I will be doing the second option.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a file named LocalValetDriver.php
&lt;/h2&gt;

&lt;p&gt;This local valet driver will be loaded only for the current application. No more, no less.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;LocalValetDriver&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;LaravelValetDriver&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/** your code here */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we extend the built in Laravel class named &lt;strong&gt;LaravelValetDriver&lt;/strong&gt; , we are required to have 2 functions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;serves()&lt;/strong&gt;, and&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;frontControllerPath()&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  "serves" function
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;serves()&lt;/strong&gt; function is used to determine if the current web app should use the valet driver. It receives 3 parameters returns true or false. If &lt;strong&gt;serves()&lt;/strong&gt; returns a &lt;em&gt;true&lt;/em&gt;, then Valet will attempt to use the driver to actually load and process your website. We want true.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;$sitePath&lt;/strong&gt; : the absolute path that your linked site inside of valet (e.g. &lt;em&gt;C:\xampp\htdocs\mysweetapp&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;$siteName&lt;/strong&gt; : the name that your valet site (e.g. &lt;em&gt;mysweetapp&lt;/em&gt;); the same name used for your .test site (e.g. &lt;em&gt;mysweetapp.test&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;$uri&lt;/strong&gt; : the actual uri from the browser request; say you visit mysweetapp.test/contact, the uri is "contact". If you browse to &lt;em&gt;mysweetapp.test&lt;/em&gt;, the uri is &lt;em&gt;empty&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The logic inside the function is simple. We check for specific files that are specific to the web app or CMS you want to use this custom driver for. WordPress for example would check for wp-config.php.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cd"&gt;/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;serves&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sitePath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$siteName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;file_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sitePath&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'/init.php'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;file_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sitePath&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'/config.ini'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For my app, I am checking for 2 files: &lt;strong&gt;init.php&lt;/strong&gt; * and &lt;strong&gt;config.ini&lt;/strong&gt;. These files then would need to exists inside If they exists my working directory, &lt;em&gt;C:\xampp\htdocs\mysweetapp\this-file-here.php&lt;/em&gt;. If they are both found, then the driver will be loaded and used by Valet.&lt;/p&gt;

&lt;h2&gt;
  
  
  "frontControllerPath" function
&lt;/h2&gt;

&lt;p&gt;The frontControllerPath function returns the full absolute path of the page being loaded on your website. Fully resolved, as they say. This function is the heart of your custom driver. It will perform all the logic to check if the file exists. Even use it to hide php file extensions with Valet (like I do).&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;frontControllerPath()&lt;/strong&gt; function takes the same parameters as the &lt;strong&gt;serves()&lt;/strong&gt; function. The exact same. How convenient.&lt;/p&gt;

&lt;p&gt;In my custom driver's function, I first check if the the request uri is the root of a directly (e.g. &lt;em&gt;mysweetapp.test&lt;/em&gt;) and loading the index.php file by default.&lt;/p&gt;

&lt;p&gt;Next checking if the request uri is an actual file that exits with the given extension (e.g. mysweetapp.test/page1.php).&lt;/p&gt;

&lt;p&gt;Then checking if the the uri exists with the added php extension (e.g. &lt;em&gt;mysweetapp.test/page_name&lt;/em&gt; turns into &lt;em&gt;page_name.php&lt;/em&gt;). This will effectively &lt;strong&gt;hide php extensions inside of Valet&lt;/strong&gt;. I love it and use it for every web app.&lt;/p&gt;

&lt;p&gt;Finally defaulting to the 404 page that is located inside the &lt;strong&gt;public_html&lt;/strong&gt; directory. If no 404.php file exists, then it will default to the default Valet 404 page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cd"&gt;/**
    * Get the fully resolved path to the application's front controller.
    * @param string $sitePath
    * @param string $siteName
    * @param string $uri
    * @return string
*/&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;frontControllerPath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sitePath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$siteName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'index.php'&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="c1"&gt;// add the public folder to the sitePath&lt;/span&gt;
    &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'/public_html'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// smart handle the requests, defaulting to index.php in directories and hiding php extensions&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;is_dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;file_exists&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/index.php'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/index.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;file_exists&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;file_exists&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'.php'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/404.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Complete custom Valet driver for a custom web app&lt;/p&gt;

&lt;p&gt;The complete working version of my custom Valet driver is below. Of course feel free to modify it to your hearts content. Source available on GitHub.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="cd"&gt;/**
* Local valet driver for a custom framework or web app
* by Nick Frostbutter (https://frostbutter.com)
* - loads index.php file by default in all directories
* - hides "php" extensions by default
* Tutorial: https://frostbutter.com/articles/create-a-custom-laravel-valet-driver-hide-php-extensions
*/&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;LocalValetDriver&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;LaravelValetDriver&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/**
    * Determine if the driver serves the request.
    *
    * @param string $sitePath
    * @param string $siteName
    * @param string $uri
    * @return bool
    */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;serves&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sitePath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$siteName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;file_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sitePath&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'/init.php'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;file_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sitePath&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'/config.ini'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="cd"&gt;/**
    * Get the fully resolved path to the application's front controller.
    *
    * @param string $sitePath
    * @param string $siteName
    * @param string $uri
    * @return string
    */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;frontControllerPath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sitePath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$siteName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'index.php'&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="c1"&gt;// add the public folder to the sitePath&lt;/span&gt;
        &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'/public_html'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// smart handle the requests, defaulting to index.php in directories and hiding php extensions&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;is_dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;file_exists&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/index.php'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/index.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;file_exists&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;file_exists&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'.php'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$sitePath&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/404.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This driver has been a delight, just like Valet. Making your life as a developer easier is a must.&lt;/p&gt;

&lt;p&gt;If you are interested, you can read more about custom Valet drivers from the &lt;a href="https://laravel.com/docs/8.x/valet#custom-valet-drivers" rel="noopener noreferrer"&gt;Laravel docs here&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;This article on &lt;a href="https://frostbutter.com/articles/create-a-custom-laravel-valet-driver-hide-php-extensions" rel="noopener noreferrer"&gt;how to create a custom laravel valet driver&lt;/a&gt; was originally by me, &lt;a href="https://frostbutter.com" rel="noopener noreferrer"&gt;Nick Frostbutter&lt;/a&gt;, on my personal site.&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>valet</category>
    </item>
    <item>
      <title>Deploy NuxtJS SSG with Cloudflare Pages</title>
      <dc:creator>Nick Frostbutter</dc:creator>
      <pubDate>Mon, 17 Jan 2022 05:00:00 +0000</pubDate>
      <link>https://dev.to/nickfrosty/deploy-nuxtjs-ssg-with-cloudflare-pages-dnd</link>
      <guid>https://dev.to/nickfrosty/deploy-nuxtjs-ssg-with-cloudflare-pages-dnd</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gK731H6C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/deploy-nuxtjs-ssg-with-cloudflare-pages-light3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gK731H6C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/deploy-nuxtjs-ssg-with-cloudflare-pages-light3.jpg" alt="Deploy NuxtJS SSG with Cloudflare Pages" title="Deploy NuxtJS SSG with Cloudflare Pages" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After discovering the wonders of &lt;a href="https://pages.cloudflare.com"&gt;Cloudflare Pages&lt;/a&gt; and tinkering around a bit, I was hooked.&lt;/p&gt;

&lt;p&gt;With the very straightforward "deployment pipeline" I could setup for each of my static NuxtJS websites, I made the move. I shifted all of my &lt;a href="https://nuxtjs.org"&gt;NuxtJS&lt;/a&gt; static websites over to Cloudflare Pages.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;PS: This article is &lt;strong&gt;not&lt;/strong&gt; sponsored by or affiliated with Cloudflare. They just make &lt;strong&gt;really awesome&lt;/strong&gt; products, and give a &lt;strong&gt;very generous&lt;/strong&gt; free plan to people. And I like free. 😁&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Cloudflare Pages?
&lt;/h2&gt;

&lt;p&gt;In case you have not heard about this newer amazing product from the folks at Cloudflare, Pages are a near effortless JAMstack platform to deploy static Git based websites.&lt;/p&gt;

&lt;p&gt;Here's the gist:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;connect your Git account (&lt;a href="https://github.com/nickfrosty"&gt;GitHub&lt;/a&gt; or GitLab)&lt;/li&gt;
&lt;li&gt;select your repo to deploy&lt;/li&gt;
&lt;li&gt;set your build steps (aka generate the static site)&lt;/li&gt;
&lt;li&gt;get a live static website at "your-site-name.pages.dev"&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Use Cloudflare Pages (for free)
&lt;/h3&gt;

&lt;p&gt;To actually deploy any repo, you will need a Cloudflare account. If you don't already have one, you will can &lt;a href="https://dash.cloudflare.com/sign-up/pages"&gt;signup&lt;/a&gt; for one. Don't worry, it's free. Like &lt;em&gt;actually&lt;/em&gt; free. Like &lt;em&gt;no questions asked&lt;/em&gt; free.&lt;/p&gt;

&lt;p&gt;Once in your Cloudflare account, navigate to the "Pages" page. (I know, this is like rocket science here.)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Px3joOSV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/intro-to-cloudflare-pages.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Px3joOSV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/intro-to-cloudflare-pages.png" alt="Get started with Cloudflare Pages" width="880" height="285"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  How to Deploy NuxtJS to Cloudflare Pages
&lt;/h2&gt;

&lt;p&gt;From the Pages window, select the &lt;code&gt;Create a Project&lt;/code&gt; button. You will then be able to connect your GitHub or GitLab account. Either allow access to your entire account, or select the specific repos. You can even select the repos from any of the organizations you are apart of.&lt;/p&gt;

&lt;h3&gt;
  
  
  Select the NuxtJS repo to deploy
&lt;/h3&gt;

&lt;p&gt;From the list of repos, select the NuxtJS SSG repo you want to deploy. Then &lt;code&gt;Begin Setup&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CAR-wKwh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/select-nuxtjs-repo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CAR-wKwh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/select-nuxtjs-repo.png" alt="Select your NuxtJS repo to deploy with Cloudflare Pages" width="880" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Name your project
&lt;/h3&gt;

&lt;p&gt;The project name you choose will automatically give you a &lt;code&gt;*.pages.dev&lt;/code&gt; url to access the production builds of your NuxtJS SSG site.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4PZ4Opyl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/name-your-project-and-select-production-branch.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4PZ4Opyl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/name-your-project-and-select-production-branch.png" alt="Name your project and select the production branch" width="880" height="358"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Select your repo's "production" branch
&lt;/h3&gt;

&lt;p&gt;Next, select the "production" branch for your NuxtJS site. This can be any of the branches that your repo has. It is likely "&lt;em&gt;master&lt;/em&gt;" or "&lt;em&gt;main&lt;/em&gt;". Any pushes to this "production" branch will automatically build your site, and deploy it to your site's domain.&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;Note: At the time of me writing this article, Cloudflare does not currently allow removing this "pages.dev" url from the account.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is because that "&lt;em&gt;pages.dev&lt;/em&gt;" url will also allow you to view all your &lt;code&gt;preview&lt;/code&gt; deployments for your repo. And "&lt;em&gt;preview&lt;/em&gt;" meaning any other commits that are not on your &lt;code&gt;production&lt;/code&gt; branch.&lt;/p&gt;




&lt;h3&gt;
  
  
  Enter your NuxtJS build settings
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_tOdrRuc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/set-your-nuxtjs-build-settings.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_tOdrRuc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/set-your-nuxtjs-build-settings.png" alt="Enter your NuxtJS build settings" width="880" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside of the &lt;code&gt;Build Settings&lt;/code&gt;, select NuxtJS as the framework preset. This will auto populate the build settings to use the default &lt;code&gt;nuxt gnerate&lt;/code&gt; build command, with a final output directory of &lt;code&gt;dist&lt;/code&gt;. If you have manually changed these settings for your Nuxt app, then just update these here. Otherwise, the defaults are likely what you want.&lt;/p&gt;

&lt;h3&gt;
  
  
  Are you deploying a monorepo? No problem!
&lt;/h3&gt;

&lt;p&gt;If you are using a monorepo setup, like I am for the &lt;a href="https://github.com/nickfrosty/nuxt-seo"&gt;nuxt-seo project&lt;/a&gt;, then you can also deploy that to Cloudflare Pages.&lt;/p&gt;

&lt;p&gt;Inside the _ &lt;strong&gt;Build Settings&lt;/strong&gt; _ area, click the &lt;em&gt;&lt;strong&gt;Root directory (advanced)&lt;/strong&gt;&lt;/em&gt; link to view the extra settings.&lt;/p&gt;

&lt;p&gt;To build &lt;strong&gt;only the specific potion&lt;/strong&gt; of your monorepo, like a "docs" site, then enter the name of that directory as the &lt;code&gt;path&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Hv7z4FxF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/deploy-monorepo-with-cloudflare-pages.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Hv7z4FxF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/deploy-monorepo-with-cloudflare-pages.png" alt="Deploy a monorepo with Cloudflare Pages" width="880" height="174"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my case of the &lt;a href="https://npmjs.org/nuxt-seo"&gt;npm nuxt-seo&lt;/a&gt; package, the &lt;a href="https://nuxt-seo.frostbutter.com"&gt;nuxt-seo docs&lt;/a&gt; site is located in the "docs" directory. So my &lt;code&gt;path&lt;/code&gt; is set to "docs" to only generate the static docs site with Cloudflare Pages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Nuxt generate with env vars
&lt;/h3&gt;

&lt;p&gt;If you need to set specific env vars that affect your Nuxt SSG build, then you can enter them in Cloudflare Pages as well:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zxePzEvs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/nuxt-generate-with-env-vars.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zxePzEvs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/nuxt-generate-with-env-vars.png" alt="Set nuxt generate env vars" width="880" height="241"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To read more about the specific ENV vars that Cloudflare automatically exposes, check their &lt;a href="https://developers.cloudflare.com/pages/platform/build-configuration"&gt;build configuration docs&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Set a custom domain for Cloudflare Pages
&lt;/h2&gt;

&lt;p&gt;Once you have a successful build for your new Cloudflare Pages site, you can set a custom domain.&lt;/p&gt;

&lt;p&gt;From inside the Pages manager in the Cloudflare Dashboard, navigate to the _ &lt;strong&gt;Custom Domains&lt;/strong&gt; _ tab. Enter the domain name you wish to use as your primary domain for your Cloudflare Pages static site.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8Oq880pG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/custom-domain-for-cloudflare-pages.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8Oq880pG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/cloudflare/deploy-nuxtjs-ssg/custom-domain-for-cloudflare-pages.png" alt="Setup a custom domain for Cloudflare Pages" width="880" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will then be prompted to update your DNS settings, creating a &lt;code&gt;CNAME&lt;/code&gt; record for your custom domain.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PS: If your DNS is already managed by Cloudflare, you can update the settings with the one click "save" button. If not, then you will have to manually create a &lt;code&gt;CNAME&lt;/code&gt; record with your DNS provider.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  My final thoughts on Cloudflare Pages
&lt;/h2&gt;

&lt;p&gt;With Cloudflare Pages being still fairly new, I have run into a few issues with deployments. Sometimes I will get build failures. Most of the time, these failures were because of Cloudflare Pages using using an older version of Node and NPM by default.&lt;/p&gt;

&lt;p&gt;Fortunately, you can manually set the Node and NPM version using the build ENV settings, like I discussed above.&lt;/p&gt;

&lt;p&gt;Sometimes the builds can be a bit slow, taking ~5-10 minutes to finish the build. But then again, it's free. So I am so very willing to wait for free 😁&lt;/p&gt;

&lt;p&gt;With all that said: &lt;strong&gt;they are awesome, but &lt;em&gt;still&lt;/em&gt; early on.&lt;/strong&gt; I really like the way they are setup and how easy it is to setup an automated deployment pipeline for my static sites (including &lt;a href="https://frostbutter.com/"&gt;my blog here&lt;/a&gt;).&lt;/p&gt;




&lt;p&gt;This article was originally posted to my personal site at &lt;a href="https://frostbutter.com/articles/deploy-nuxt-ssg-with-cloudflare-pages"&gt;frostbutter.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nuxt</category>
      <category>cloudflare</category>
      <category>ssg</category>
      <category>jamstack</category>
    </item>
    <item>
      <title>Setup font awesome in Vue and NuxtJS</title>
      <dc:creator>Nick Frostbutter</dc:creator>
      <pubDate>Wed, 12 Jan 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/nickfrosty/setup-font-awesome-in-vue-and-nuxtjs-4486</link>
      <guid>https://dev.to/nickfrosty/setup-font-awesome-in-vue-and-nuxtjs-4486</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fvue%2Ffont-aweseome-in-vue-and-nuxt-js.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fvue%2Ffont-aweseome-in-vue-and-nuxt-js.jpg" title="Setup font awesome in Vue and NuxtJS" alt="Setup font awesome in Vue and NuxtJS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have been living under a rock for several years and don't know, Fontawesome a wonderful icon library. It's open source, SVG based, and can be used on any website like utility classes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two different options to get awesome
&lt;/h2&gt;

&lt;p&gt;Before the setups steps you should know, there are two ways to use Fontawesome icons in a Vue or Nuxt project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"component" based icons&lt;/li&gt;
&lt;li&gt;or utility "class" based icons&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both options work well, and are really just a matter of preference. But they have very similar setups, so I'll show both methods here.&lt;/p&gt;

&lt;p&gt;With "component" based icons, you can add icons like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;font-awesome-icon&lt;/span&gt; &lt;span class="na"&gt;:icon=&lt;/span&gt;&lt;span class="s"&gt;"['fas', 'user']"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With utility "class" based icons, you can icons like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;i&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"fa fas fa-user"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/i&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With Vue being a componentized framework, some people really love being able to use Fontawesome icons just like any other component. Personally, I do not.&lt;/p&gt;

&lt;p&gt;I really like the utility class method. I find it easier, and I can use other &lt;a href="https://frostbutter.com/articles/tag/tailwind" rel="noopener noreferrer"&gt;Tailwind&lt;/a&gt; utility classes or regular CSS to style icons further when I want to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install the "&lt;em&gt;fortawesome&lt;/em&gt;" packages
&lt;/h2&gt;

&lt;p&gt;That's right. The package is actually &lt;strong&gt;&lt;em&gt;fortawesome&lt;/em&gt;&lt;/strong&gt;. Not fontawesome. Don't ask me why...&lt;/p&gt;

&lt;p&gt;Using your favorite package manager, install the &lt;code&gt;fortawesome&lt;/code&gt; dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; @fortawesome/fontawesome-svg-core @fortawesome/free-solid-svg-icons
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install the " &lt;strong&gt;core&lt;/strong&gt;" package which you must add. As well as the "solid" icon pack. This will allow us to use the solid icons from Fontawesome.&lt;/p&gt;

&lt;p&gt;If you want to add more icons into your project, then you can also install the "brands" and "regular" icon packs. (I end up using the same brand icons, like &lt;a href="https://twitter.com/nickfrosty" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; and GitHub a lot.)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; @fortawesome/free-brands-svg-icons @fortawesome/free-regular-svg-icons
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see the official NPM package here: &lt;a href="https://www.npmjs.com/package/@fortawesome/fontawesome-svg-core" rel="noopener noreferrer"&gt;@fortawesome/fontawesome-svg-core&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Fontawesome in Vue JS
&lt;/h2&gt;

&lt;p&gt;If you are using a regular Vue JS project, then open up your _ &lt;strong&gt;main.js&lt;/strong&gt; _ project file, add add the following code to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* Import all the font awesome goodness */&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;library&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@fortawesome/fontawesome-svg-core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// loads all the "solid" icons&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;fas&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@fortawesome/free-solid-svg-icons&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// loads only the "twitter" brand icon&lt;/span&gt;
&lt;span class="c1"&gt;// import { faTwitter } from '@fortawesome/free-brands-svg-icons'&lt;/span&gt;

&lt;span class="c1"&gt;// add each of the imported icons into the app&lt;/span&gt;
&lt;span class="nx"&gt;library&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fas&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// can be a list of all the icons e.g. (fas, fab, faTwitter, etc)&lt;/span&gt;

&lt;span class="c1"&gt;// to use component based icons&lt;/span&gt;
&lt;span class="c1"&gt;//import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'&lt;/span&gt;

&lt;span class="c1"&gt;// to use class based icons&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;dom&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@fortawesome/fontawesome-svg-core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;dom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note: Specifically, you should add this code before you create your "app" object.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here we are importing the &lt;code&gt;library&lt;/code&gt; object from the &lt;code&gt;fortawesome core&lt;/code&gt;. The library will allow us to specify which icons we want to use in our project. More on&lt;/p&gt;

&lt;p&gt;Next, I import &lt;code&gt;fas&lt;/code&gt; from the &lt;code&gt;solid&lt;/code&gt; icon pack. This is how you import all of the solid icons from the solid icon pack. The same way works for the brand icons. To import all the brand icons, import &lt;code&gt;fab&lt;/code&gt; from the &lt;code&gt;brand&lt;/code&gt; icon pack.&lt;/p&gt;

&lt;p&gt;Make sense?&lt;/p&gt;

&lt;p&gt;If you want to only use a specific icon in your project, you can import only the desired icons from the each icon pack. For example, to only import that twitter icon from the brand pack, use this line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;import { faTwitter } from '@fortawesome/free-brands-svg-icons'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;blockquote&gt;
&lt;p&gt;Note: the icon names are written in Pascal case. (e.g. "faTwitter", &lt;strong&gt;not&lt;/strong&gt;"fa-twitter")&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;After importing all the icons you want for your project, we add them to the library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;library.add(fas); // can be a list of all the icons e.g. (fas, fab, faTwitter, etc)

// addd all solid icons and twitter
library.add(fas, faTwitter);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;add&lt;/code&gt; function, you can pass the list of all the icons you imported and want to use in your project.&lt;/p&gt;

&lt;h3&gt;
  
  
  To use component based icons:
&lt;/h3&gt;

&lt;p&gt;Import the &lt;code&gt;FontAwesomeIcon&lt;/code&gt; component on each of your &lt;em&gt;.vue&lt;/em&gt; pages you want to use the component. This way, you can use font awesome icons like any other vue component. Like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;font-awesome-icon&lt;/span&gt; &lt;span class="na"&gt;:icon=&lt;/span&gt;&lt;span class="s"&gt;"['fas', 'user']"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just pass in an array into the &lt;code&gt;icon&lt;/code&gt; prop. The first item in the array is the library you imported, the second item is the icon name itself.&lt;/p&gt;

&lt;h3&gt;
  
  
  To use the utility class icons:
&lt;/h3&gt;

&lt;p&gt;We import &lt;em&gt;dom&lt;/em&gt; from the fortawesome core. The &lt;code&gt;dom&lt;/code&gt; will allow us to use the utility class method of using the icons. the &lt;code&gt;dom.watch()&lt;/code&gt; function is where the magic happens for Vue to enable the normal font awesome classes to work properly.&lt;/p&gt;

&lt;p&gt;Using this way, you will be able to add fontawesome icons like regular html:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;i&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"fa fas fa-user"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/i&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are going to use the component method for the icons, then you do not need to import &lt;code&gt;dom&lt;/code&gt; or use &lt;code&gt;dom.watch()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But like I said earlier, this is the method that I &lt;strong&gt;REALLY&lt;/strong&gt; prefer. It seems cleaner.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Fontawesome in NuxtJS
&lt;/h2&gt;

&lt;p&gt;If you are trying to add Fontawesome icons into a Nuxt JS app, the setup is very similar. The only difference is that in order to actually tell Nuxt to use Fontawesome icons, you must create a plugin with the code from the section above, then load the plugin in your &lt;code&gt;nuxt.config.js&lt;/code&gt; file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create the Fontawesome plugin
&lt;/h3&gt;

&lt;p&gt;From inside your Nuxt app's root directory, create the new file &lt;code&gt;~/plugins/fontawesome.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you do not already have a &lt;code&gt;plugins&lt;/code&gt; folder, just create it now 🙂&lt;/p&gt;

&lt;p&gt;In the exact way I explained above, import and add all the Fortawesome icons you want to use in your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* Import all the font awesome goodness */&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;library&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dom&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@fortawesome/fontawesome-svg-core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;fas&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@fortawesome/free-solid-svg-icons&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;faTwitter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@fortawesome/free-brands-svg-icons&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;library&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fas&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;faTwitter&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;dom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the code into your new &lt;code&gt;fontawesome.js&lt;/code&gt; plugin file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add your new plugin into your "&lt;em&gt;nuxt.config.js&lt;/em&gt;" file:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;~/plugins/fontawesome.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;],&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All done. Reload your hot server, and give it a test. Enjoy the awesome that is Fontawesome!&lt;/p&gt;




&lt;p&gt;This article on &lt;a href="https://frostbutter.com/articles/setup-font-awesome-in-vue-and-nuxt-js" rel="noopener noreferrer"&gt;how to setup font awesome in vue&lt;/a&gt; was originally by me, &lt;a href="https://frostbutter.com" rel="noopener noreferrer"&gt;Nick Frostbutter&lt;/a&gt;, on my personal blog.&lt;/p&gt;

</description>
      <category>fontawesome</category>
      <category>vue</category>
      <category>nuxt</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Backup and restore MySQL databases (from the command line)</title>
      <dc:creator>Nick Frostbutter</dc:creator>
      <pubDate>Mon, 10 Jan 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/nickfrosty/backup-and-restore-mysql-databases-from-the-command-line-359l</link>
      <guid>https://dev.to/nickfrosty/backup-and-restore-mysql-databases-from-the-command-line-359l</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4Yjm2lPa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/mysql/backup-and-restore-mysql-databasse-from-command-line.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4Yjm2lPa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/mysql/backup-and-restore-mysql-databasse-from-command-line.jpg" alt="Backup and restore MySQL databases (from the command line)" title="Backup and restore MySQL databases (from the command line)" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last few days, I have been migrating &lt;a href="https://frostbutter.com/projects"&gt;my side projects&lt;/a&gt; between two different servers.&lt;/p&gt;

&lt;p&gt;While doing so, I needed a quick way to also backup and restore the MySQL databases. The most simplest and most effective way to do is is with the command line. Using the &lt;code&gt;mysqldump&lt;/code&gt; and &lt;code&gt;mysql&lt;/code&gt; commands.&lt;/p&gt;

&lt;p&gt;PS: Sometimes I do use phpMyAdmin to create a quick database backup. But sometimes, I will get some weird errors while trying to import the database later. Also, phpMyAdmin gets limited by your server's PHP file upload limit.&lt;/p&gt;

&lt;h2&gt;
  
  
  TLDR;
&lt;/h2&gt;

&lt;p&gt;The quick and dirty version:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;have your MySQL username, password, and database name on hand&lt;/li&gt;
&lt;li&gt;ensure this MySQL user has the correct permission to create tables and records&lt;/li&gt;
&lt;li&gt;upload your backup file to the new MySQL server (if it's different from the initial server)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Backup your MySQL database with mysqldump
&lt;/h3&gt;

&lt;p&gt;To create a MySQL backup from the command line, use the &lt;code&gt;mysqldump&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysqldump &lt;span class="nt"&gt;-u&lt;/span&gt; mysql_username &lt;span class="nt"&gt;-p&lt;/span&gt; datbase_name &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /path/to/the/new/backup/file.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will get prompted for your the password for the &lt;code&gt;mysql_username&lt;/code&gt; account. Then, your database backup will begin.&lt;/p&gt;

&lt;p&gt;This will create a full MySQL database backup to the same server in a new file located at &lt;code&gt;/path/to/the/new/backup/file.sql&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If this file already exists, it will be overridden. If your ssh account does not have write access to this file location, then the backup operation will fail.&lt;/p&gt;

&lt;h3&gt;
  
  
  Transfer the database backup to the new server
&lt;/h3&gt;

&lt;p&gt;If you need to transfer the database backup to a different server, like I did, you can securely download it using the &lt;code&gt;scp&lt;/code&gt; command from &lt;strong&gt;your local computer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To &lt;strong&gt;download&lt;/strong&gt; a file with &lt;code&gt;scp&lt;/code&gt;, run this on your local computer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;scp remote_user_1@server_1_ip:/path/to/remote/file.sql /path/to/local/computer/save/directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you can &lt;strong&gt;upload&lt;/strong&gt; the file to the other server, run this on your local computer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;scp /path/to/local/computer/save/file.sql remote_user_2@server_2_ip:/path/to/upload/remote/file.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Restore a MySQL backup
&lt;/h3&gt;

&lt;p&gt;With your backup file on the final server (or even the same server as the backup was taken from), you can restore the MySQL database backup from the command line using the &lt;code&gt;mysql&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql &lt;span class="nt"&gt;-u&lt;/span&gt; mysql_username &lt;span class="nt"&gt;-p&lt;/span&gt; database_name &amp;lt; /absolute/path/to/the/backup.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When prompted, enter your MySQL user account's password. Then you're off to the races! 🚀&lt;/p&gt;

&lt;p&gt;Your database tables and records will begin to be created. The overall time for this to complete will vary based on the backup size, compression, and server specs.&lt;/p&gt;




&lt;h2&gt;
  
  
  How to backup and restore a MySQL database
&lt;/h2&gt;

&lt;p&gt;To actually backup and restore the MySQL database backup using the command line, you will need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the MySQL username and password for the database&lt;/li&gt;
&lt;li&gt;command line access to your MySQL server&lt;/li&gt;
&lt;li&gt;a database that your MySQL user has permissions to access, (or permissions to create one)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are using a MySQL provider like DigitalOcean, like me, then you should be able to SSH into the server and be ready to go. If you are using a MySQL provider like Bluehost or A2 hosting, then you may need to request SSH access from their support line.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connect to your MySQL server
&lt;/h2&gt;

&lt;p&gt;Using the command line, SSH into your MySQL server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh server_username@ip_address
&lt;span class="c"&gt;# or&lt;/span&gt;
ssh server_username@domain.tld
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  List your MySQL databases
&lt;/h3&gt;

&lt;p&gt;If you do not already know the name of the database you want to create a backup of, then you can list the MySQL databases your MySQL user account has access to:&lt;/p&gt;

&lt;p&gt;Using the &lt;code&gt;mysql&lt;/code&gt; command line tool, aka &lt;code&gt;cli&lt;/code&gt;, and a valid username and password:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql &lt;span class="nt"&gt;-u&lt;/span&gt; mysql_username &lt;span class="nt"&gt;-p&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will get prompted to enter this MySQL user's account password. Then this will connect to the database server, with the MySQL user &lt;code&gt;mysql_username&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The &lt;code&gt;-p&lt;/code&gt; flag will let the terminal to prompt us for the password. Without the &lt;code&gt;-p&lt;/code&gt; flag, then your connection will likely fail. Saying something like "&lt;em&gt;password required&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;When your connection was successful, you can list the MySQL databases the &lt;code&gt;mysql_username&lt;/code&gt; account has access to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;show databases&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you know the database name, exit from the &lt;code&gt;mysql&lt;/code&gt; cli:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a MySQL database backup with mysqldump
&lt;/h2&gt;

&lt;p&gt;In order to create our MySQL database backup, especially for a quick full backup, I like to use the &lt;code&gt;mysqldump&lt;/code&gt; command. Not only is it installed with MySQL (and MariaDB) by default, but the command has basically the same syntax as the &lt;code&gt;mysql&lt;/code&gt; command. But more on that in a bit.&lt;/p&gt;

&lt;p&gt;With the name of your database on hand, run the &lt;code&gt;mysqldump&lt;/code&gt; command like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysqldump &lt;span class="nt"&gt;-u&lt;/span&gt; mysql_username &lt;span class="nt"&gt;-p&lt;/span&gt; datbase_name &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /path/to/the/new/backup/file.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-u mysql_username&lt;/code&gt; - connects to the MySQL database with the MySQL user account names '&lt;em&gt;mysql_username&lt;/em&gt;'&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-p&lt;/code&gt; - tells MySQL to prompt me to enter the user's password&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;datbase_name&lt;/code&gt; - simply the name of the MySQL database you want to backup&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt; /path/to/the/new/backup/file.sql&lt;/code&gt; - pipes the output from the command into a local file on the same server&lt;/li&gt;
&lt;/ul&gt;




&lt;blockquote&gt;
&lt;p&gt;Notice the direction of the &lt;code&gt;&amp;gt;&lt;/code&gt; character. This tells the command to send the mysql database records into the specified file.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;After running the command, you will get prompted for your the password for the &lt;code&gt;mysql_username&lt;/code&gt; account. Then, your database backup will begin. Unfortunately, you will not see any change in the terminal while the backup is in progress. But once it is done, the terminal will drop back to the prompt. Allowing you to continue.&lt;/p&gt;

&lt;p&gt;And naturally, the time to create the backup will vary based on the size of the database and the specs of the server. For a benchmark, my database was about 500k records and took ~2mins.&lt;/p&gt;

&lt;h2&gt;
  
  
  Securely download your database backup
&lt;/h2&gt;

&lt;p&gt;If you &lt;em&gt;need&lt;/em&gt; to transfer the database backup to a different server, like I did, you can securely download it using the "&lt;em&gt;secure copy&lt;/em&gt;" command &lt;code&gt;scp&lt;/code&gt; command from &lt;strong&gt;your local computer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To &lt;strong&gt;download&lt;/strong&gt; a file with &lt;code&gt;scp&lt;/code&gt;, run this on your local computer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;scp remote_user_1@server_1_ip:/path/to/remote/file.sql /path/to/local/computer/save/directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Securely upload your database backup
&lt;/h2&gt;

&lt;p&gt;In order to actually restore the backup on your MySQL server, you will need to upload the backup file to the new server.&lt;/p&gt;

&lt;p&gt;To &lt;strong&gt;upload&lt;/strong&gt; the database backup from your local computer, use the "&lt;em&gt;secure copy&lt;/em&gt;" command &lt;code&gt;scp&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;scp /path/to/local/computer/save/file.sql remote_user_2@server_2_ip:/path/to/upload/remote/file.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Both of these &lt;code&gt;scp&lt;/code&gt; command examples are run from my &lt;strong&gt;local computer&lt;/strong&gt; since the SSH keys for each of these servers are on my computer. If you have the SSH keys setup to transfer files directly between these two servers, then you could simply &lt;code&gt;scp&lt;/code&gt; between the two.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create your MySQL database server
&lt;/h3&gt;

&lt;p&gt;Now that we are connected, we can show the list of available MySQL databases:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;show databases&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Delete MySQL database (as needed)
&lt;/h3&gt;

&lt;p&gt;If you are restoring from a complete MySQL database backup from &lt;code&gt;mysqldump&lt;/code&gt;, then you may need to delete the already existing database, then recreate it. Counter-productive, I know.&lt;/p&gt;

&lt;p&gt;To delete a MySQL database, use this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;drop database name_here&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In order to DELETE new MySQL databases, you user account will need the &lt;code&gt;DELETE&lt;/code&gt; permission item. If your account does not have it, you may need to DELETE the database from your hosting control panel.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Create a new MySQL database
&lt;/h3&gt;

&lt;p&gt;If it does not already exist on the server, you can create a new MySQL database with this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;create database name_here&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In order to CREATE new MySQL databases, you user account will need the &lt;code&gt;CREATE&lt;/code&gt; permission item. If your account does not have it, you may need to CREATE the database from your hosting control panel.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Select the MySQL database to restore
&lt;/h3&gt;

&lt;p&gt;Once your database exists, you can select it with the &lt;code&gt;use&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;use database_name&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You &lt;strong&gt;must select&lt;/strong&gt; (aka &lt;code&gt;use&lt;/code&gt;) the database to use in order to restore the backup.&lt;/p&gt;

&lt;h2&gt;
  
  
  Restore the MySQL database from the backup
&lt;/h2&gt;

&lt;p&gt;Since we have uploaded our database backup, we are ready to restore this backup.&lt;/p&gt;

&lt;p&gt;Exit from the mysql cli, using the &lt;code&gt;exit;&lt;/code&gt; command. Then from the regular terminal prompt, restore your database backup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql &lt;span class="nt"&gt;-u&lt;/span&gt; mysql_username &lt;span class="nt"&gt;-p&lt;/span&gt; database_name &amp;lt; /absolute/path/to/the/backup.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Notice the direction of the &lt;code&gt;&amp;lt;&lt;/code&gt; character. This tells the command to read the contents of the file and send it to the mysql program. (aka import the backup)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hope this article helped our. Happy backups! 😁&lt;/p&gt;




&lt;p&gt;This article was on &lt;a href="https://frostbutter.com/articles/restore-mysql-database-from-backup-with-command-line/"&gt;how to backup and restore a MySQL database&lt;/a&gt; was originally posted to my personal site at &lt;a href="https://frostbutter.com"&gt;frostbutter.com&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Add CSS Scroll Animation and Smooth Scrolling</title>
      <dc:creator>Nick Frostbutter</dc:creator>
      <pubDate>Fri, 07 Jan 2022 14:42:20 +0000</pubDate>
      <link>https://dev.to/nickfrosty/add-css-scroll-animation-and-smooth-scrolling-34on</link>
      <guid>https://dev.to/nickfrosty/add-css-scroll-animation-and-smooth-scrolling-34on</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fux-tips%2Fcss-scroll-behavior-scroll-animation-and-smooth-scrolling.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fux-tips%2Fcss-scroll-behavior-scroll-animation-and-smooth-scrolling.jpg" title="Add CSS Scroll Animation and Smooth Scrolling" alt="Add CSS Scroll Animation and Smooth Scrolling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The basic way to add smooth scroll animation is using anchors/indexes on your website. Those are the hashtag urls that you can set inside of a link. By default, if someone clicks on of the link their browser will jerk them down to the location of the anchor/id on the page. No so pretty looking. And certainly not a great user experience.&lt;/p&gt;

&lt;p&gt;So, how to add the smooth scroll animation you ask?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;add the anchor link on your page: &lt;code&gt;&amp;lt;a href="#my_link"&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;create the anchor endpoint on the page element: &lt;code&gt;&amp;lt;div id="my_link"&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;add the CSS scroll animation property, aka &lt;code&gt;scroll-behavior&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;enjoy&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Add the anchor for smooth scrolling
&lt;/h2&gt;

&lt;p&gt;Assuming you have your website already setup, find whichever link you want to use as your action. Simply assign the href parameter with a hashtag ("#") link of the id the page element to stop scrolling at.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#myelement"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;click here to scroll to "myelement"&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Create the smooth scroll endpoint element
&lt;/h2&gt;

&lt;p&gt;Next, assign an "id" attribute to the element you want your smooth scroll to stop at. Make sure you give it the exact same name as previously used in the anchor tag. But without the "#" in the id value.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"whatever"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"myelement"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Add CSS scroll animation with "scroll-behavior"
&lt;/h2&gt;

&lt;p&gt;With your page's anchor and endpoint all setup on your website, you can add the smooth scrolling effect by adding this single line into your main CSS file for your website:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;scroll-behavior&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;smooth&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; It is important to add the &lt;code&gt;scroll-behavior&lt;/code&gt; style on to the &lt;code&gt;html&lt;/code&gt; tag so your entire website will have the smooth scrolling effect.&lt;/p&gt;

&lt;p&gt;Some people, including myself, have tried to set the smooth scrolling on the &lt;code&gt;body&lt;/code&gt; tag. But that does not work for some reason.&lt;/p&gt;

&lt;p&gt;Once you save your changes, and reload the CSS into the browser, your snazzy new smooth scrolling will be in effect.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS scroll animation on old browsers?
&lt;/h2&gt;

&lt;p&gt;The downside of this UX tip, is that the CSS scroll animation does not work in older browsers. But anyone using any reasonable modern browser should be fine. And worst case, they won't get the added UX boost. But let's be honest, if they are using an older browser (cough internet explorer cough) then they already make poor life decisions. And obviously not looking for the best user experience on the web. Right?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fux-tips%2FQuick-UX-Tips-CSS-Scroll-Animation-with-Smooth-Scrolling-browser-support.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fux-tips%2FQuick-UX-Tips-CSS-Scroll-Animation-with-Smooth-Scrolling-browser-support.png" alt="web browser support for css smooth scrolling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The good news is that browser support for the CSS scroll-behavior property has been around for a bit. So that's a plus :)&lt;/p&gt;




&lt;p&gt;This article on &lt;a href="https://frostbutter.com/articles/css-scroll-animation-and-smooth-scrolling-with-scroll-behavior" rel="noopener noreferrer"&gt;css scroll animation&lt;/a&gt; was originally posted to my personal site at &lt;a href="https://frostbutter.com" rel="noopener noreferrer"&gt;frostbutter.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>scroll</category>
      <category>animation</category>
    </item>
    <item>
      <title>JavaScript current year with getFullYear()</title>
      <dc:creator>Nick Frostbutter</dc:creator>
      <pubDate>Sat, 01 Jan 2022 14:27:58 +0000</pubDate>
      <link>https://dev.to/nickfrosty/javascript-current-year-with-getfullyear-h1c</link>
      <guid>https://dev.to/nickfrosty/javascript-current-year-with-getfullyear-h1c</guid>
      <description>&lt;p&gt;Did you hard code the year in your footer? New year, new problems. &lt;/p&gt;

&lt;p&gt;With this one-liner, you can dynamically set the year with JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;year&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;getFullYear&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are using &lt;a href="https://vuejs.org"&gt;VueJS&lt;/a&gt; or &lt;a href="https://nuxtjs.org"&gt;NuxtJS&lt;/a&gt;, you can add the current year code directly into your template section&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;footer&amp;gt;&lt;/span&gt;
        Copyright © &lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;getFullYear&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/footer&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can find more useful dev articles on my site, &lt;a href="https://frostbutter.com/articles"&gt;frostbutter.com/articles&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>nuxt</category>
      <category>javascript</category>
      <category>newyears</category>
    </item>
    <item>
      <title>How to Install Ghost CMS on Windows localhost</title>
      <dc:creator>Nick Frostbutter</dc:creator>
      <pubDate>Wed, 29 Dec 2021 20:19:56 +0000</pubDate>
      <link>https://dev.to/nickfrosty/how-to-install-ghost-cms-on-windows-localhost-28ea</link>
      <guid>https://dev.to/nickfrosty/how-to-install-ghost-cms-on-windows-localhost-28ea</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fghost%2FHow-to-Install-Ghost-CMS-on-Windows-localhost.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fghost%2FHow-to-Install-Ghost-CMS-on-Windows-localhost.jpg" alt="Cover image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The thing about trying to install Ghost CMS on Windows is that there a few, let's say nuances. Ghost CMS is actually designed to be run on a specific Ubuntu linux version. So you have to perform some extra steps to setup a Ghost blog on Windows. Fear not, it can and shall be done.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick overview to install Ghost CMS on Windows
&lt;/h2&gt;

&lt;p&gt;(1) To actually install Ghost CMS on Windows, you will need to get the backend server setup. So you will have to install NodeJS server, if you don't already have it. Which most people on Windows don't already have a NodeJS server setup. Since most just using something like XAMPP for a localhost PHP/MySQL server.&lt;/p&gt;

&lt;p&gt;(2) After NodeJS is installed, you can use the Node Package Manager (aka npm) to install Ghost blog on Windows. When installing Ghost locally, it will actually use a local SQLite database for you to perform your testing on. No need to worry about having a MySQL database installed and ready to use with Ghost CMS. How nice of them :)&lt;/p&gt;

&lt;p&gt;(3) Once your localhost Ghost blog is installed, you can work your way through the very simple setup wizard to create your account and start getting to know Ghost CMS.&lt;/p&gt;

&lt;p&gt;Let's get to it!&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Node JS server on windows
&lt;/h2&gt;

&lt;p&gt;Download the NodeJS installer from &lt;a href="https://NodeJS.org" rel="noopener noreferrer"&gt;NodeJS.org&lt;/a&gt;. You can run through the generic Windows installer pretty smoothly. I recommend leaving all the defaults set as to where NodeJS will install to and the packages tit will install. This just makes things easier.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fghost%2FHow-to-Install-Ghost-CMS-on-Windows-localhost-install-NodeJS-on-Windows.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fghost%2FHow-to-Install-Ghost-CMS-on-Windows-localhost-install-NodeJS-on-Windows.png" alt="install Node JS and NPM from the official website"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you are using Visual Studio Code, like most developers using Windows, then you should for sure install &lt;a href="https://community.chocolatey.org/packages/vscode" rel="noopener noreferrer"&gt;Chocolatey&lt;/a&gt;. It will also install the VS Code addons to enable better integration into VS Code for your Ghost CMS editing.&lt;/p&gt;

&lt;p&gt;As you install Node JS on Windows, you will get a PowerShell prompt that will run through a portion of the installation. This PowerShell will install Python, Chocolatey, and Visual Studio Tools if you do not already have them installed. Do note, it can take a few minutes to install all of these thing. Totally okay. I think my installation took about 5 minutes.&lt;/p&gt;

&lt;p&gt;So go get a fresh cup of coffee ☕&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fghost%2FHow-to-Install-Ghost-CMS-on-Windows-localhost-verify-NodeJS-and-npm-are-installed-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fghost%2FHow-to-Install-Ghost-CMS-on-Windows-localhost-verify-NodeJS-and-npm-are-installed-1.png" alt="verify node and npm are installed using terminal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should restart your computer after installing NodeJS in order for all of the new dependencies and software packages to work properly.&lt;/p&gt;

&lt;p&gt;To verify Node is installed, run the node -v command and npm -v command in your windows terminal or PowerShell. (I prefer the terminal that is built into VS Code). The two commands should return the version number of your Node and node package manager (npm) version. If the return a number, then you are good to go. If not, then your installation was not successful and you might need to try again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Ghost CMS on Windows
&lt;/h2&gt;

&lt;p&gt;Once NodeJS is installed, you can either download the &lt;a href="https://github.com/TryGhost/Ghost" rel="noopener noreferrer"&gt;official Ghost source code from GitHub&lt;/a&gt; or use node package manager (npm) to install Ghost CMS. I prefer using npm since it is way faster and easier. So that is what I will show below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fghost%2FHow-to-Install-Ghost-CMS-on-Windows-localhost-download-Ghost-CMS-from-GitHub-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fghost%2FHow-to-Install-Ghost-CMS-on-Windows-localhost-download-Ghost-CMS-from-GitHub-1.png" alt="download Ghost CMS from GitHub"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: At the time of me writing article, Ghost 3.0 is the most up to date version of Ghost CMS. But the installation should be about the same with future versions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to install Ghost CMS?
&lt;/h2&gt;

&lt;p&gt;Honestly, chose any folder you would like. Since Ghost CMS runs on NodeJS, you are not required to use an particular directory to install Ghost to. Unlike other server software like Apache. But since I do loads of regular PHP development and have XAMPP installed on my Windows laptop, I am going to have my Ghost blog in my usual htdocs folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fghost%2FWhere-to-install-Ghost-CMS-on-Windows-localhost.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Fghost%2FWhere-to-install-Ghost-CMS-on-Windows-localhost.png" alt="select where you want Ghost to live"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No matter where you want to install Ghost, use your terminal to navigate to that directory (using the cd command). Then create a new folder to actually install and be the home for your Ghost blog (e.g. "&lt;em&gt;ghost-blog&lt;/em&gt;"). And finally navigate into that new folder ("&lt;em&gt;cd ghost-blog&lt;/em&gt;").&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd C:\xampp\htdocs\
mkdir ghost-blog
cd ghost-blog

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install Ghost CMS in Windows with npm
&lt;/h2&gt;

&lt;p&gt;Once inside of your newly created Ghost blog folder, you are ready to install Ghost CMS. It takes two steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install the Ghost CLI (command line interface)&lt;/li&gt;
&lt;li&gt;Then actually installing the Ghost blog website files&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Possible error:&lt;/strong&gt;"ghost.ps1 cannot be loaded because running scripts is disabled on this system."&lt;/p&gt;

&lt;p&gt;If you are getting the "&lt;em&gt;ghost.ps1 cannot be loaded because running scripts is disabled on this system&lt;/em&gt;" error message (or something similar), then you will need to run the two installation commands with the &lt;strong&gt;runas&lt;/strong&gt; command prefix. This will force PowerShell to run the command as the administrator account you specify. Just include and update the command below to run each as an administrator. Like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;runas "/user:usernamehere" "yourcommand_here"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or you can run VS code/terminal as an administrator, then give VS code permission to run commands in terminal as an Admin with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Set-ExecutionPolicy Unrestricted

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install Ghost CLI in Windows
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g ghost-cli@latest

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that single command, your Ghost CLI installation will begin downloading and installing, automatically. With the latest version of course. My install took about 23 seconds. So not to bad.&lt;/p&gt;

&lt;h2&gt;
  
  
  Actually Install Ghost CMS in Windows
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ghost install local

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While installing Ghost CMS, you may get a Windows firewall prompt to allow NodeJS to access the internet (or be accessed by other devices on your local network. You will need to allow at least the "private networks" option to be able to actually view your Ghost blog.&lt;/p&gt;

&lt;p&gt;Once the install is complete, it will automatically start the Ghost server for you.&lt;/p&gt;

&lt;p&gt;How nice of them :)&lt;/p&gt;

&lt;h2&gt;
  
  
  Enjoy your new Ghost blog on windows!
&lt;/h2&gt;

&lt;p&gt;That's it. You are done installing Ghost CMS on Windows. Super easy right? Right! You can browser over to your Ghost blog by navigating to the localhost url that is given in your terminal window. Likely something like &lt;em&gt;&lt;a href="http://localhost:2368/ghost/" rel="noopener noreferrer"&gt;http://localhost:2368/ghost/&lt;/a&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;From this url, you will be able to complete the Ghost CMS setup and customize your Ghost blog. Enjoy all the greatness and speed of Ghost CMS!&lt;/p&gt;

&lt;h2&gt;
  
  
  Finish the Ghost blog setup wizard
&lt;/h2&gt;

&lt;p&gt;With your new Ghost blog created, you can work your way though the quick setup wizard. The quick steps will let you create the your first account and even invite other users to be Ghost CMS managers of your new Ghost blog.&lt;/p&gt;




&lt;p&gt;This article on "&lt;a href="https://frostbutter.com/articles/how-to-install-ghost-cms-on-windows-localhost" rel="noopener noreferrer"&gt;how to install ghost CMS on Windows&lt;/a&gt;" was originally published to my site, &lt;a href="https://frostbutter.com" rel="noopener noreferrer"&gt;frostbutter.com&lt;/a&gt;, where you can find more useful dev articles.&lt;/p&gt;

</description>
      <category>ghost</category>
      <category>node</category>
      <category>windows</category>
      <category>localhost</category>
    </item>
    <item>
      <title>Fix "PHP executable not found" error in VS Code</title>
      <dc:creator>Nick Frostbutter</dc:creator>
      <pubDate>Mon, 20 Dec 2021 15:54:42 +0000</pubDate>
      <link>https://dev.to/nickfrosty/fix-php-executable-not-found-error-in-vs-code-3nej</link>
      <guid>https://dev.to/nickfrosty/fix-php-executable-not-found-error-in-vs-code-3nej</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D3aWLfdq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/vs-code/fix-php-executable-not-found/Fix-PHP-executable-not-found-error-in-Visual-Studio-Code-VS-Code.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D3aWLfdq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/vs-code/fix-php-executable-not-found/Fix-PHP-executable-not-found-error-in-Visual-Studio-Code-VS-Code.png" alt='Fix "PHP executable not found" error in VS Code' width="880" height="495"&gt;&lt;/a&gt;&lt;br&gt;
Nobody likes errors, least of all computer programmers!&lt;/p&gt;

&lt;p&gt;If you are a PHP developer and recently installed Visual Studio Code (VS Code), then you are most likely getting a pesky "&lt;a href="https://frostbutter.com/articles/fix-php-executable-not-found-error-in-vs-code"&gt;PHP executable not found&lt;/a&gt;" error message every time you start the program.&lt;/p&gt;

&lt;p&gt;Some of the other VS Code error message you will see with the PHP executable not found message includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install PHP 7 and add to your PATH"&lt;/li&gt;
&lt;li&gt;"set php.executablePath setting"&lt;/li&gt;
&lt;li&gt;"Cannot validate since no PHP executable is set"&lt;/li&gt;
&lt;li&gt;"Use the php.validate.executablePath to configure the PHP executable"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With every single one of these VS Code error messages, you simply need to update your Windows &lt;strong&gt;PATH&lt;/strong&gt; setting for your PHP executable location. Doing that will fix all of these PHP executable errors!&lt;/p&gt;

&lt;h2&gt;
  
  
  How to fix PHP executable not found error in VS Code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Install php on your computer (e.g. with XAMPP)&lt;/li&gt;
&lt;li&gt;Locate your php installation directory&lt;/li&gt;
&lt;li&gt;Open Advanced System Settings on Windows&lt;/li&gt;
&lt;li&gt;Update the Windows "PATH" environment variable&lt;/li&gt;
&lt;li&gt;Close VS Code and reopen it&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Install php on your computer (e.g. with XAMPP)
&lt;/h2&gt;

&lt;p&gt;The first and very most important step to fix the PHP executable not found error on Visual Studio Code is to actually have PHP installed on your computer. Now that might seem like an obvious starting point, but you would be surprised how many people don't have PHP installed on their local web dev environment (e.g. their localhost server).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bZAVv84y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/vs-code/fix-php-executable-not-found/Install-XAMPP-on-localhost-to-fix-PHP-executable-not-found.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bZAVv84y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/vs-code/fix-php-executable-not-found/Install-XAMPP-on-localhost-to-fix-PHP-executable-not-found.png" alt="install XAMPP on windows to install php" width="880" height="751"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Personally, I have always been a fan of the XAMPP suite by &lt;a href="https://apachefriends.org/"&gt;ApacheFriends.org&lt;/a&gt;. I have been using the XAMPP suite to install PHP, MySQL, and phpMyAdmin for my localhost web servers for &lt;strong&gt;years&lt;/strong&gt;. I highly recommend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Locate your php installation directory
&lt;/h2&gt;

&lt;p&gt;Once you have PHP installed on your local computer (as part of your localhost server), you need to find the PHP installation directory. As we need the folder path that holds your &lt;strong&gt;php.exe&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uloFHw1r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/vs-code/fix-php-executable-not-found/fix-php-executable-not-found-VS-code-2-find-your-php-installation-directory.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uloFHw1r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/vs-code/fix-php-executable-not-found/fix-php-executable-not-found-VS-code-2-find-your-php-installation-directory.png" alt="locate your php executable file" width="880" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you installed XAMPP, simply browse to your XAMPP installation directory. The default location is at C:\xampp. From inside the XAMPP folder, open the PHP folder and locate the php.exe file. If you can find the php.exe file from in this folder, then this folder will be your php installation directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Open Advanced System Settings on Windows
&lt;/h2&gt;

&lt;p&gt;Now that we know your php installation directory, we need to open the actually add the folder path into the Windows' PATH. But to get there, you have to open a few different screens.&lt;/p&gt;

&lt;p&gt;From the your file explorer or desktop, right click on "This PC". Then select "Properties" from the drop down. Doing this will open the Windows control panel menu for your system settings.&lt;/p&gt;

&lt;p&gt;From the system settings menu, you will see all of your computer's basic information like RAM, CPU size, and your computer name.&lt;/p&gt;

&lt;p&gt;On the left hand side of the program, you will see an option to open "Advanced System Settings". Go ahead and open the Windows advanced system settings program.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D30hhtn9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/vs-code/fix-php-executable-not-found/fix-php-executable-not-found-VS-code-4-open-advanced-system-properties.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D30hhtn9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/vs-code/fix-php-executable-not-found/fix-php-executable-not-found-VS-code-4-open-advanced-system-properties.png" alt="open the advanced system settings in Windows control panel" width="880" height="759"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Please note:&lt;/strong&gt; this WILL require you to have administrative permissions on your Windows computer. If you do not, then you will have to contact the person that does in order to update the Windows PATH variable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Update the Windows "PATH" environment variable
&lt;/h2&gt;

&lt;p&gt;Once you have successfully found and opened the Windows advanced system settings popup, you can edit your Windows environment variables. While selected to the Advanced tab in the popup, click on the "Environment variables..." button at the bottom. This will open another program.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8GiSszjM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/vs-code/fix-php-executable-not-found/fix-php-executable-not-found-VS-code-5-add-a-new-windows-environment-variable-for-path.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8GiSszjM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://frostbutter.com/media/articles/vs-code/fix-php-executable-not-found/fix-php-executable-not-found-VS-code-5-add-a-new-windows-environment-variable-for-path.png" alt="update your path variable to save the location of the php executable" width="880" height="771"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here you can update all of your Windows environment variables. But in order to fix the PHP executable not found error message in VS Code, we really only care about the PATH variable.&lt;/p&gt;

&lt;p&gt;So, from the list of User variables, select the "Path" option. Then click the Edit button. This will open the variable editor window.&lt;/p&gt;

&lt;p&gt;Inside of the variable editor window, you can create a new PATH variable quite easily. Simply click the "New" button on the right hand side. Then enter in your PHP installation directory that we got from the step above.&lt;/p&gt;

&lt;p&gt;Be sure to click away from the new path you created to ensure the updated PHP path is correctly saved into Windows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Close VS Code and reopen it
&lt;/h2&gt;

&lt;p&gt;When you have successfully saved your PHP path location into the Windows PATH variable, you can close out of all of the Windows control panel windows.&lt;/p&gt;

&lt;p&gt;You can now close VS code and reopen it. And you will notice that you have gotten rid of the the "PHP executable not found" error message that you get on VS code start up. Great success!&lt;/p&gt;




&lt;p&gt;This article on how to &lt;a href="https://frostbutter.com/articles/fix-php-executable-not-found-error-in-vs-code"&gt;fix "PHP executable not found" error in VS Code&lt;/a&gt; was originally published to my site, &lt;a href="https://frostbutter.com"&gt;frostbutter.com&lt;/a&gt;, where you can find more useful dev articles.&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>php</category>
      <category>windows</category>
      <category>errors</category>
    </item>
    <item>
      <title>Use Laravel Mix without Laravel (using npm)</title>
      <dc:creator>Nick Frostbutter</dc:creator>
      <pubDate>Sat, 11 Dec 2021 11:43:33 +0000</pubDate>
      <link>https://dev.to/nickfrosty/use-laravel-mix-without-laravel-using-npm-m09</link>
      <guid>https://dev.to/nickfrosty/use-laravel-mix-without-laravel-using-npm-m09</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Flaravel%2Flaravel-mix-without-laravel-with-npm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffrostbutter.com%2Fmedia%2Farticles%2Flaravel%2Flaravel-mix-without-laravel-with-npm.jpg" alt="Use Laravel Mix without Laravel (using npm)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Laravel Mix is a great tool to smooth out your development process. But I don't use Laravel. But you can still get the magic sauce of Laravel Mix without Laravel, using npm&lt;/p&gt;

&lt;p&gt;After hours of trial and error, here is how to actually setup and use Laravel mix &lt;strong&gt;WITHOUT&lt;/strong&gt; actually using the Laravel framework. Using npm.&lt;/p&gt;

&lt;p&gt;Literally hours of struggle and errors. Hours trying to figure out how to setup Laravel mix for a Tailwind project,  finally got a working result. Here is the most straightforward way to setup Laravel Mix using NPM. As well how to properly configure your webpack config file.&lt;/p&gt;

&lt;p&gt;Side note: Even though I love what &lt;a href="https://twitter.com/taylorotwell" rel="noopener noreferrer"&gt;Taylor Otwell&lt;/a&gt;, and the great peeps over at Laravel do, I still don't use the &lt;a href="https://laravel.com" rel="noopener noreferrer"&gt;Laravel framework&lt;/a&gt; in any of my PHP based web apps. It seems like a sin since it is such a popular framework. But that's cool. I just like vanilla PHP.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install NodeJS and NPM
&lt;/h2&gt;

&lt;p&gt;For starters, you will need to have node JS and npm installed on your system, whether you are running Windows (like me), Linux (sometimes like me), or Mac (never like me). Laravel Mix relies on npm.&lt;/p&gt;

&lt;p&gt;You can find the official installer on the &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;NodeJS website here&lt;/a&gt;. It's a very straightforward installer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create your package.json
&lt;/h2&gt;

&lt;p&gt;Browse on over to your terminal window, and navigate to the directory you want to setup Laravel mix. You need to create your &lt;strong&gt;package.json&lt;/strong&gt; file. Either with this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or by using the sample &lt;strong&gt;package.json&lt;/strong&gt; file below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add these "devDependencies" to package.json
&lt;/h2&gt;

&lt;p&gt;Since we want to use Laravel Mix with NPM, we need to actually set it to be a dependency to use it in the project. But since I do not want it to load on my production site, I add as a dev dependency.&lt;/p&gt;

&lt;p&gt;Mix needs a few other packages to be loaded as well. Listed below are the required &lt;strong&gt;devDependencies&lt;/strong&gt; you should add (tailwind and browser sync are optional):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"devDependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"cross-env"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^5.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"laravel-mix"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^2.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"laravel-mix-purgecss"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^2.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"laravel-mix-tailwind"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^0.1.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"tailwindcss"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^1.2.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"browser-sync"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"latest"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"browser-sync-webpack-plugin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^2.0.1"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt; In order to get the most out of using Laravel Mix, I also use BrowserSync. And you should to! It will help you auto refresh your project while working on front end code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add the Mix "scripts" to package.json
&lt;/h2&gt;

&lt;p&gt;The big reason to use Laravel Mix is really to use these sweet npm scripts. Each of these scripts (aka commands) have their specific uses, but you should add all of them for your current and/or future use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm run development"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"development"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"watch"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm run development -- --watch"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"watch-poll"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm run watch -- --watch-poll"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"hot"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"prod"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm run production"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"production"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are new to Laravel Mix and never used these scripts before, here is a brief description of what they do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"development": compiles your CSS and JS into their final public resting place for your project. But in "dev" mode, the files are not minified. Making the build time much faster for your dev work (aka frequent changes)&lt;/li&gt;
&lt;li&gt;"&lt;strong&gt;dev&lt;/strong&gt;": just short hand for "&lt;em&gt;development&lt;/em&gt;"&lt;/li&gt;
&lt;li&gt;"&lt;strong&gt;watch&lt;/strong&gt;": the same as dev, but you will get auto reload and rebuilds on your project (if you have browser sync setup)&lt;/li&gt;
&lt;li&gt;"&lt;strong&gt;production&lt;/strong&gt;": compiles your CSS and JS into their final public resting place for your project &lt;strong&gt;WITH&lt;/strong&gt; minification&lt;/li&gt;
&lt;li&gt;"&lt;strong&gt;prod&lt;/strong&gt;": just short hand for "&lt;em&gt;production&lt;/em&gt;"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And when you want to run each of these commands, you run them in the terminal using npm like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run dev
npm run watch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install Laravel Mix with NPM
&lt;/h2&gt;

&lt;p&gt;With your &lt;strong&gt;package.json&lt;/strong&gt; file configured, we want to actually run the npm installer to download the correct versions for each of the packages we need for the project:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;The download may take some time, but that is totally fine. Mine took about 8 minutes. Wowza!&lt;/p&gt;

&lt;p&gt;Once your installation command is complete, you should see a new folder created named "&lt;strong&gt;node_modules&lt;/strong&gt;". This is good! If you do not see the folder (and it full of files and folders) then something went wrong. Maybe try again?&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure your webpack.mix.js file
&lt;/h2&gt;

&lt;p&gt;Now is the time to configure your webpack script. It is &lt;strong&gt;SUPER&lt;/strong&gt; important to get this script right, because if you do not then you will for sure get errors (I know from experience).&lt;/p&gt;

&lt;p&gt;For the most part, this webpack.config.js file is pretty standard. We tell the processor to use the "laravel-mix" package as well as load up tailwind and purgeCSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  But, you MUST update this file to your project!
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;laravel-mix&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;laravel-mix-tailwind&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;laravel-mix-purgecss&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="cm"&gt;/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel applications. By default, we are compiling the CSS
| file for the application as well as bundling up all the JS files.
|
*/&lt;/span&gt;
&lt;span class="nx"&gt;mix&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setPublicPath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;update_to_your_source_folder&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="nx"&gt;mix&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;js&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;location/of/your/site.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;where/to/save/your/js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postCss&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;location/of/your/tailwind.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;where/to/save/your/css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tailwindcss&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mix&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;inProduction&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;mix&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;version&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This config file tells webpack where to look for your CSS and JS files to actually process them for your web app. Be sure to update the following info for your:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;update_to_your_source_folder&lt;/strong&gt;: this location if the folder of your public site (relative to the location of your webpack.config.js file) (e.g. "&lt;em&gt;public&lt;/em&gt;")&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;location/of/your/site.js&lt;/strong&gt;: the relative location of your sites primary javascript file (where you can load the other javascript files as well) (e.g. "&lt;em&gt;resources/js/site.js&lt;/em&gt;")&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;where/to/save/your/js&lt;/strong&gt;: the relative location to save the new compiled JS file. this should most likely be somewhere inside of your public folder (e.g. "&lt;em&gt;public/assets&lt;/em&gt;")&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;location/of/your/tailwind.css&lt;/strong&gt;: the relative location of your sites primary CSS file (where you can load the other CSS libraries as well like tailwind) (e.g. "&lt;em&gt;resources/js/tailwind.css&lt;/em&gt;")&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;where/to/save/your/css&lt;/strong&gt;: the relative location to save the new compiled CSS file. this should most likely be somewhere inside of your public folder (e.g. "&lt;em&gt;public/assets&lt;/em&gt;")&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Enable BrowserSync via webpack? You should!
&lt;/h2&gt;

&lt;p&gt;If you have made the productive decision to use browser sync, then good for you. It is a super straight forward process. You can add these lines of code directly into your &lt;strong&gt;webpack.config.js&lt;/strong&gt; file (I like to put mine just above the "&lt;em&gt;mix.setPublicPath&lt;/em&gt;" code):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;proxy_url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;APP_URL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;mix&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;browserSync&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;proxy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;proxy_url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;ghostMode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;auto&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1rem&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;files&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./resources/**/*.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./resources/**/*.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./public/*&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Before you move on: update the files to auto detect!
&lt;/h3&gt;

&lt;p&gt;You must update the array of "files" listed in the config. These wildcard enabled locations are all the possible locations and types of files that, when their source code is updated, browser sync will make its magic happen. Making the browser auto reload for your.&lt;/p&gt;

&lt;p&gt;You will also need to make sure the "proxy_url" variable is correctly set to your site's local testing address. If you are using a tool like Laravel's Valet, then your "proxy_url" might be "project.test". (And yes, I also use Valet from Laravel too. Again, without using the actual Laravel framework...)&lt;/p&gt;

&lt;p&gt;Now, with browser sync enabled with Laravel Mix you will be able to use the "npm run watch" command to get the most out of your dev environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure the tailwind.config.js file
&lt;/h2&gt;

&lt;p&gt;Since for this article, and my future projects, I am setting up this project using Mix AND tailwind, we need to actually configure tailwind. I run the following command to create the scaffolding of the tailwind.config.js file for me:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm tailwind init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will auto-create the default (and pretty empty) tailwind.config.js file. Looking pretty darn near close to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// tailwind.config.js&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;purge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
    &lt;span class="na"&gt;darkMode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// or 'media' or 'class'&lt;/span&gt;
    &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;variants&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This barebones structure is great, but you still most update the "purge" attribute. This is an array of all the locations of your source code files that use the tailwind library. &lt;/p&gt;

&lt;p&gt;To make purgeCSS to load all the html files in your public folder, use something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;purge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./public/*.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Listing out each of the folders and file type here will allow purgeCSS to auto search your source code to smartly find all the used tailwind CSS. In turn, smartly removing the unused CSS making your compiled CSS way small!&lt;/p&gt;

&lt;h2&gt;
  
  
  Create your CSS and HTML files
&lt;/h2&gt;

&lt;p&gt;To make use the basic tailwind components and utilities, add this to your &lt;strong&gt;tailwind.css&lt;/strong&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tailwindcss/base&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tailwindcss/components&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tailwindcss/utilities&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Let's test out Laravel Mix!
&lt;/h2&gt;

&lt;p&gt;You should be ready to go and test out Laravel Mix.&lt;/p&gt;

&lt;p&gt;In your terminal, go run the "&lt;strong&gt;dev&lt;/strong&gt;" command to make sure you get no errors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see some action in your terminal, showing you how far along webpack is at parsing and building out your compiled CSS and JS files. If all goes well, you should get a colored output stating the final file size of the compiled scripts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't forget:&lt;/strong&gt; when you are ready to move your project up to a production server, you need to run the "&lt;strong&gt;prod&lt;/strong&gt;" command to actually build and minify your scripts. Or else, what was the point of all of this effort?! &lt;/p&gt;

&lt;h2&gt;
  
  
  Enjoy!
&lt;/h2&gt;

&lt;p&gt;With these steps all completed, your fresh Laravel Mix install is complete. And looky there, no Laravel framework was used!&lt;/p&gt;




&lt;p&gt;This article on using &lt;a href="https://frostbutter.com/articles/use-laravel-mix-without-laravel-using-npm" rel="noopener noreferrer"&gt;Laravel mix with Laravel&lt;/a&gt; was originally published to my site, &lt;a href="https://frostbutter.com" rel="noopener noreferrer"&gt;frostbutter.com&lt;/a&gt;, where you can find more useful dev articles.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>npm</category>
      <category>tailwindcss</category>
      <category>php</category>
    </item>
  </channel>
</rss>
