laravel / homestead

MIT License
3.86k stars 1.45k forks source link

Per-project install, serve-laravel fails due to missing /vagrant/scripts #1439

Closed Braunson closed 4 years ago

Braunson commented 4 years ago

Versions

Host operating system

Windows 10 Home

Expected behavior

Should run the serve script

Actual behavior

Trying to run serve-laravel that's defined in aliases but /vagrant/scripts doesn't seem to exist and thus the command throws errors

bash: /vagrant/scripts/create-certificate.sh: No such file or directory
dos2unix: /vagrant/scripts/site-types/laravel.sh: No such file or directory
dos2unix: Skipping /vagrant/scripts/site-types/laravel.sh, not a regular file.
bash: /vagrant/scripts/site-types/laravel.sh: No such file or directory

I think this may be related to #574 but not sure of a workaround.. I'm trying to use serve-laravel function to register another site (i.e. phpMyAdmin) -- Any ideas of a workaround without duplicating the code from /vagrant/scripts/{create-certificate,site-types/laravel} into my after.sh script (where this is all called from)?

Steps to reproduce

  1. Copy down Homestead.yaml
  2. Run vagrant up
  3. Watch up logs.
Braunson commented 4 years ago

I just noticed homestead/resources/localized/aliases 🤦‍♂️

Braunson commented 4 years ago

Having issues with this still, running the script in after.sh and it's still saying serve-laravel: command not found. Any ideas?

svpernova09 commented 4 years ago

post your Homestead.yaml Are you manually mapping . (current folder)?

Braunson commented 4 years ago

Homestead.yaml

ip: 192.168.12.120
memory: 2048
cpus: 2
provider: virtualbox
name: project-homestead
hostname: project-homestead

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: '~/Documents/GitHub/project'
      to: /home/vagrant/project

sites:
    - map: project.local
      to: /home/vagrant/project/public
      schedule: true

databases:
    - homestead
    - project

features:
    - mariadb: true
    - ohmyzsh: true
    - webdriver: true
svpernova09 commented 4 years ago

Windows users should not use the ~/ path syntax and instead should use the full path to their project, such as C:\Users\user\Code\project1.

https://laravel.com/docs/7.x/homestead#configuring-homestead

Give that a spin and report back.

svpernova09 commented 4 years ago

If you're still having issues after that, set your 3 features to false, then do a vagrant destroy && vagrant up and post the log.

Braunson commented 4 years ago

@svpernova09 I just changed to ~/ as I was using the Windows typical path before, but did change it back and tried again with the same error. After the box is up, I can confirm /vagrant/vendor/.../etc is there and exists, bot for some reason the command in my after.sh returns serve-laravel: command not found.

Ouput from vagrant destroy && vagrant up with path fixed and all features removed.

PS C:\Users\Braunson\Documents\GitHub\project> vagrant destroy -f
==> project-homestead: Forcing shutdown of VM...
==> project-homestead: Destroying VM and associated drives...
==> project-homestead: [vagrant-hostsupdater] Removing hosts
PS C:\Users\Braunson\Documents\GitHub\project> vagrant up
Bringing machine 'project-homestead' up with 'virtualbox' provider...
==> project-homestead: Importing base box 'laravel/homestead'...
==> project-homestead: Matching MAC address for NAT networking...
==> project-homestead: Checking if box 'laravel/homestead' version '10.0.0-beta' is up to date...
==> project-homestead: Setting the name of the VM: project-homestead
==> project-homestead: Clearing any previously set network interfaces...
==> project-homestead: Preparing network interfaces based on configuration...
    project-homestead: Adapter 1: nat
    project-homestead: Adapter 2: hostonly
==> project-homestead: Forwarding ports...
    project-homestead: 80 (guest) => 8000 (host) (adapter 1)
    project-homestead: 443 (guest) => 44300 (host) (adapter 1)
    project-homestead: 3306 (guest) => 33060 (host) (adapter 1)
    project-homestead: 4040 (guest) => 4040 (host) (adapter 1)
    project-homestead: 5432 (guest) => 54320 (host) (adapter 1)
    project-homestead: 8025 (guest) => 8025 (host) (adapter 1)
    project-homestead: 9600 (guest) => 9600 (host) (adapter 1)
    project-homestead: 27017 (guest) => 27017 (host) (adapter 1)
    project-homestead: 22 (guest) => 2222 (host) (adapter 1)
==> project-homestead: Running 'pre-boot' VM customizations...
==> project-homestead: Booting VM...
==> project-homestead: Waiting for machine to boot. This may take a few minutes...
    project-homestead: SSH address: 127.0.0.1:2222
    project-homestead: SSH username: vagrant
    project-homestead: SSH auth method: private key
    project-homestead: Warning: Connection aborted. Retrying...
    project-homestead: Warning: Connection reset. Retrying...
    project-homestead: Warning: Remote connection disconnect. Retrying...
    project-homestead:
    project-homestead: Vagrant insecure key detected. Vagrant will automatically replace
    project-homestead: this with a newly generated keypair for better security.
    project-homestead:
    project-homestead: Inserting generated public key within guest...
    project-homestead: Removing insecure key from the guest if it's present...
    project-homestead: Key inserted! Disconnecting and reconnecting using new SSH key...
