Adding Homestead to a SlimPHP App

Joe • March 21, 2016

php slimphp vagrant

I've been a fan of SlimPHP for a really long time. Recently I started using it for a site that I do freelancing development for and wanted to share a quick solution to local development. It's no secret that I love Laravel's Homestead vagrant environment. Using the per-project installation method, you are only three commands away from running a SlimPHP skeleton application in a local Homestead VM.

Create your new SlimPHP project based on their Skeleton Project

composer create-project slim/slim-skeleton SlimPHPDemo
Installing slim/slim-skeleton (3.0.1)
  - Installing slim/slim-skeleton (3.0.1)
    Downloading: 100%

Created project in SlimPHPDemo
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
  - Installing psr/log (1.0.0)
    Loading from cache

  - Installing monolog/monolog (1.17.2)
    Downloading: 100%

  - Installing psr/http-message (1.0)
    Downloading: 100%

  - Installing slim/php-view (2.0.6)
    Downloading: 100%

  - Installing pimple/pimple (v3.0.2)
    Downloading: 100%

  - Installing nikic/fast-route (v0.6.0)
    Downloading: 100%

  - Installing container-interop/container-interop (1.1.0)
    Loading from cache

  - Installing slim/slim (3.1.0)
    Downloading: 100%

monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
monolog/monolog suggests installing graylog2/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing php-console/php-console (Allow sending log messages to Google Chrome)
monolog/monolog suggests installing raven/raven (Allow sending log messages to a Sentry server)
monolog/monolog suggests installing rollbar/rollbar (Allow sending log messages to Rollbar)
monolog/monolog suggests installing ruflin/elastica (Allow sending log messages to an Elastic Search server)
monolog/monolog suggests installing videlalvaro/php-amqplib (Allow sending log messages to an AMQP server using php-amqplib)
Generating autoload files

Now we can add Homestead:

composer require -- dev laravel/homestead
Using version ^3.0 for laravel/homestead
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing symfony/process (v3.0.3)
    Loading from cache

  - Installing symfony/polyfill-mbstring (v1.1.1)
    Loading from cache

  - Installing symfony/console (v3.0.3)
    Loading from cache

  - Installing laravel/homestead (v3.0.2)
    Loading from cache

symfony/console suggests installing symfony/event-dispatcher ()
Writing lock file
Generating autoload files

Now "make" the Homestead config

./vendor/bin/homestead make
Homestead Installed!

Now you're ready to vagrant up!

vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'laravel/homestead'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'laravel/homestead' is up to date...
==> default: A newer version of the box 'laravel/homestead' is available! You currently
==> default: have version '0.4.1'. The latest is version '0.4.2'. Run
==> default: `vagrant box update` to update.
==> default: Setting the name of the VM: slimphpdemo
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 80 => 8000 (adapter 1)
    default: 443 => 44300 (adapter 1)
    default: 3306 => 33060 (adapter 1)
    default: 5432 => 54320 (adapter 1)
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/halo/PhpstormProjects/SlimPHPDemo
    default: /home/vagrant/slimphpdemo => /Users/halo/PhpstormProjects/SlimPHPDemo
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBeub1sTnpX7Tp7f0ukLAz7dMn7CS9w6eHmc1wtJNp/iXHzyBRKZ+ov8z+voCVJOrSDyTsG0IKcby8+UxwpzR2nyqiBPw+oaSD1elIHFS48h7Wd5f41S6QeHUlhac20fa5EHTnNw9jphtxDuYPa+xiaNdbdvJKC1jZuipsqc4qlcDC1LISOtIsAzMF1fnByWEe3JBvRxvCmegruu424chIGG23elIoBHsOvY/6BI+5G2BNSBvqzHxfQ2mK6j4tEj2K2s+4M3r4FrgZIYgHxxZtADdNGwditFu5ipfaQSc1n5YFQiI87iTO5OZCBdffMY3qQWaE3ne+hAVDSdJLWFDn halo@mobile-rage-work
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: Running provisioner: shell...
    default: Running: /var/folders/5r/06h4xkxs3dx9p611w11pb7h40000gn/T/vagrant-shell20160321-66474-at8i8e.sh
==> default: Running provisioner: shell...
    default: Running: /var/folders/5r/06h4xkxs3dx9p611w11pb7h40000gn/T/vagrant-shell20160321-66474-1ct6hui.sh
==> default: nginx stop/waiting
==> default: nginx start/running, process 2179
==> default:  * Restarting PHP 7.0 FastCGI Process Manager php-fpm7.0
==> default:    ...done.
==> default: Running provisioner: shell...
    default: Running: /var/folders/5r/06h4xkxs3dx9p611w11pb7h40000gn/T/vagrant-shell20160321-66474-cqhokg.sh
==> default: mysql:
==> default: [Warning] Using a password on the command line interface can be insecure.
==> default: Running provisioner: shell...
    default: Running: /var/folders/5r/06h4xkxs3dx9p611w11pb7h40000gn/T/vagrant-shell20160321-66474-4bipyl.sh
==> default: createdb: database creation failed: ERROR:  database "homestead" already exists
==> default: Running provisioner: shell...
    default: Running: /var/folders/5r/06h4xkxs3dx9p611w11pb7h40000gn/T/vagrant-shell20160321-66474-1s9n70l.sh
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
==> default: Updating to version a8e9df55dc62d8806360be2f79ad112b8678d397.
==> default:     Downloading: Connecting...
==> default:
==> default:     Downloading: 100%
==> default:
==> default:
==> default: Use composer self-update -- rollback to return to version 837fa805ec9f8dcb1e05e0fca4099f0dab4f1e04
vagrant up: 00:52

Don't forget to add Homestead.yaml to your .gitignore file!

Thanks for reading.