├── .gitignore
├── laravel-starter.png
├── provisioning
├── .my.cnf.j2
├── vars
│ └── main.yml
├── ansible.cfg
├── hosts
├── nginx.conf
└── playbook.yml
├── .travis.yml
├── Vagrantfile
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .vagrant/
2 | .idea/
3 | provisioning/playbook.retry
4 |
--------------------------------------------------------------------------------
/laravel-starter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/msztorc/laravel-starter/HEAD/laravel-starter.png
--------------------------------------------------------------------------------
/provisioning/.my.cnf.j2:
--------------------------------------------------------------------------------
1 | [client]
2 | user="{{ db_root_name }}"
3 | password="{{ db_root_pass }}"
--------------------------------------------------------------------------------
/provisioning/vars/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 | web_root: /var/www/my-project
3 | web_host: laravel.host
4 | db_root_name: root
5 | db_root_pass: p4ssvv0rD
6 | app_db_name: my-project
7 | app_db_user: my-project
8 | app_db_pass: p4ssvv0rD
--------------------------------------------------------------------------------
/provisioning/ansible.cfg:
--------------------------------------------------------------------------------
1 | [defaults]
2 | host_key_checking=false
3 |
4 | [paramiko_connection]
5 | record_host_keys=false
6 |
7 | [ssh_connection]
8 | ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null
--------------------------------------------------------------------------------
/provisioning/hosts:
--------------------------------------------------------------------------------
1 | [local]
2 | localhost ansible_connection=local
3 |
4 | [vagrant]
5 | 10.10.10.10 ansible_connection=local ansible_ssh_user=vagrant ansible_ssh_private_key_file=/vagrant/.vagrant/machines/default/virtualbox/private_key
6 |
7 | [staging]
8 | X.X.X.X ansible_ssh_user=root
9 |
10 | [all:vars]
11 | ansible_python_interpreter=/usr/bin/python3
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | ---
2 | # dist: bionic
3 |
4 | matrix:
5 | include:
6 | - os: linux
7 | dist: bionic
8 | - os: linux
9 | dist: xenial
10 | #group: travis_latest
11 | #env: DOCKER="debian:buster" VARIANT="debian"
12 |
13 | language: python
14 | python: "3.5"
15 |
16 | # Doc: https://docs.travis-ci.com/user/customizing-the-build#Build-Matrix
17 | env:
18 | - ANSIBLE_VERSION=latest
19 |
20 | branches:
21 | only:
22 | - master
23 |
24 | before_install:
25 | - sudo apt-get update -qq
26 |
27 | install:
28 | # Install Ansible.
29 | - if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install ansible; else pip install ansible==$ANSIBLE_VERSION; fi
30 | - if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install ansible-lint; fi
31 |
32 | script:
33 | # Check the role/playbook's syntax.
34 | - ansible-playbook --limit="local" --inventory-file=provisioning/hosts provisioning/playbook.yml --syntax-check
35 |
36 | # Run the role/playbook with ansible-playbook.
37 | - ansible-playbook --limit="local" --inventory-file=provisioning/hosts provisioning/playbook.yml -vvvv --skip-tags update,copy_host_ssh_id
38 |
--------------------------------------------------------------------------------
/provisioning/nginx.conf:
--------------------------------------------------------------------------------
1 | server {
2 | listen 80;
3 |
4 | root {{ web_root }}/public;
5 | index index.php index.html index.htm;
6 |
7 | charset utf-8;
8 |
9 | add_header X-Frame-Options "SAMEORIGIN";
10 | add_header X-XSS-Protection "1; mode=block";
11 | add_header X-Content-Type-Options "nosniff";
12 |
13 | server_name {{ web_host }};
14 |
15 | location / {
16 | try_files $uri $uri/ =404 /index.php?$query_string;
17 | }
18 |
19 | # Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
20 | sendfile off;
21 |
22 | location = /favicon.ico { access_log off; log_not_found off; }
23 | location = /robots.txt { access_log off; log_not_found off; }
24 |
25 | error_page 404 /index.php;
26 |
27 | location = /50x.html {
28 | root {{ web_root }}/public;
29 | }
30 |
31 | location ~ \.php$ {
32 | try_files $uri =404;
33 | fastcgi_split_path_info ^(.+\.php)(/.+)$;
34 | fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
35 | fastcgi_index index.php;
36 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
37 | include fastcgi_params;
38 | }
39 |
40 | location ~ /\.(?!well-known).* {
41 | deny all;
42 | }
43 | }
--------------------------------------------------------------------------------
/Vagrantfile:
--------------------------------------------------------------------------------
1 | # -*- mode: ruby -*-
2 | # vi: set ft=ruby :
3 |
4 | # All Vagrant configuration is done below. The "2" in Vagrant.configure
5 | # configures the configuration version (we support older styles for
6 | # backwards compatibility). Please don't change it unless you know what
7 | # you're doing.
8 | Vagrant.configure("2") do |config|
9 | # The most common configuration options are documented and commented below.
10 | # For a complete reference, please see the online documentation at
11 | # https://docs.vagrantup.com.
12 |
13 | # Every Vagrant development environment requires a box. You can search for
14 | # boxes at https://vagrantcloud.com/search.
15 | config.vm.box = "ubuntu/bionic64"
16 |
17 | # Disable automatic box update checking. If you disable this, then
18 | # boxes will only be checked for updates when the user runs
19 | # `vagrant box outdated`. This is not recommended.
20 | # config.vm.box_check_update = false
21 |
22 | # Create a forwarded port mapping which allows access to a specific port
23 | # within the machine from a port on the host machine. In the example below,
24 | # accessing "localhost:8080" will access port 80 on the guest machine.
25 | # NOTE: This will enable public access to the opened port
26 | # config.vm.network "forwarded_port", guest: 80, host: 8080
27 |
28 | # Create a forwarded port mapping which allows access to a specific port
29 | # within the machine from a port on the host machine and only allow access
30 | # via 127.0.0.1 to disable public access
31 | # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
32 |
33 | # Create a private network, which allows host-only access to the machine
34 | # using a specific IP.
35 | # config.vm.network "private_network", ip: "192.168.33.10"
36 | config.vm.network "private_network", ip: "10.10.10.10"
37 | config.vm.hostname = "laravel.host"
38 |
39 | # Create a public network, which generally matched to bridged network.
40 | # Bridged networks make the machine appear as another physical device on
41 | # your network.
42 | # config.vm.network "public_network"
43 |
44 | # Share an additional folder to the guest VM. The first argument is
45 | # the path on the host to the actual folder. The second argument is
46 | # the path on the guest to mount the folder. And the optional third
47 | # argument is a set of non-required options.
48 | # config.vm.synced_folder "../data", "/vagrant_data"
49 | #owner: "www-data",
50 | #group: "ubuntu",
51 | #mount_options: ["dmode=775,fmode=664"]
52 |
53 | # Provider-specific configuration so you can fine-tune various
54 | # backing providers for Vagrant. These expose provider-specific options.
55 | # Example for VirtualBox:
56 | #
57 | # config.vm.provider "virtualbox" do |vb|
58 | # # Display the VirtualBox GUI when booting the machine
59 | # vb.gui = true
60 | #
61 | # # Customize the amount of memory on the VM:
62 | # vb.memory = "1024"
63 | # end
64 |
65 | config.vm.provider "virtualbox" do |vb|
66 | vb.memory = 2048
67 | vb.cpus = 2
68 | end
69 |
70 | #
71 | # View the documentation for the provider you are using for more
72 | # information on available options.
73 |
74 | # Enable provisioning with a shell script. Additional provisioners such as
75 | # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
76 | # documentation for more information about their specific syntax and use.
77 | # config.vm.provision "shell", inline: <<-SHELL
78 | # apt-get update
79 | # apt-get install -y apache2
80 | # SHELL
81 |
82 | config.vm.provision "shell", inline: <<-SHELL
83 | #sed -i 's/ChallengeResponseAuthentication no/ChallengeResponseAuthentication yes/g' /etc/ssh/sshd_config
84 | #sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
85 | #echo "ubuntu:ubuntu" | sudo chpasswd
86 | #ssh-keyscan -H 10.10.10.10 >> ~/.ssh/known_hosts
87 | #service ssh restart
88 | SHELL
89 |
90 | # Run Ansible from the Vagrant VM
91 | config.vm.provision "ansible_local" do |ansible|
92 | ansible.install = true
93 | ansible.version = "latest"
94 | ansible.verbose = true
95 | ansible.playbook = "provisioning/playbook.yml"
96 | ansible.limit = "vagrant"
97 | ansible.inventory_path = "provisioning/hosts"
98 | end
99 | end
100 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Laravel Starter
2 |
3 | [](https://travis-ci.org/msztorc/laravel-starter)
4 | [](https://www.opensource.org/licenses/MIT)
5 |
6 | [](https://github.com/msztorc/laravel-starter)
7 |
8 | Quick and easy server provisioning for Laravel using Ansible + Vagrant auto provisioning for local environments.
9 |
10 | **Default environment setup**
11 |
12 | - ubuntu 18.04 (bionic64)
13 | - laravel:latest
14 | - php 7.4
15 | - mysql 5.7
16 | - nginx
17 |
18 | #### Provisioning methods
19 |
20 | - Vagrant deployment with Ansible local provisioning
21 | - Ansible provisioning (remote environments)
22 |
23 |
24 | ### Quick start
25 |
26 | Clone this repo
27 |
28 | ```bash
29 | git clone https://github.com/msztorc/laravel-starter.git
30 | ```
31 |
32 | ```bash
33 | cd laravel-starter
34 | ```
35 |
36 | Adjust your config settings like project name, passwords, etc... - see below for more details.
37 |
38 | **Provisioning variables**
39 |
40 | [provisioning/group_vars/all](provisioning/group_vars/all)
41 |
42 | ```yaml
43 | web_root: /var/www/my-project # project path
44 | web_host: laravel.host # project domain
45 | db_root_pass: p4ssvv0rD # database root password
46 | app_db_name: my-project # application database name
47 | app_db_user: my-project # application database user
48 | app_db_pass: p4ssvv0rD # application database user password
49 | ```
50 |
51 | **Inventory**
52 |
53 | [provisioning/hosts](provisioning/hosts)
54 |
55 | ```ini
56 | [local]
57 | localhost ansible_connection=local
58 |
59 | [vagrant]
60 | 10.10.10.10 ansible_connection=local ansible_ssh_user=vagrant ansible_ssh_private_key_file=/vagrant/.vagrant/machines/default/virtualbox/private_key
61 |
62 | [sandbox]
63 | X.X.X.X ansible_ssh_user=root
64 |
65 | [all:vars]
66 | ansible_python_interpreter=/usr/bin/python3
67 | ```
68 |
69 |
70 | #### Vagrant deployment with Ansible local provisioning
71 |
72 | Vagrant configurations are stored in [Vagrantfile](Vagrantfile)
73 |
74 | Box default config
75 |
76 | __IP & hostname__
77 |
78 | ```ruby
79 | config.vm.network "private_network", ip: "10.10.10.10"
80 | config.vm.hostname = "laravel.host"
81 | ```
82 |
83 | __Resources (default: memory - 2GB, vCPUs - 2)__
84 |
85 | ```ruby
86 | config.vm.provider "virtualbox" do |vb|
87 | vb.memory = 2048
88 | vb.cpus = 2
89 | end
90 | ```
91 |
92 | __Set synced folder__ (local, destination)
93 |
94 | ```ruby
95 | # config.vm.synced_folder "../data", "/vagrant_data"
96 | ```
97 |
98 | If you want to set synced folder mapping local project to box webroot, you have to uncomment this line:
99 |
100 | ```ruby
101 | config.vm.synced_folder "../GIT/my-project", "/var/www/my-project"
102 | ```
103 |
104 |
105 | Run your VM using Vagrant with Ansible auto-provisioning
106 |
107 | ```bash
108 | vagrant up
109 | ```
110 |
111 |
112 | **Note**
113 | Remember to run `vagrant reload` every time when Vagrantfile has been updated
114 |
115 | Other useful vagrant commands
116 |
117 | Check status of all machines
118 |
119 | ``vagrant global-status``
120 |
121 | Halt vagrant box (run in box directory)
122 |
123 | ``vagrant halt``
124 |
125 | Up vagrant box (run in box directory)
126 |
127 | ``vagrant up``
128 |
129 | **Note**
130 | Remember to run `vagrant reload` and `vagrant provision` every time when any provisioning configs were updated
131 |
132 | ### Xdebug
133 |
134 | To integrate Xdebug with PhpStorm perform following steps:
135 |
136 | 1. Make sure you have ``php7.4-xdebug`` extension installed in within the vagrant box.
137 | 2. Append following configuration to the ``/etc/php/7.4/php.ini`` file:
138 | ```
139 | [xdebug]
140 | zend_extension=/usr/lib/php/20170718/xdebug.so
141 | xdebug.remote_enable=1
142 | xdebug.remote_port=9000
143 | xdebug.profiler_enable=1
144 | xdebug.remote_host=10.10.10.10
145 | ```
146 | 3. Execute command: ``sudo service php7.4-fpm restart``.
147 | 4. Install ``Xdebug helper`` extension for Chrome (or some kind of equivalent for your browser).
148 | 5. In PhpStorm:
149 | * Press Ctrl+Shift+A and search ``Web Server Debug Validation``.
150 | * Choose ``Local Web Server or Shared Folder``.
151 | * Determine ``Path to create validation script`` like so: ``////my-project/public``
152 | * Determine ``Url to validation script`` like so: ``http://laravel.host``.
153 | * After clicking ``Validate`` button you should receive some information with green ticks. If not - you probably messed up with previous settings.
154 | 6. Navigate to: ``Languages & Frameworks > PHP > Servers`` and map your local and remote paths. It should be something like: ``my-project -> /var/www/my-project``.
155 | 7. Press ``Start Listening for PHP Debug Connections`` button. It should be placed on top right side with phone icon.
156 | 8. Place breakpoint somewhere in your code that will be executed in the next request e.g. ``index.php``.
157 | 9. In the browser:
158 | * Make sure you have enabled ``Debug`` option in previously installed browser extension.
159 | * Refresh application's page.
160 | 10. In PhpStorm ``Debug`` panel should appear. You can toggle it using Alt+5.
161 | 11. Enjoy :metal:
162 |
163 |
164 |
165 | #### Ansible provisioning
166 |
167 | Adjust `staging` section in inventory file [provisioning/hosts](provisioning/hosts) and set IP for remote server
168 |
169 | ```ini
170 | [staging]
171 | X.X.X.X ansible_ssh_user=root
172 | ```
173 |
174 | ```bash
175 | cd provisioning
176 | ansible-playbook -i hosts --limit staging playbook.yml
177 | ```
178 |
179 | or using user and password
180 |
181 | ```bash
182 | ansible-playbook -i hosts --limit staging playbook.yml -u root -k
183 | ```
184 |
185 | `-u` , `--user`
186 |
187 | `-k`, `--ask-pass`
188 | ask for connection password
189 |
190 |
191 | if you want to enable debugging just add to `ansible-playbook` command verbose option `-v` (`-vvv` for more, `-vvvv` to enable connection debugging)
--------------------------------------------------------------------------------
/provisioning/playbook.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - hosts: all
3 | become: yes
4 | remote_user: root
5 | vars_files:
6 | - vars/main.yml
7 |
8 | tasks:
9 |
10 | - name: Install required packages
11 | apt:
12 | name: "{{ packages }}"
13 | vars:
14 | packages:
15 | - git
16 | - python3-selinux
17 | - selinux-utils
18 | - python3-dev
19 | - build-essential
20 | - nginx
21 | - sqlite3
22 | - python-setuptools
23 | - python3-pip
24 | - curl
25 | update_cache: yes
26 | state: latest
27 |
28 | - name: Install PyMySQL
29 | command: pip3 install PyMySQL
30 |
31 |
32 | - name: Making sure that pymysql is present
33 | become: true
34 | pip:
35 | name: pymysql
36 | state: present
37 |
38 | - name: Install dependencies for mysql
39 | apt:
40 | name: "{{ packages }}"
41 | update_cache: no
42 | state: latest
43 | vars:
44 | packages:
45 | - libmysqlclient-dev
46 | when: ansible_distribution == "Ubuntu"
47 |
48 | - name: Install dependencies for mariadb
49 | apt:
50 | name: "{{ packages }}"
51 | update_cache: no
52 | state: latest
53 | vars:
54 | packages:
55 | - libmariadbclient-dev
56 | when: ansible_distribution == "Debian"
57 |
58 | - name: Install mysql
59 | apt:
60 | name: "{{ packages }}"
61 | update_cache: no
62 | state: latest
63 | vars:
64 | packages:
65 | - mysql-server
66 | - mysql-client
67 | when: ansible_distribution == "Ubuntu"
68 |
69 | - name: Install mariadb
70 | apt:
71 | name: "{{ packages }}"
72 | update_cache: no
73 | state: latest
74 | vars:
75 | packages:
76 | - mariadb-server
77 | - mariadb-client
78 | when: ansible_distribution == "Debian"
79 |
80 | - name: Start MySQL
81 | service: name=mysql state=started
82 | become: true
83 |
84 | - name: Get MySQL version.
85 | command: 'mysql --version'
86 | register: mysql_cli_version
87 | changed_when: false
88 | check_mode: false
89 |
90 | # - name: Set root user password
91 | # mysql_user:
92 | # name: root
93 | # password: "{{ db_root_pass }}"
94 | # check_implicit_admin: true
95 | # when: ('MariaDB' in mysql_cli_version.stdout)
96 |
97 | - name: Disallow root login remotely
98 | command: 'mysql -NBe "{{ item }}"'
99 | with_items:
100 | - DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')
101 | changed_when: false
102 |
103 | - name: Get list of hosts for the root user.
104 | command: mysql -NBe
105 | "SELECT Host
106 | FROM mysql.user
107 | WHERE User = 'root'
108 | ORDER BY (Host='localhost') ASC"
109 | register: mysql_root_hosts
110 | changed_when: false
111 | check_mode: false
112 |
113 | # Note: We do not use mysql_user for this operation, as it doesn't always update
114 | # the root password correctly. See: https://goo.gl/MSOejW
115 | # Set root password for MySQL >= 5.7.x.
116 | - name: Update MySQL root password for localhost root account (5.7.x).
117 | shell: >
118 | mysql -u root -NBe
119 | 'ALTER USER "root"@"{{ item }}"
120 | IDENTIFIED WITH mysql_native_password BY "{{ db_root_pass }}";'
121 | with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}"
122 | when: >
123 | ('5.7.' in mysql_cli_version.stdout or '8.0.' in mysql_cli_version.stdout)
124 |
125 | # Set root password for MySQL < 5.7.x.
126 | - name: Update MySQL root password for localhost root account (< 5.7.x).
127 | shell: >
128 | mysql -NBe
129 | 'SET PASSWORD FOR "root"@"{{ item }}" = PASSWORD("{{ db_root_pass }}");'
130 | with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}"
131 | when: >
132 | ('5.7.' not in mysql_cli_version.stdout and '8.0.' not in mysql_cli_version.stdout)
133 |
134 |
135 | # This command will fail when the root password was set previously
136 |
137 | # - name: Check if root password is set
138 | # shell: >
139 | # mysqladmin -u root status
140 | # changed_when: false
141 | # failed_when: false
142 | # register: root_pwd_check
143 | # tags: mariadb
144 |
145 | # - name: Set MariaDB root password for the first time (root@localhost)
146 | # mysql_user:
147 | # name: root
148 | # password: "{{ db_root_pass }}"
149 | # host: localhost
150 | # state: present
151 | # when: (root_pwd_check.rc == 0 and 'MariaDB' in mysql_cli_version.stdout)
152 | # tags: mariadb
153 |
154 | # - name: Set MariaDB root password for 127.0.0.1, ::1
155 | # mysql_user:
156 | # name: root
157 | # password: "{{ db_root_pass }}"
158 | # host: "{{ item }}"
159 | # login_user: root
160 | # login_password: "{{ db_root_pass }}"
161 | # state: present
162 | # with_items:
163 | # - ::1
164 | # - 127.0.0.1
165 | # when: (root_pwd_check.rc == 0 and 'MariaDB' in mysql_cli_version.stdout)
166 | # tags: mariadb
167 |
168 |
169 | - name: Create .my.cnf file with root password credentials
170 | template:
171 | src: ".my.cnf.j2"
172 | dest: "/root/.my.cnf"
173 | owner: root
174 | group: root
175 | mode: 0600
176 | tags:
177 | - mycnf
178 | become: yes
179 |
180 | - name: Create the app database
181 | mysql_db:
182 | name: "{{app_db_name}}"
183 | login_user: "{{db_root_name}}"
184 | login_password: "{{db_root_pass}}"
185 | config_file: "/root/.my.cnf"
186 | collation: utf8_general_ci
187 | encoding: utf8
188 | state: present
189 |
190 | - name: Create the app user
191 | mysql_user:
192 | name: "{{app_db_user}}"
193 | password: "{{ app_db_pass }}"
194 | priv: "{{app_db_name}}.*:ALL"
195 | host: localhost
196 |
197 | - name: Set the correct opcache filename (Ubuntu/Debian).
198 | set_fact:
199 | php_opcache_conf_filename: "10-opcache.ini"
200 |
201 | - name: Add repository for latest PHP (Ubuntu).
202 | apt_repository: repo='ppa:ondrej/php'
203 | when: ansible_distribution == "Ubuntu"
204 |
205 | # Debian-specific tasks.
206 | - name: Add dependencies for latest PHP (Debian).
207 | apt:
208 | name: "{{ packages }}"
209 | vars:
210 | packages:
211 | - apt-transport-https
212 | - ca-certificates
213 | when: ansible_distribution == "Debian"
214 |
215 | - name: Add Ondrej Sury's apt key (Debian).
216 | apt_key:
217 | url: https://packages.sury.org/php/apt.gpg
218 | state: present
219 | when: ansible_distribution == "Debian"
220 |
221 | - name: Add Ondrej Sury's repo (Debian).
222 | apt_repository:
223 | repo: "deb https://packages.sury.org/php/ {{ ansible_distribution_release }} main"
224 | state: present
225 | register: php_ondrej_debian_repo
226 | when: ansible_distribution == "Debian"
227 |
228 | - name: Update apt caches after repo is added (Debian).
229 | apt: update_cache=yes
230 | when: php_ondrej_debian_repo.changed and (ansible_distribution == "Debian")
231 |
232 | # PHP package purges.
233 | - name: Purge PHP version packages.
234 | apt:
235 | name: "{{ packages }}"
236 | state: absent
237 | purge: yes
238 | force: yes
239 | vars:
240 | packages:
241 | - php5.6-common
242 | - php7.0-common
243 | - php7.1-common
244 | - php7.2-common
245 | - php7.3-common
246 |
247 | - name: install php
248 | apt:
249 | name: "{{ packages }}"
250 | update_cache: yes
251 | state: latest
252 | vars:
253 | packages:
254 | - php7.4-cli
255 | - php7.4-curl
256 | - php7.4-fpm
257 | - php7.4-intl
258 | - php7.4-json
259 | - php7.4-sqlite3
260 | - php7.4-mbstring
261 | - php7.4-xml
262 | - php7.4-zip
263 | - php7.4-mysql
264 |
265 | - name: ensure php7.4-fpm cgi.fix_pathinfo=0
266 | lineinfile: dest=/etc/php/7.4/fpm/php.ini regexp='^(.*)cgi.fix_pathinfo=' line=cgi.fix_pathinfo=0
267 | notify:
268 | - restart php7.4-fpm
269 | - restart nginx
270 |
271 | - name: create /var/www/ directory
272 | file: dest=/var/www/ state=directory owner=www-data group=www-data mode=0755
273 |
274 | - name: Clone git repository
275 | git: >
276 | dest={{web_root}}
277 | repo=https://github.com/laravel/laravel.git
278 | update=no
279 | become: yes
280 | become_user: root
281 | register: cloned
282 |
283 | - name: Set swap
284 | shell: /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
285 | become: yes
286 | become_user: root
287 |
288 | - name: Set swap
289 | shell: /sbin/mkswap /var/swap.1
290 | become: yes
291 | become_user: root
292 |
293 | - name: Set swap
294 | shell: /sbin/swapon /var/swap.1
295 | become: yes
296 | become_user: root
297 |
298 | - name: install composer
299 | shell: curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
300 | become: yes
301 | become_user: root
302 | args:
303 | creates: /usr/local/bin/composer
304 |
305 | - name: composer create-project
306 | composer: command=create-project working_dir={{web_root}} optimize_autoloader=no
307 | become: yes
308 | become_user: root
309 | when: cloned
310 |
311 | - name: set APP_DEBUG=false
312 | lineinfile: dest={{web_root}}/.env regexp='^APP_DEBUG=' line=APP_DEBUG=false
313 |
314 | - name: set APP_ENV=production
315 | lineinfile: dest={{web_root}}/.env regexp='^APP_ENV=' line=APP_ENV=production
316 |
317 | - name: set DB_DATABASE
318 | lineinfile: dest={{web_root}}/.env regexp='^DB_DATABASE=' line=DB_DATABASE={{app_db_name}}
319 |
320 | - name: set DB_USERNAME
321 | lineinfile: dest={{web_root}}/.env regexp='^DB_USERNAME=' line=DB_USERNAME={{app_db_user}}
322 |
323 | - name: set DB_PASSWORD
324 | lineinfile: dest={{web_root}}/.env regexp='^DB_PASSWORD=' line=DB_PASSWORD={{app_db_pass}}
325 |
326 | # set app key
327 | - name: set APP_KEY
328 | lineinfile: dest={{web_root}}/.env regexp='^APP_KEY=' line=APP_KEY=base64:OcpsUbr53Dlz2HPavY8v/C757q0nIUUieIPFwuc5meE=
329 |
330 | - name: Configure nginx
331 | template: src=nginx.conf dest=/etc/nginx/sites-available/default
332 | notify:
333 | - restart php7.4-fpm
334 | - restart nginx
335 |
336 | - name: install composer packages
337 | composer: command=install working_dir={{web_root}} optimize_autoloader=no
338 | become: yes
339 | become_user: root
340 |
341 | - name: Setting group
342 | command: chgrp -R www-data {{web_root}}/storage {{web_root}}/bootstrap/cache
343 | become: yes
344 |
345 | - name: Setting permissions
346 | command: chmod -R ug+rwx {{web_root}}/storage {{web_root}}/bootstrap/cache
347 | become: yes
348 |
349 | # - name: Laravel key generate
350 | # command: php artisan key:generate
351 | # args:
352 | # chdir: {{web_root}}
353 |
354 | - name: Getting ip address
355 | command: bash -c "hostname -I | awk '$0=$NF'"
356 | register: getip
357 |
358 | - name: Provisioning done
359 | debug:
360 | msg:
361 | - "--------------------------------------------------------------"
362 | - "Machine IP address {{ getip.stdout }}"
363 | - "Host {{ web_host }} (remember to add to your hosts file)"
364 | - "Web address: http://{{ web_host }}"
365 |
366 | handlers:
367 | - name: restart php7.4-fpm
368 | service: name=php7.4-fpm state=restarted
369 |
370 | - name: restart nginx
371 | service: name=nginx state=restarted
372 |
373 | - name: restart mysql
374 | service: name=mysql state=restarted
375 |
--------------------------------------------------------------------------------