==> project-homestead: Machine booted and ready!
==> project-homestead: Checking for guest additions in VM...
==> project-homestead: [vagrant-hostsupdater] Checking for host entries
==> project-homestead: [vagrant-hostsupdater] Writing the following entries to (C:/WINDOWS/system32/drivers/etc/hosts)
==> project-homestead: [vagrant-hostsupdater]   192.168.12.120  project-homestead  # VAGRANT: ce6e1dfbe7675e7dfeceddff148094a0 (project-homestead) / f2ec3edb-cb5f-4de5-be8e-d386804ba945
==> project-homestead: [vagrant-hostsupdater]   192.168.12.120  project.local  # VAGRANT: ce6e1dfbe7675e7dfeceddff148094a0 (project-homestead) / f2ec3edb-cb5f-4de5-be8e-d386804ba945
==> project-homestead: [vagrant-hostsupdater] This operation requires administrative access. You may skip it by manually adding equivalent entries to the hosts file.
==> project-homestead: Setting hostname...
==> project-homestead: Configuring and enabling network interfaces...
==> project-homestead: Mounting shared folders...
    project-homestead: /vagrant => C:/Users/Braunson/Documents/GitHub/project
    project-homestead: /home/vagrant/project => C:/Users/Braunson/Documents/GitHub/project
==> project-homestead: Running provisioner: file...
    project-homestead: C:/Users/Braunson/Documents/GitHub/project/.homestead/aliases => /tmp/bash_aliases
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: inline script
    project-homestead:
    project-homestead: ssh-rsa --removed-for-length--
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: inline script
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: inline script
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: inline script
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: inline script
    project-homestead: Ignoring feature: webdriver because it is set to false
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: C:/Users/GEEKYB~1/AppData/Local/Temp/vagrant-shell20200624-21540-1x1jr5q.sh
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: C:/Users/GEEKYB~1/AppData/Local/Temp/vagrant-shell20200624-21540-1odx520.sh
==> project-homestead: Running provisioner: Creating Certificate: project.local (shell)...
    project-homestead: Running: script: Creating Certificate: project.local
    project-homestead: Updating certificates in /etc/ssl/certs...
    project-homestead: 1 added, 0 removed; done.
    project-homestead: Running hooks in /etc/ca-certificates/update.d...
    project-homestead: done.
==> project-homestead: Running provisioner: Creating Site: project.local (shell)...
    project-homestead: Running: script: Creating Site: project.local
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: inline script
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: C:/Users/GEEKYB~1/AppData/Local/Temp/vagrant-shell20200624-21540-1siypgg.sh
==> project-homestead: Running provisioner: Creating Schedule (shell)...
    project-homestead: Running: script: Creating Schedule
==> project-homestead: Running provisioner: Clear Variables (shell)...
    project-homestead: Running: script: Clear Variables
==> project-homestead: Running provisioner: Restarting Cron (shell)...
    project-homestead: Running: script: Restarting Cron
==> project-homestead: Running provisioner: Restart Webserver (shell)...
    project-homestead: Running: script: Restart Webserver
==> project-homestead: Running provisioner: Creating MySQL Database: homestead (shell)...
    project-homestead: Running: script: Creating MySQL Database: homestead
==> project-homestead: Running provisioner: Creating Postgres Database: homestead (shell)...
    project-homestead: Running: script: Creating Postgres Database: homestead
==> project-homestead: Running provisioner: Creating MySQL Database: project (shell)...
    project-homestead: Running: script: Creating MySQL Database: project
==> project-homestead: Running provisioner: Creating Postgres Database: project (shell)...
    project-homestead: Running: script: Creating Postgres Database: project
==> project-homestead: Running provisioner: Update Composer (shell)...
    project-homestead: Running: script: Update Composer
    project-homestead: You are already using composer version 1.10.7 (stable channel).
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: C:/Users/GEEKYB~1/AppData/Local/Temp/vagrant-shell20200624-21540-13qkubi.sh
==> project-homestead: Running provisioner: Update motd (shell)...
    project-homestead: Running: script: Update motd
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: C:/Users/GEEKYB~1/AppData/Local/Temp/vagrant-shell20200624-21540-1ejs93n.sh

    -- After.sh gets run from here on out.. --

    project-homestead: installing some extra software
    project-homestead: installing PHPMyAdmin
    project-homestead: Downloading phpMyAdmin RELEASE_5_0_2
    project-homestead: Serving the domain: pma.project.local
    project-homestead: bash: line 16: serve-laravel: command not found
    project-homestead: Installing dependencies for phpMyAdmin on pma.project.local
    project-homestead: yarn install v1.22.4
    project-homestead: [1/4] Resolving packages...
    project-homestead: [2/4] Fetching packages...
    project-homestead: info fsevents@2.0.7: The platform "linux" is incompatible with this module.
    project-homestead: info "fsevents@2.0.7" is an optional dependency and failed compatibility check. Excluding it from installation.
    project-homestead: [3/4] Linking dependencies...
    project-homestead: [4/4] Building fresh packages...
    project-homestead: $ yarn run --silent css-compile --quiet --style=compressed
    project-homestead: Done in 16.66s.

