Skip to content

Instantly share code, notes, and snippets.

@aeosys
Last active July 9, 2017 17:14
Show Gist options
  • Save aeosys/9ea58d042b13ae12e07a1c993d1832b4 to your computer and use it in GitHub Desktop.
Save aeosys/9ea58d042b13ae12e07a1c993d1832b4 to your computer and use it in GitHub Desktop.
PHP7 dev server for Symfony
---
- hosts: all
become: true
vars:
apache_config_file: symfony.apache.conf
tasks:
# Packages
- name: Update apt cache
apt: update_cache=yes
- name: Install https transport
apt:
name: apt-transport-https
state: present
update_cache: yes
- name: Add repository key for PHP7.1
apt_key:
url: https://packages.sury.org/php/apt.gpg
state: present
- name: Add repository for PHP7.1
apt_repository: repo={{ item }} state=present update_cache=yes
with_items:
- deb https://packages.sury.org/php/ jessie main
- name: Install packages
apt: name={{ item }} state=latest
with_items:
- git
- apache2
- mariadb-server
- python-mysqldb
# Apache
- name: Enabled mod_rewrite
apache2_module: name=rewrite state=present
notify:
- restart apache2
- name: Move Apache configuration to quest
copy: src="{{ apache_config_file }}" dest=/etc/apache2/sites-available/dev-site.conf
notify:
- restart apache2
- name: Apply Apache configuration
command: a2ensite dev-site
args:
creates: /etc/apache2/sites-enabled/dev-site.conf
notify:
- restart apache2
- name: Disable default Apache configuration
command: a2dissite 000-default
args:
removes: /etc/apache2/sites-enabled/000-default.conf
notify:
- restart apache2
- name: Create db for site
mysql_db: name=site state=present
- name: Create site folder
file: path=/home/vagrant/site state=directory mode=0775
become: true
become_user: vagrant
- name: Link www to home folder
file: src=/home/vagrant/site path=/var/www/site state=link force=yes
# PHP
- name: Install PHP7.1
apt: name={{ item }} state=latest
with_items:
- php7.1
- php7.1-bz2
- php7.1-curl
- php7.1-cli
- php7.1-dba
- php7.1-imap
- php7.1-intl
- php7.1-json
- php7.1-mbstring
- php7.1-mcrypt
- php7.1-mysql
- php7.1-odbc
- php7.1-soap
- php7.1-xml
- php7.1-zip
# Composer
- name: Install composer
shell: curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
args:
creates: /usr/local/bin/composer
handlers:
- name: restart apache2
service: name=apache2 state=restarted
<VirtualHost *:80>
ServerName devel.tld
ServerAlias www.devel.tld
DocumentRoot /var/www/symfony/web
<Directory /var/www/symfony/web>
AllowOverride None
Require all granted
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
# Authentication headers
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
</IfModule>
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
<Directory /var/www/symfony>
Options FollowSymlinks
</Directory>
# optionally disable the RewriteEngine for the asset directories
# which will allow apache to simply reply with a 404 when files are
# not found instead of passing the request into the full symfony stack
<Directory /var/www/symfony/web/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
ErrorLog /var/log/apache2/symfony_error.log
CustomLog /var/log/apache2/symfony_access.log combined
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment