Skip to content

Fixed to update the vagrant box with changes done on Symfony projects and added PostgreSQL database #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,29 @@ Installation
* Install vagrant using the installation instructions in the [Getting Started document](https://www.vagrantup.com/docs/getting-started/)
* Clone this repository and cd into it
* Run ```vagrant up``` in order to set up the box using the ```ansible_local``` provisioner
* You should now have your working
* You should now have your working
* Symfony2 Standard Edition under http://192.168.50.4:8081/
* Laravel Quickstart example app under http://192.168.50.4:8082/

The installation process will create a folder symfony-standard inside
the main directory of the repository. You can now start working inside
this folder directly on your host computer using your favourite IDE.
Changes done there will be reflected directly on the vagrant box as the
directory is mounted in the vagrant box under ```/vagrant```. Also you
can login into the box using ```vagrant ssh``` and have the full control
The installation process will create a folder symfony-standard inside
the main directory of the repository. You can now start working inside
this folder directly on your host computer using your favourite IDE.
Changes done there will be reflected directly on the vagrant box as the
directory is mounted in the vagrant box under ```/vagrant```. Also you
can login into the box using ```vagrant ssh``` and have the full control
over processes etc.

As the provisioning using the ansible provisioner is very fast you can
As the provisioning using the ansible provisioner is very fast you can
repeat the whole procedure at any time. In order to start fresh just run
```vagrant destroy``` and ```vagrant up```. This will undo all you manual
```vagrant destroy``` and ```vagrant up```. This will undo all you manual
changes done on the vagrant box and provide you with a clean setup.

Installed components
--------------------

* [Nginx](http://nginx.org)
* [MySQL](http://dev.mysql.com/downloads/mysql/)
* [PostgreSQL](https://www.postgresql.org/)
* [PHP 7.0](http://www.php.net/)
* [php-fpm](http://php-fpm.org)
* [git](http://git-scm.com/)
Expand All @@ -45,6 +46,9 @@ Changes
-------

### unreleased
* Added PostgreSQL 9.3 Database


### v1.4.1

* Introduce php_version variable, set PHP default version to 7.0 [#33](https://github.com/dirkaholic/vagrant-php-dev-box/pull/33)
Expand Down
35 changes: 34 additions & 1 deletion playbooks/roles/laravel-quickstart/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,39 @@
- name: Create MySQL user for laravel
mysql_user: name=laravel password=laravel priv=*.*:ALL state=present

- name: Create PostgreSQL database for laravel
sudo: yes
sudo_user: postgres
postgresql_db: name=laravel state=present

- name: init database user
postgresql_user: name=laravel password=laravel db=symfony priv=ALL
sudo: yes
sudo_user: postgres

- name: psql check schema laravel
command: psql -t -d symfony -c "SELECT EXISTS(SELECT 1 FROM pg_namespace WHERE nspname = 'laravel');"
register: check_schema
changed_when: "'f' in '{{ check_schema.stdout }}'"
sudo: yes
sudo_user: postgres

- name: psql schema laravel
command: psql -d laravel -c "CREATE SCHEMA laravel; ALTER USER laravel SET search_path TO laravel;"
when: check_schema.changed
sudo: yes
sudo_user: postgres

- name: psql grant access to schema laravel to all
postgresql_privs: database=laravel type=schema objs=laravel roles=PUBLIC privs=USAGE
sudo: yes
sudo_user: postgres

- name: psql grant access to tables of schema laravel
postgresql_privs: database=laravel schema=laravel type=table objs=ALL_IN_SCHEMA roles=PUBLIC privs=SELECT
sudo: yes
sudo_user: postgres

- name: Clone Laravel quickstart application
git: repo=https://github.com/laravel/quickstart-basic
dest=/vagrant/laravel-quickstart
Expand Down Expand Up @@ -54,4 +87,4 @@
dest=/etc/nginx/sites-enabled/laravel.conf
state=link
notify:
- restart nginx
- restart nginx
3 changes: 2 additions & 1 deletion playbooks/roles/php/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
apt: name={{ item }} state=present
with_items:
- php{{ php_version }}-mysql
- php{{ php_version }}-pgsql
- php{{ php_version }}-intl
- php{{ php_version }}-cli
- php{{ php_version }}-mcrypt
Expand All @@ -31,4 +32,4 @@
shell: curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

- name: Configure composer cache directory to avoid using slow NFS
shell: composer config --global cache-dir /dev/shm/composer/cache
shell: composer config --global cache-dir /dev/shm/composer/cache
2 changes: 2 additions & 0 deletions playbooks/roles/postgresql/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
locale: UTF-8
32 changes: 32 additions & 0 deletions playbooks/roles/postgresql/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
- name: Add PostgreSQL repository
apt_repository: repo='deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' state=present
sudo: yes

- name: Add PostgreSQL repository key
apt_key: url=https://www.postgresql.org/media/keys/ACCC4CF8.asc state=present
sudo: yes

- name: Update apt cache
apt: update_cache=yes
sudo: yes

- name: Install PostgreSQL server
shell: >
LANG={{ locale }} LC_COLLATE={{ locale }} LC_CTYPE={{ locale }}
LC_MESSAGES={{ locale }} LC_MONETARY={{ locale }}
LC_NUMERIC={{ locale }} LC_TIME={{ locale }}
LC_ALL={{ locale }}
apt-get install -y postgresql-9.3
sudo: yes

- name: Install PostgreSQL development library
apt: pkg=libpq-dev state=present
sudo: yes

- name: Install Python Psycopg2 library
apt: pkg=python-psycopg2 state=present
sudo: yes

- name: Restart postgresql server
service: name=postgresql state=started enabled=yes
sudo: yes
41 changes: 40 additions & 1 deletion playbooks/roles/symfony-standard/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,39 @@
- name: Create MySQL user for symfony
mysql_user: name=symfony password=symfony priv=*.*:ALL state=present

- name: Create PostgreSQL database for symfony
sudo: yes
sudo_user: postgres
postgresql_db: name=symfony state=present

- name: init database user
postgresql_user: name=symfony password=symfony db=symfony priv=ALL
sudo: yes
sudo_user: postgres

- name: psql check schema symfony
command: psql -t -d symfony -c "SELECT EXISTS(SELECT 1 FROM pg_namespace WHERE nspname = 'symfony');"
register: check_schema
changed_when: "'f' in '{{ check_schema.stdout }}'"
sudo: yes
sudo_user: postgres

- name: psql schema symfony
command: psql -d symfony -c "CREATE SCHEMA symfony; ALTER USER symfony SET search_path TO symfony;"
when: check_schema.changed
sudo: yes
sudo_user: postgres

- name: psql grant access to schema symfony to all
postgresql_privs: database=symfony type=schema objs=symfony roles=PUBLIC privs=USAGE
sudo: yes
sudo_user: postgres

- name: psql grant access to tables of schema symfony
postgresql_privs: database=symfony schema=symfony type=table objs=ALL_IN_SCHEMA roles=PUBLIC privs=SELECT
sudo: yes
sudo_user: postgres

- name: Clone Symfony2 standard edition
git: repo=https://github.com/symfony/symfony-standard.git
dest=/vagrant/symfony-standard
Expand Down Expand Up @@ -44,4 +77,10 @@
dest=/etc/nginx/sites-enabled/symfony.conf
state=link
notify:
- restart nginx
- restart nginx

- name: Change to Symfony development enviroment for reflect the changes directly on the vagrant box
replace:
dest: /vagrant/symfony-standard/web/app.php
regexp: \$kernel = new.*$
replace: $kernel = new AppKernel('dev', true);
3 changes: 2 additions & 1 deletion playbooks/vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
- base
- nginx
- mysql
- postgresql
- php
- php-devtools
- php-fpm
- symfony-standard
- laravel-quickstart
- laravel-quickstart