after.sh

#!/bin/sh

# If you would like to do some extra provisioning you may
# add any commands you wish to this file and they will
# be run after the Homestead machine is provisioned.

if [ ! -f /usr/local/extra_homestead_software_installed ]; then
    echo 'installing some extra software'

    # Install PHPMyAdmin
    echo 'installing PHPMyAdmin'
    curl -sS https://gist.githubusercontent.com/Braunson/f7205b83bef1acfb2fe833fdefd30271/raw/phpmyadmin.sh | bash -s pma.project.local

    # Install some global tools we need
    composer global require friendsofphp/php-cs-fixer "squizlabs/php_codesniffer=*" phpunit/phpunit phploc/phploc pdepend/pdepend phpmd/phpmd hirak/prestissimo infection/infection sarfraznawaz2005/composer-cost --quiet --no-interaction

    # Adjust CLI PHP Configuration
    for i in /etc/php/7.4/cli/php.ini;
    do
        sudo sed -i 's|memory_limit = 512M|memory_limit  = -1|' $i
    done

    # touch /usr/local/extra_homestead_software_installed
else
    echo "extra software already installed... moving on..."
fi

Vagrantfile

Note the only change is moving where the aliases and after.sh files are stored, into a .homestead directory in the project to keep things clean. Also adding SharedFoldersEnableSymlinksCreate at the bottom.

# -*- mode: ruby -*-
# vi: set ft=ruby :

require 'json'
require 'yaml'

VAGRANTFILE_API_VERSION ||= "2"
confDir = $confDir ||= File.expand_path("vendor/laravel/homestead", File.dirname(__FILE__))
hsDir   = $hsDir   ||= File.expand_path(File.join(File.dirname(__FILE__), ".homestead"))

homesteadYamlPath = File.expand_path("Homestead.yaml", File.dirname(__FILE__))
homesteadJsonPath = File.expand_path("Homestead.json", File.dirname(__FILE__))
afterScriptPath = hsDir + "/after.sh"
customizationScriptPath = hsDir + "/user-customizations.sh"
aliasesPath = hsDir + "/aliases"

require File.expand_path(confDir + '/scripts/homestead.rb')

Vagrant.require_version '>= 2.2.4'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    if File.exist? aliasesPath then
        config.vm.provision "file", source: aliasesPath, destination: "/tmp/bash_aliases"
        config.vm.provision "shell" do |s|
            s.inline = "awk '{ sub(\"\r$\", \"\"); print }' /tmp/bash_aliases > /home/vagrant/.bash_aliases"
        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 "Homestead settings file not found in " + File.dirname(__FILE__)
    end

    Homestead.configure(config, settings)

    if File.exist? afterScriptPath then
        config.vm.provision "shell", path: afterScriptPath, privileged: false, keep_color: true
    end

    if File.exist? customizationScriptPath then
        config.vm.provision "shell", path: customizationScriptPath, privileged: false, keep_color: true
    end

    if Vagrant.has_plugin?('vagrant-hostsupdater')
        config.hostsupdater.aliases = settings['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'] }
    end

    config.vm.provider "virtualbox" do |v|
        v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
    end
end
svpernova09 commented 4 years ago

Revert any modifications to Vagrantfile, then run vagrant destroy && vagrant up and then show me the output of ls -alh /vagrant && df -h

svpernova09 commented 4 years ago

Also: Show me what's in your aliases file in the root of your repo. It could be out of date , if so, delete it and run the make command again.

Braunson commented 4 years ago

@svpernova09 Done, I renamed the Vagrantfile (to keep the old but allow for the new via make), republished Vagrantfile, aliases, after.sh. Added my few custom lines to the after.sh file.

Had the same serve-laravel not found error.

vagrant destroy && make && vagrant up output

PS C:\Users\Braunson\Documents\GitHub\project> vagrant destroy -f
==> project-homestead: Forcing shutdown of VM...
==> project-homestead: Destroying VM and associated drives...
==> project-homestead: [vagrant-hostsupdater] Removing hosts
PS C:\Users\Braunson\Documents\GitHub\project> vendor\\bin\\homestead make
Homestead Installed!
PS C:\Users\Braunson\Documents\GitHub\project> VAGRANT UP^C
PS C:\Users\Braunson\Documents\GitHub\project> ^C
PS C:\Users\Braunson\Documents\GitHub\project> vagrant up
Bringing machine 'project-homestead' up with 'virtualbox' provider...
==> project-homestead: Importing base box 'laravel/homestead'...
==> project-homestead: Matching MAC address for NAT networking...
==> project-homestead: Checking if box 'laravel/homestead' version '10.0.0-beta' is up to date...
==> project-homestead: Setting the name of the VM: project-homestead
==> project-homestead: Clearing any previously set network interfaces...
==> project-homestead: Preparing network interfaces based on configuration...
    project-homestead: Adapter 1: nat
    project-homestead: Adapter 2: hostonly
