Skip to content
Open
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,42 @@ If this is your first time here, try [experimenting with the live demo](http://b
Installation
------------

## With Vagrant

We have provided a Vagrantfile for easy installation. Vagrant is software that controls some of the major virtualization software such as [VMWare Workstation](https://www.vmware.com/products/workstation.html) and [Oracle VirtualBox](https://www.virtualbox.org/). With a simple text file, you can clone a machine to run locally on your computer. More details can be found at [https://www.vagrantup.com](https://www.vagrantup.com).


$ vagrant up

Now browse to http://localhost:8080 to see the OAuth2 Demo Application

### xdebug (Optional)

- URL: http://localhost:8080
- Local port (listening): 9000
- Host IP: 192.168.34.1
- Guest IP: 192.168.34.2
- Path map: `this/directory` maps to `/var/www`

For example, if you're using JetBrains PhpStorm:

- Create a new `PHP Web Application`:

![Run/Debug Configurations](http://i.imgur.com/yg2XolG.png "Run/Debug Configurations")

- Add a new server by clicking on the `...` beside `Server`
- Set the `Host` to `localhost`
- Set the `Port` to `8080`
- Map this directory to `/var/www/`

![Servers](http://i.imgur.com/xeItbEg.png "Servers")

- Set a test breakpoint in the `index.php` and Debug

![Debug](http://i.imgur.com/yArVmvS.png "Debug")

## Locally

Use [Composer](http://getcomposer.org/) to install this application:

$ git clone git://github.com/bshaffer/oauth2-demo-php.git
Expand Down
99 changes: 99 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = '2'

@script = <<SCRIPT
# Install dependencies

add-apt-repository ppa:ondrej/php -y
apt-get update
apt-get install -y apache2 php5.6 php5.6-curl php5.6-sqlite php5.6-xdebug curl php5.6-curl zip unzip
apt remove -y php7.1-cli

# Configure Apache
echo "<VirtualHost *:8080>
DocumentRoot /var/www/web
AllowEncodedSlashes On

<Directory /var/www/web>
Options +FollowSymLinks -MultiViews
DirectoryIndex index.php index.html
Order allow,deny
Allow from all
AllowOverride All
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</Directory>


ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:8081>
DocumentRoot /var/www/web
AllowEncodedSlashes On

<Directory /var/www/web>
Options +FollowSymLinks -MultiViews
DirectoryIndex index.php index.html
Order allow,deny
Allow from all
AllowOverride All
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</Directory>


ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>" > /etc/apache2/sites-available/000-default.conf

a2enmod rewrite
echo "xdebug.remote_enable=on" >> /etc/php/5.6/apache2/conf.d/xdebug.ini
echo "xdebug.remote_host=192.168.34.1" >> /etc/php/5.6/apache2/conf.d/xdebug.ini
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This address seems oddly specific (192.168.34.1). Why is that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that 33 is the default. I could be wrong.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

33 definitely used to be/possibly is still the default. Doing a quick Google search returns tons of documents with 192.168.33.1.

sed -i 's/Listen 80/Listen 8080/' /etc/apache2/ports.conf

echo Listen 8081 >> /etc/apache2/ports.conf
service apache2 restart

cd /var/www/
cp data/parameters.json.dist data/parameters.json
sed -i 's?"grant"?"http://localhost:8081/lockdin/token"?g' data/parameters.json
sed -i 's?"access"?"http://localhost:8081/lockdin/resource"?g' data/parameters.json


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

cd /var/www/
composer install

# Reset home directory of vagrant user
if ! grep -q "cd /var/www" /home/vagrant/.profile; then
echo "cd /var/www" >> /home/vagrant/.profile
fi


SCRIPT

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'bento/ubuntu-16.04'
config.vm.network "private_network", ip: "192.168.34.2"
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.network "forwarded_port", guest: 8081, host: 8081
config.vm.synced_folder '.', '/var/www'
config.vm.provision 'shell', inline: @script

config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "1024"]
vb.customize ["modifyvm", :id, "--name", "oauth2-demo-php"]
end
end