Skip to content

Commit

Permalink
Added Vagrant support
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel committed Jun 14, 2018
1 parent 83ba06e commit 9052397
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@ clover.xml
coveralls-upload.json
phpunit.xml
vendor/
*.log
41 changes: 41 additions & 0 deletions README.md
Expand Up @@ -27,6 +27,46 @@ you can enable using:
$ composer development-enable
```

## Vagrant

You can execute [Vagrant](https://www.vagrantup.com/) to setup a Linux
environment to run the `zend-expressive-api` application.

This setup will install the following environment:

- Linux Ubuntu 18.04
- PHP 7.2.5
- nginx 1.5.1
- SQLite 3.22

In order to run Vagrant you need a VM hypervisor like [VirtualBox](https://www.virtualbox.org/)
that can be execute on Win, Mac and Linux operating systems.

To execute the Vagrant box you can use the command as follows:

```bash
vagrant up
```

This will require some times (the first execution). When finished, you can see
the application running at `localhost:8080`.

The web directory of the nginx server is configured to the `public` folder
(`/home/ubuntu/zend-expressive-api` in the VM). You have also the logs of the
web server (access_log, error_log) configured in the `log` local folder.

If you want to connect to the VM you can SSH into it, using the command:

```bash
vagrant ssh
```

If you want to close/stop the VM you can use the following command:

```bash
vagrant destroy
```

## REST example

We provide a REST API to a _User_ resource backed by a simple
Expand All @@ -48,6 +88,7 @@ as well as the OAuth2 database. You can do so as follows:
# Creating and populating the sample database
$ sqlite3 data/users.sqlite < data/schema.sql
$ sqlite3 data/users.sqlite < data/data.sql

# Creating and populating the OAuth2 database
$ sqlite3 data/oauth2.sqlite < vendor/zendframework/zend-expressive-authentication/oauth2/data/oauth2.sql
$ sqlite3 data/oauth2.sqlite < data/oath2_test_users.sql
Expand Down
62 changes: 62 additions & 0 deletions Vagrantfile
@@ -0,0 +1,62 @@
# Vagrant configuration for zend-expressive workshop
# @author Enrico Zimuel (enrico@zend.com)

VAGRANTFILE_API_VERSION = '2'

$script = <<SCRIPT
# Fix for Temporary failure resolving 'archive.ubuntu.com'
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null
# Install dependencies
apt-get update
apt-get install -y nginx git curl sqlite3 php7.2 php7.2-cli php7.2-fpm php7.2-sqlite3 php7.2-pdo php7.2-xml
# Configure Nginx
echo "server {
listen 8080;
root /home/ubuntu/zend-expressive-api/public;
server_name ubuntu-xenial;
# Logs
access_log /home/ubuntu/zend-expressive-api/log/access_log;
error_log /home/ubuntu/zend-expressive-api/log/error_log;
index index.php index.html index.htm;
location / {
try_files \\$uri \\$uri/ /index.php;
}
location ~ \\.php\$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
include snippets/fastcgi-php.conf;
}
# Block access to .htaccess
location ~ \\.htaccess {
deny all;
}
}" > /etc/nginx/sites-available/zend-expressive-api
chmod 644 /etc/nginx/sites-available/zend-expressive-api
ln -s /etc/nginx/sites-available/zend-expressive-api /etc/nginx/sites-enabled/zend-expressive-api
service nginx restart
if [ -e /usr/local/bin/composer ]; then
/usr/local/bin/composer self-update
else
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
fi
chmod +r /home/ubuntu/zend-expressive-api/data/oauth2/*
SCRIPT

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'bento/ubuntu-18.04'
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.synced_folder '.', '/home/ubuntu/zend-expressive-api'
config.vm.provision 'shell', inline: $script

config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "1024"]
vb.customize ["modifyvm", :id, "--name", "zend-expressive-api"]
end
end
4 changes: 4 additions & 0 deletions log/.gitignore
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
20 changes: 0 additions & 20 deletions public/rpc.php

This file was deleted.

0 comments on commit 9052397

Please sign in to comment.