==> project-homestead: Forwarding ports...
    project-homestead: 80 (guest) => 8000 (host) (adapter 1)
    project-homestead: 443 (guest) => 44300 (host) (adapter 1)
    project-homestead: 3306 (guest) => 33060 (host) (adapter 1)
    project-homestead: 4040 (guest) => 4040 (host) (adapter 1)
    project-homestead: 5432 (guest) => 54320 (host) (adapter 1)
    project-homestead: 8025 (guest) => 8025 (host) (adapter 1)
    project-homestead: 9600 (guest) => 9600 (host) (adapter 1)
    project-homestead: 27017 (guest) => 27017 (host) (adapter 1)
    project-homestead: 22 (guest) => 2222 (host) (adapter 1)
==> project-homestead: Running 'pre-boot' VM customizations...
==> project-homestead: Booting VM...
==> project-homestead: Waiting for machine to boot. This may take a few minutes...
    project-homestead: SSH address: 127.0.0.1:2222
    project-homestead: SSH username: vagrant
    project-homestead: SSH auth method: private key
    project-homestead: Warning: Remote connection disconnect. Retrying...
    project-homestead: Warning: Connection reset. Retrying...
    project-homestead: Warning: Connection aborted. Retrying...
    project-homestead:
    project-homestead: Vagrant insecure key detected. Vagrant will automatically replace
    project-homestead: this with a newly generated keypair for better security.
    project-homestead:
    project-homestead: Inserting generated public key within guest...
    project-homestead: Removing insecure key from the guest if it's present...
    project-homestead: Key inserted! Disconnecting and reconnecting using new SSH key...
==> project-homestead: Machine booted and ready!
==> project-homestead: Checking for guest additions in VM...
==> project-homestead: [vagrant-hostsupdater] Checking for host entries
==> project-homestead: [vagrant-hostsupdater] Writing the following entries to (C:/WINDOWS/system32/drivers/etc/hosts)
==> project-homestead: [vagrant-hostsupdater]   192.168.12.120  project-homestead  # VAGRANT: 78fef416707bc4537918db3c92034e0b (project-homestead) / c79abdb0-e399-43cc-8cb8-3bf49eb6c36d
==> project-homestead: [vagrant-hostsupdater]   192.168.12.120  project.local  # VAGRANT: 78fef416707bc4537918db3c92034e0b (project-homestead) / c79abdb0-e399-43cc-8cb8-3bf49eb6c36d
==> project-homestead: [vagrant-hostsupdater] This operation requires administrative access. You may skip it by manually adding equivalent entries to the hosts file.
==> project-homestead: Setting hostname...
==> project-homestead: Configuring and enabling network interfaces...
==> project-homestead: Mounting shared folders...
    project-homestead: /vagrant => C:/Users/Braunson/Documents/GitHub/project
    project-homestead: /home/vagrant/project => C:/Users/Braunson/Documents/GitHub/project
==> project-homestead: Running provisioner: file...
    project-homestead: aliases => /tmp/bash_aliases
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: inline script
    project-homestead:
    project-homestead: ssh-rsa -- Removed --
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: inline script
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: inline script
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: inline script
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: inline script
    project-homestead: Ignoring feature: webdriver because it is set to false
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: C:/Users/GEEKYB~1/AppData/Local/Temp/vagrant-shell20200624-25348-1h6622x.sh
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: C:/Users/GEEKYB~1/AppData/Local/Temp/vagrant-shell20200624-25348-4gi4r0.sh
==> project-homestead: Running provisioner: Creating Certificate: project.local (shell)...
    project-homestead: Running: script: Creating Certificate: project.local
    project-homestead: Updating certificates in /etc/ssl/certs...
    project-homestead: 1 added, 0 removed; done.
    project-homestead: Running hooks in /etc/ca-certificates/update.d...
    project-homestead: done.
==> project-homestead: Running provisioner: Creating Site: project.local (shell)...
    project-homestead: Running: script: Creating Site: project.local
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: inline script
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: C:/Users/GEEKYB~1/AppData/Local/Temp/vagrant-shell20200624-25348-1v5hayg.sh
==> project-homestead: Running provisioner: Creating Schedule (shell)...
    project-homestead: Running: script: Creating Schedule
==> project-homestead: Running provisioner: Clear Variables (shell)...
    project-homestead: Running: script: Clear Variables
==> project-homestead: Running provisioner: Restarting Cron (shell)...
    project-homestead: Running: script: Restarting Cron
==> project-homestead: Running provisioner: Restart Webserver (shell)...
    project-homestead: Running: script: Restart Webserver
==> project-homestead: Running provisioner: Creating MySQL Database: homestead (shell)...
    project-homestead: Running: script: Creating MySQL Database: homestead
==> project-homestead: Running provisioner: Creating Postgres Database: homestead (shell)...
    project-homestead: Running: script: Creating Postgres Database: homestead
==> project-homestead: Running provisioner: Creating MySQL Database: project (shell)...
    project-homestead: Running: script: Creating MySQL Database: project
==> project-homestead: Running provisioner: Creating Postgres Database: project (shell)...
    project-homestead: Running: script: Creating Postgres Database: project
