title: Vagrant and Postgres on Mac M1 Monterey - psql: error: connection to server on socket
body: <p>I am moving from an Intel Mac to one running M1. I am trying to get Vagrant running using Laravel Homestead and Parallels.</p>
  <p>When I run</p>
  <pre><code>vagrant up
  </code></pre>
  <p>everything runs as expected until it tries to provision PostgreSQL. At that point, I run into the error:</p>
  <blockquote>
  <p>==&gt; machine2018: Running provisioner: Creating Postgres Database: socket_wrench (shell)...</p>
  </blockquote>
  <blockquote>
  <p>machine2018: Running: script: Creating Postgres Database: socket_wrench</p>
  </blockquote>
  <blockquote>
  <p>machine2018: createdb: error: could not connect to database template1: connection to server on socket &quot;/var/run/postgresql/.s.PGSQL.5432&quot; failed: No such file or directory
  machine2018:       Is the server running locally and accepting connections on that socket?</p>
  </blockquote>
  <blockquote>
  <p>The SSH command responded with a non-zero exit status. Vagrant
  assumes that this means the command failed. The output for this command
  should be in the log above. Please read the output to determine what
  went wrong.</p>
  </blockquote>
  <p>Despite ensuring Postgres is running locally on my Mac AND running out of /var/run/postgresql (instead of the default /tmp), I still get this message. And the same is true when I vagrant ssh into my box.</p>
  <pre><code>pg_ctl -D /usr/local/var/postgres restart
  waiting for server to shut down.... done
  server stopped
  waiting for server to start....2022-03-22 12:27:18.024 EDT [16259] LOG:  starting PostgreSQL 14.2 on aarch64-apple-darwin21.3.0, compiled by Apple clang version 13.0.0 (clang-1300.0.29.30), 64-bit
  2022-03-22 12:27:18.025 EDT [16259] LOG:  listening on IPv6 address &quot;::1&quot;, port 5432
  2022-03-22 12:27:18.025 EDT [16259] LOG:  listening on IPv4 address &quot;127.0.0.1&quot;, port 5432
  2022-03-22 12:27:18.025 EDT [16259] LOG:  listening on Unix socket &quot;/var/run/postgresql/.s.PGSQL.5432&quot;
  2022-03-22 12:27:18.030 EDT [16260] LOG:  database system was shut down at 2022-03-22 12:27:17 EDT
  2022-03-22 12:27:18.037 EDT [16259] LOG:  database system is ready to accept connections
  </code></pre>
  <p>Here is my Vagrantfile</p>
  <pre><code># -*- mode: ruby -*-
  # vi: set ft=ruby :
  
  require 'json'
  require 'yaml'
  
  Vagrant.require_version '&gt;= 2.2.4'
  
  VAGRANTFILE_API_VERSION ||= &quot;2&quot;
  confDir = $confDir ||= File.expand_path(&quot;vendor/laravel/homestead&quot;, File.dirname(__FILE__))
  
  homesteadYamlPath = File.expand_path(&quot;Homestead.yaml&quot;, File.dirname(__FILE__))
  homesteadJsonPath = File.expand_path(&quot;Homestead.json&quot;, File.dirname(__FILE__))
  afterScriptPath = &quot;after.sh&quot;
  aliasesPath = &quot;aliases&quot;
  
  require File.expand_path(confDir + '/scripts/homestead.rb')
  
  Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
      if File.exist? aliasesPath then
          config.vm.provision &quot;file&quot;, source: aliasesPath, destination: &quot;/tmp/bash_aliases&quot;
          config.vm.provision &quot;handle_aliases&quot;, type: &quot;shell&quot; do |s|
              s.inline = &quot;awk '{ sub(\&quot;\r$\&quot;, \&quot;\&quot;); print }' /tmp/bash_aliases &gt; /home/vagrant/.bash_aliases &amp;&amp; chown vagrant:vagrant /home/vagrant/.bash_aliases&quot;
          end
      end
  
      if File.exist? homesteadYamlPath then
          settings = YAML::load(File.read(homesteadYamlPath))
      elsif File.exist? homesteadJsonPath then
          settings = JSON::parse(File.read(homesteadJsonPath))
      else
          abort &quot;Homestead settings file not found in #{confDir}&quot;
      end
  
      Homestead.configure(config, settings)
  
      if File.exist? afterScriptPath then
          config.vm.provision &quot;Run after.sh&quot;, type: &quot;shell&quot;, path: afterScriptPath, privileged: false, keep_color: true
      end
  
  #     if File.exist? customizationScriptPath then
  #         config.vm.provision &quot;Run customize script&quot;, type: &quot;shell&quot;, path: customizationScriptPath, privileged: false, keep_color: true
  #     end
  
      if Vagrant.has_plugin?('vagrant-hostsupdater')
          config.hostsupdater.remove_on_suspend = false
          config.hostsupdater.aliases = settpo.ings['sites'].map { |site| site['map'] }
      elsif Vagrant.has_plugin?('vagrant-hostmanager')
          config.hostmanager.enabled = true
          config.hostmanager.manage_host = true
          config.hostmanager.aliases = settings['sites'].map { |site| site['map'] }
      elsif Vagrant.has_plugin?('vagrant-goodhosts')
          config.goodhosts.aliases = settings['sites'].map { |site| site['map'] }
      end
  
      if Vagrant.has_plugin?('vagrant-notify-forwarder')
          config.notify_forwarder.enable = true
      end
  end
  </code></pre>