==> project-homestead: Running provisioner: Update Composer (shell)...
    project-homestead: Running: script: Update Composer
    project-homestead: You are already using composer version 1.10.7 (stable channel).
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: C:/Users/GEEKYB~1/AppData/Local/Temp/vagrant-shell20200624-25348-39c6n.sh
==> project-homestead: Running provisioner: Update motd (shell)...
    project-homestead: Running: script: Update motd
==> project-homestead: Running provisioner: shell...
    project-homestead: Running: C:/Users/GEEKYB~1/AppData/Local/Temp/vagrant-shell20200624-25348-zn31rh.sh

    project-homestead: installing PHPMyAdmin
    project-homestead: Downloading phpMyAdmin RELEASE_5_0_2
    project-homestead: Serving the domain: pma.project.local
    project-homestead: bash: line 16: serve-laravel: command not found
    project-homestead: Installing dependencies for phpMyAdmin on pma.project.local
    project-homestead: yarn install v1.22.4
    project-homestead: [1/4] Resolving packages...
    project-homestead: [2/4] Fetching packages...
    project-homestead: info There appears to be trouble with your network connection. Retrying...
    project-homestead: info fsevents@2.0.7: The platform "linux" is incompatible with this module.
    project-homestead: info "fsevents@2.0.7" is an optional dependency and failed compatibility check. Excluding it from installation.
    project-homestead: [3/4] Linking dependencies...
    project-homestead: [4/4] Building fresh packages...
    project-homestead: $ yarn run --silent css-compile --quiet --style=compressed
    project-homestead: Done in 40.93s.

ls -alh /vagrant && df -h

vagrant@project-homestead:~$ ls -alh /vagrant && df -h
total 1.9M
drwxrwxrwx  1 vagrant vagrant 8.0K Jun 24 18:28 .
drwxr-xr-x 21 root    root    4.0K Jun 24 18:33 ..
-rwxrwxrwx  1 vagrant vagrant 1.4K Jun 24 18:29 after.sh
-rwxrwxrwx  1 vagrant vagrant 8.0K Jun 24 18:28 aliases
drwxrwxrwx  1 vagrant vagrant 4.0K Jun 22 16:07 app
-rwxrwxrwx  1 vagrant vagrant 1.7K Jun 22 16:07 artisan
drwxrwxrwx  1 vagrant vagrant    0 Jun 22 16:07 bootstrap
-rwxrwxrwx  1 vagrant vagrant 3.4K Jun 23 21:05 composer.json
-rwxrwxrwx  1 vagrant vagrant 353K Jun 24 00:26 composer.lock
drwxrwxrwx  1 vagrant vagrant 4.0K Jun 22 16:07 config
drwxrwxrwx  1 vagrant vagrant 4.0K Jun 22 16:07 database
-rwxrwxrwx  1 vagrant vagrant  226 Jun 22 21:23 .editorconfig
-rwxrwxrwx  1 vagrant vagrant  936 Jun 23 21:10 .env
-rwxrwxrwx  1 vagrant vagrant  885 Jun 23 21:07 .env.example
drwxrwxrwx  1 vagrant vagrant 4.0K Jun 24 18:29 .git
-rwxrwxrwx  1 vagrant vagrant   64 Jun 22 16:07 .gitattributes
drwxrwxrwx  1 vagrant vagrant 4.0K Jun 22 20:54 .github
-rwxrwxrwx  1 vagrant vagrant  615 Jun 23 23:12 .gitignore
drwxrwxrwx  1 vagrant vagrant 4.0K Jun 24 18:29 .homestead
-rwxrwxrwx  1 vagrant vagrant  454 Jun 24 17:55 Homestead.yaml
-rwxrwxrwx  1 vagrant vagrant  653 Jun 22 21:35 Homestead.yaml.dist
-rwxrwxrwx  1 vagrant vagrant 691K Jun 24 00:27 _ide_helper.php
-rwxrwxrwx  1 vagrant vagrant 1.1K Jun 22 16:07 package.json
-rwxrwxrwx  1 vagrant vagrant 593K Jun 22 16:07 package-lock.json
-rwxrwxrwx  1 vagrant vagrant 1.2K Jun 22 21:23 .php_cs
-rwxrwxrwx  1 vagrant vagrant 118K Jun 24 00:27 .phpstorm.meta.php
-rwxrwxrwx  1 vagrant vagrant  325 Jun 23 19:34 phpunit-printer.yml
-rwxrwxrwx  1 vagrant vagrant 1.7K Jun 23 19:39 phpunit.xml
-rwxrwxrwx  1 vagrant vagrant  106 Jun 22 16:07 Procfile
drwxrwxrwx  1 vagrant vagrant 4.0K Jun 22 16:07 public
-rwxrwxrwx  1 vagrant vagrant 1008 Jun 22 20:26 readme.md
drwxrwxrwx  1 vagrant vagrant 4.0K Jun 22 16:07 resources
drwxrwxrwx  1 vagrant vagrant    0 Jun 23 22:52 routes
drwxrwxrwx  1 vagrant vagrant    0 Jun 22 16:07 storage
drwxrwxrwx  1 vagrant vagrant 4.0K Jun 23 19:56 tests
drwxrwxrwx  1 vagrant vagrant    0 Jun 23 23:30 .vagrant
-rwxrwxrwx  1 vagrant vagrant 1.9K Jun 24 18:28 Vagrantfile
-rwxrwxrwx  1 vagrant vagrant 2.2K Jun 24 18:28 Vagrantfile-old
drwxrwxrwx  1 vagrant vagrant  16K Jun 24 00:26 vendor
drwxrwxrwx  1 vagrant vagrant    0 Jun 22 17:08 .vscode
-rwxrwxrwx  1 vagrant vagrant  572 Jun 22 16:07 webpack.mix.js
Filesystem                               Size  Used Avail Use% Mounted on
udev                                     951M     0  951M   0% /dev
tmpfs                                    199M  1.4M  198M   1% /run
/dev/mapper/homestead--vg-root            54G  6.7G   45G  14% /
tmpfs                                    994M   28K  994M   1% /dev/shm
tmpfs                                    5.0M     0  5.0M   0% /run/lock
tmpfs                                    994M     0  994M   0% /sys/fs/cgroup
/dev/sda1                                511M  4.0K  511M   1% /boot/efi
/dev/mapper/homestead--vg-mysql--master   63G  237M   60G   1% /homestead-vg/master
tmpfs                                    199M   28K  199M   1% /run/user/124
vagrant                                  931G  570G  362G  62% /vagrant
home_vagrant_project                   931G  570G  362G  62% /home/vagrant/project
tmpfs                                    199M  4.0K  199M   1% /run/user/1000

aliases

alias ..="cd .."
alias ...="cd ../.."

alias h='cd ~'
alias c='clear'
alias art=artisan

alias codecept='vendor/bin/codecept'
alias phpspec='vendor/bin/phpspec'
alias phpunit='vendor/bin/phpunit'
alias serve=serve-laravel

alias xoff='sudo phpdismod -s cli xdebug'
alias xon='sudo phpenmod -s cli xdebug'

alias nrd="npm run dev"
alias nrw="npm run watch"
alias nrwp="npm run watch-poll"
alias nrh="npm run hot"
alias nrp="npm run production"

alias yrd="yarn run dev"
alias yrw="yarn run watch"
alias yrwp="yarn run watch-poll"
alias yrh="yarn run hot"
alias yrp="yarn run production"

function artisan() {
    php artisan "$@"
}

function dusk() {
    pids=$(pidof /usr/bin/Xvfb)

    if [ ! -n "$pids" ]; then
        Xvfb :0 -screen 0 1280x960x24 &
    fi

    php artisan dusk --filter "$@"
}

function php56() {
    sudo update-alternatives --set php /usr/bin/php5.6
    sudo update-alternatives --set php-config /usr/bin/php-config5.6
    sudo update-alternatives --set phpize /usr/bin/phpize5.6
}

function php70() {
    sudo update-alternatives --set php /usr/bin/php7.0
    sudo update-alternatives --set php-config /usr/bin/php-config7.0
    sudo update-alternatives --set phpize /usr/bin/phpize7.0
}

function php71() {
    sudo update-alternatives --set php /usr/bin/php7.1
    sudo update-alternatives --set php-config /usr/bin/php-config7.1
    sudo update-alternatives --set phpize /usr/bin/phpize7.1
}

function php72() {
    sudo update-alternatives --set php /usr/bin/php7.2
    sudo update-alternatives --set php-config /usr/bin/php-config7.2
    sudo update-alternatives --set phpize /usr/bin/phpize7.2
}

function php73() {
    sudo update-alternatives --set php /usr/bin/php7.3
    sudo update-alternatives --set php-config /usr/bin/php-config7.3
    sudo update-alternatives --set phpize /usr/bin/phpize7.3
}

function php74() {
    sudo update-alternatives --set php /usr/bin/php7.4
    sudo update-alternatives --set php-config /usr/bin/php-config7.4
    sudo update-alternatives --set phpize /usr/bin/phpize7.4
}

function serve-apache() {
    if [[ "$1" && "$2" ]]
    then
        sudo bash /vagrant/scripts/create-certificate.sh "$1"
        sudo dos2unix /vagrant/scripts/site-types/apache.sh
        sudo bash /vagrant/scripts/site-types/apache.sh "$1" "$2" 80 443 "${3:-7.4}"
    else
        echo "Error: missing required parameters."
        echo "Usage: "
        echo "  serve-apache domain path"
    fi
}

function serve-laravel() {
    if [[ "$1" && "$2" ]]
    then
        sudo bash /vagrant/scripts/create-certificate.sh "$1"
        sudo dos2unix /vagrant/scripts/site-types/laravel.sh
        sudo bash /vagrant/scripts/site-types/laravel.sh "$1" "$2" 80 443 "${3:-7.4}"
    else
        echo "Error: missing required parameters."
        echo "Usage: "
        echo "  serve domain path"
    fi
}

function serve-proxy() {
    if [[ "$1" && "$2" ]]
    then
        sudo dos2unix /vagrant/scripts/site-types/proxy.sh
        sudo bash /vagrant/scripts/site-types/proxy.sh "$1" "$2" 80 443 "${3:-7.4}"
    else
        echo "Error: missing required parameters."
        echo "Usage: "
        echo "  serve-proxy domain port"
    fi
}

function serve-silverstripe() {
    if [[ "$1" && "$2" ]]
    then
        sudo bash /vagrant/scripts/create-certificate.sh "$1"
        sudo dos2unix /vagrant/scripts/site-types/silverstripe.sh
        sudo bash /vagrant/scripts/site-types/silverstripe.sh "$1" "$2" 80 443 "${3:-7.4}"
    else
        echo "Error: missing required parameters."
        echo "Usage: "
        echo "  serve-silverstripe domain path"
    fi
}

function serve-spa() {
    if [[ "$1" && "$2" ]]
    then
        sudo bash /vagrant/scripts/create-certificate.sh "$1"
        sudo dos2unix /vagrant/scripts/site-types/spa.sh
        sudo bash /vagrant/scripts/site-types/spa.sh "$1" "$2" 80 443 "${3:-7.4}"
    else
        echo "Error: missing required parameters."
        echo "Usage: "
        echo "  serve-spa domain path"
    fi
}

function serve-statamic() {
    if [[ "$1" && "$2" ]]
    then
        sudo bash /vagrant/scripts/create-certificate.sh "$1"
        sudo dos2unix /vagrant/scripts/site-types/statamic.sh
        sudo bash /vagrant/scripts/site-types/statamic.sh "$1" "$2" 80 443 "${3:-7.4}"
    else
        echo "Error: missing required parameters."
        echo "Usage: "
        echo "  serve-statamic domain path"
    fi
}

function serve-symfony2() {
    if [[ "$1" && "$2" ]]
    then
        sudo bash /vagrant/scripts/create-certificate.sh "$1"
        sudo dos2unix /vagrant/scripts/site-types/symfony2.sh
        sudo bash /vagrant/scripts/site-types/symfony2.sh "$1" "$2" 80 443 "${3:-7.4}"
    else
        echo "Error: missing required parameters."
        echo "Usage: "
        echo "  serve-symfony2 domain path"
    fi
}

function serve-symfony4() {
    if [[ "$1" && "$2" ]]
    then
        sudo bash /vagrant/scripts/create-certificate.sh "$1"
        sudo dos2unix /vagrant/scripts/site-types/symfony4.sh
        sudo bash /vagrant/scripts/site-types/symfony4.sh "$1" "$2" 80 443 "${3:-7.4}"
    else
        echo "Error: missing required parameters."
        echo "Usage: "
        echo "  serve-symfony4 domain path"
    fi
}

function serve-pimcore() {
    if [[ "$1" && "$2" ]]
    then
        sudo bash /vagrant/scripts/create-certificate.sh "$1"
        sudo dos2unix /vagrant/scripts/site-types/pimcore.sh
        sudo bash /vagrant/scripts/site-types/pimcore.sh "$1" "$2" 80 443 "${3:-7.4}"
    else
        echo "Error: missing required parameters."
        echo "Usage: "
        echo "  serve-pimcore domain path"
    fi
}

function share() {
    if [[ "$1" ]]
    then
        ngrok http ${@:2} -host-header="$1" 80
    else
        echo "Error: missing required parameters."
        echo "Usage: "
        echo "  share domain"
        echo "Invocation with extra params passed directly to ngrok"
        echo "  share domain -region=eu -subdomain=test1234"
    fi
}

function flip() {
    sudo bash /vagrant/scripts/flip-webserver.sh
}

function __has_pv() {
    $(hash pv 2>/dev/null);

    return $?
}

function __pv_install_message() {
    if ! __has_pv; then
        echo $1
        echo "Install pv with \`sudo apt-get install -y pv\` then run this command again."
        echo ""
    fi
}

function dbexport() {
    FILE=${1:-/vagrant/mysqldump.sql.gz}

    # This gives an estimate of the size of the SQL file
    # It appears that 80% is a good approximation of
    # the ratio of estimated size to actual size
    SIZE_QUERY="select ceil(sum(data_length) * 0.8) as size from information_schema.TABLES"

    __pv_install_message "Want to see export progress?"

    echo "Exporting databases to '$FILE'"

    if __has_pv; then
        ADJUSTED_SIZE=$(mysql --vertical -uhomestead -psecret -e "$SIZE_QUERY" 2>/dev/null | grep 'size' | awk '{print $2}')
        HUMAN_READABLE_SIZE=$(numfmt --to=iec-i --suffix=B --format="%.3f" $ADJUSTED_SIZE)

        echo "Estimated uncompressed size: $HUMAN_READABLE_SIZE"
        mysqldump -uhomestead -psecret --all-databases --skip-lock-tables --routines 2>/dev/null | pv  --size=$ADJUSTED_SIZE | gzip > "$FILE"
    else
        mysqldump -uhomestead -psecret --all-databases --skip-lock-tables --routines 2>/dev/null | gzip > "$FILE"
    fi

    echo "Done."
}

function dbimport() {
    FILE=${1:-/vagrant/mysqldump.sql.gz}

    __pv_install_message "Want to see import progress?"

    echo "Importing databases from '$FILE'"

    if __has_pv; then
        pv "$FILE" --progress --eta | zcat | mysql -uhomestead -psecret 2>/dev/null
    else
        cat "$FILE" | zcat | mysql -uhomestead -psecret 2>/dev/null
    fi

    echo "Done."
}

function xphp() {
    (php -m | grep -q xdebug)
    if [[ $? -eq 0 ]]
    then
        XDEBUG_ENABLED=true
    else
        XDEBUG_ENABLED=false
    fi

    if ! $XDEBUG_ENABLED; then xon; fi

    HOST_IP=$(last --limit=1 | grep -oP '\d+(\.\d+){3}')

    php \
        -dxdebug.remote_host=${HOST_IP} \
        -dxdebug.remote_autostart=1 \
        "$@"

    if ! $XDEBUG_ENABLED; then xoff; fi
}
svpernova09 commented 4 years ago

Ok, let's take a step back. My concern was something wasn't being mounted properly but we've confirmed /vagrant is being mounted as we expect. Also based on logs your 1 site specified in the site config is also being created as we expect.

Why are you trying to create sites in your after.sh? I'm not surprised it's not working as expected. My suspicion is something is weird happening in the shell as it's swapping between providers and the alias you think is being loaded isn't.

Homestead needs to know about the sites so it's always going to be better to let Homestead manage the sites (we base several assumptions on these sites like features) instead of you trying to create them after the fact.

I'd prefer to avoid having to support site creation outside of Homestead's usual provisioning (before after.sh is called)

Braunson commented 4 years ago

Hmm, I originally used to put the site in the Homestead file but wanted to simplify things and use a one liner in the after.sh. As serve-laravel was an available function I saw the opportunity to move away from having i.e. phpMyAdmin setup in Homestead.yaml and instead taken care of in a one liner in after.sh.

This is the one-liner that runs:

curl -sS https://gist.githubusercontent.com/Braunson/f7205b83bef1acfb2fe833fdefd30271/raw/phpmyadmin.sh | bash -s pma.project.local

This is the code from the link:

#!/bin/bash

LATEST_VERSION=$(curl -sS 'https://api.github.com/repos/phpmyadmin/phpmyadmin/releases/latest' | awk -F '"' '/tag_name/{print $4}')
DOWNLOAD_URL="https://api.github.com/repos/phpmyadmin/phpmyadmin/tarball/$LATEST_VERSION"
SERVE_URL=${1:-phpmyadmin.local}

echo "Downloading phpMyAdmin $LATEST_VERSION"
wget $DOWNLOAD_URL -q -O 'phpmyadmin.tar.gz'

mkdir phpmyadmin && tar xf phpmyadmin.tar.gz -C phpmyadmin --strip-components 1

rm phpmyadmin.tar.gz

# Create an SSL Cert and site instance
echo "Serving the domain: $1"
serve-laravel $SERVE_URL $(pwd)/phpmyadmin

echo "Installing dependencies for phpMyAdmin on $1"
cd phpmyadmin && composer update --no-dev --quiet --no-interaction && yarn

sudo service nginx reload

It's just curious why I can't make use of serve-laravel alias in the after.sh file. Shouldn't the aliases be setup already? Isn't the vagrantuser running the after.sh file?

The only reason I see it being better to add the site into Homestead.yaml is because it'll setup the reference to the domain in the hosts file mapped to the IP.

I'll try and change the script above to instead just install PMA to ~/phpmyadmin and set the domain/site up in Homestead.yaml.

--

Looks like the user running (OS/SSH users) is vagrant in the directory /home/vagrant

svpernova09 commented 4 years ago

This is the one-liner that runs:

curl -sS https://gist.githubusercontent.com/Braunson/f7205b83bef1acfb2fe833fdefd30271/raw/phpmyadmin.sh | bash -s pma.project.local

Gotcha, 100% understand and this should be fine. Homestead shouldn't care at all about this

It's just curious why I can't make use of serve-laravel alias in the after.sh file. Shouldn't the aliases be setup already? Isn't the vagrant user running the after.sh file?

You'd like so right? But what's happened is Vagrant is running after.sh as it's own provisioner (As you saw via Vagrantfile). This means after.sh is executed as root, and most importantly: not in the homestead user's profile The alias is only available to the vagrant user in sessions that have sourced the aliases file.

What I would try is instead of this:

serve-laravel $SERVE_URL $(pwd)/phpmyadmin

Try:

bash /vagrant/scripts/create-certificate.sh "$SERVE_URL"
dos2unix /vagrant/scripts/site-types/laravel.sh
bash /vagrant/scripts/site-types/laravel.sh "$SERVE_URL" "$(pwd)/phpmyadmin" 80 443 "7.4"
Braunson commented 4 years ago

Ah that makes sense, thanks for the code. I've updated the snippet, will test soon. For now I've added the map/site into the Homestead.yaml file and just had the code installed to ~/phpmyadmin.

Thank you @svpernova09 for your very detailed and quick help on this, it's much appreciated!

svpernova09 commented 4 years ago

Last thought: Remember this means phpmyadmin will be owned by root. throw a chown -R vagrant:vagrant /path/to/phpmyadmin after you've setup everything so it runs as vagrant