If you liked what you've learned so far, dive in!
Subscribe to get access to this tutorial plus
video, code and script downloads.
With a Subscription, click any sentence in the script to jump to that part of the video!
Login SubscribeOur app is a big 500 error because Symfony can't write to its cache directory.
This is an easy fix... well mostly. Let's start with the easy part: if we 777 the var/
directory, we should be good.
Add a new task at the end: "Fix var directory permissions":
- hosts: vb | |
... lines 3 - 9 | |
tasks: | |
... lines 11 - 143 | |
- name: Fix var directory permissions | |
... lines 145 - 163 |
To refer to the var/
directory, I'll create another variable: symfony_var_dir
set to {{ symfony_root_dir }}/var
:
- hosts: vb | |
vars: | |
... line 5 | |
symfony_root_dir: /var/www/project | |
... line 7 | |
symfony_var_dir: "{{ symfony_root_dir }}/var" | |
... lines 9 - 163 |
Back at the bottom, use the file
module, set the path
to the new variable, and state to directory
:
- hosts: vb | |
... lines 3 - 9 | |
tasks: | |
... lines 11 - 143 | |
- name: Fix var directory permissions | |
file: | |
path: "{{ symfony_var_dir }}" | |
state: directory | |
... lines 148 - 163 |
That'll create the directory if it doesn't exist, but, it should. Then, they key part: mode: 0777
and recurse: yes
:
- hosts: vb | |
... lines 3 - 9 | |
tasks: | |
... lines 11 - 143 | |
- name: Fix var directory permissions | |
file: | |
path: "{{ symfony_var_dir }}" | |
state: directory | |
mode: 0777 | |
recurse: yes | |
... lines 150 - 163 |
Tip
If you're going to 777 your var/
directory, make sure that you've uncommented
the umask
calls in app.php
, app_dev.php
and bin/console
:
... lines 2 - 4 | |
// If you don't want to setup permissions the proper way, just uncomment the following PHP line | |
// read http://symfony.com/doc/current/book/installation.html#checking-symfony-application-configuration-and-setup | |
// for more information | |
umask(0000); | |
... lines 9 - 26 |
... lines 2 - 5 | |
// If you don't want to setup permissions the proper way, just uncomment the following PHP line | |
// read http://symfony.com/doc/current/book/installation.html#checking-symfony-application-configuration-and-setup | |
// for more information | |
umask(0000); | |
... lines 10 - 33 |
#!/usr/bin/env php | |
... lines 3 - 7 | |
// if you don't want to setup permissions the proper way, just uncomment the following PHP line | |
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information | |
umask(0000); | |
... lines 11 - 30 |
You can see this in the finished code download.
Ok, run the playbook!
ansible-playbook ansible/playbook.yml -i ansible/hosts.ini
By the way, needing to re-run the entire playbook after a tiny change is annoying! We'll learn a trick in a minute to help with this.
Done! Ok, switch back to your browser and try it. Woohoo! A working Symfony project... not our project yet, but still, winning! We'll use our real project next.
Setting the directory permissions to 777 is easy... and perfectly fine for a development machine. But if this were a production machine, well, 777 isn't ideal... though honestly, a lot of people do this.
What's better? In a few minutes, we'll add a task to clear and warm up Symfony's cache. On a production machine, after you've done that, you can set the var/cache
permissions back to be non-writeable, so 555. In theory, that should just work! But in practice, you'll probably need to tweak a few other settings to use non-filesystem cache - like making annotations cache in APC.
But, that's more about deployment - which we'll save for a different course!
Hey Damir,
Did you add www.mootube.l to your hosts? I mean that /etc/hosts file. Also, please, keep in mind that "www.mootube.l" and "mootube.l" are different hosts, and you should add them both to your /etc/hosts
Cheers!
Hey Victor,
I have one modul writing "mootube.l" server name. How can i write "www.mootue.l" ? If I copy and paste modul, I just rewrite all lines with "mootube.l".
Hey Damir,
I suppose you just need to use "mootube.l" instead of "www.mootube.l" - the easiest solution. So, literally, use the exact same domain in the browser URL as you use in your Ansible playbooks, as I understand it should be http://mootube.l for you (not http://www.mootube.l)
Cheers!
Hey Victor,
I don't know, what was the problem. I just added in file /etc/hosts of my host machine vagrant's IP with "mootube.l" domain name, and it's works. Will see is it works in future :). May be I will find problem later.
Thanks.
Hey Damir,
Yeah, you had to do this, and we mention this somewhere in this course, so probably you just missed it. Glad it works finally!
Cheers!
hello i have a problem with a script im working on... and i really need your help with it.. my email is patorikky@gmail.com....just send me an email so that we can engage in a discussion from there....or you can send me a whatsapp text +2349025627930 it'll be easier for us to communicate there
Hey Junior,
I'm sorry, but we do not provide support via WhatsApp, etc. And unfortunately we do not have a bandwidth for providing support in your personal projects, we can answer only questions related to the screencasts. If you have a question related to our screencasts, please, post the comment below the video where you have the problem.
I hope this helps!
Cheers!
Hey Jian,
Unfortunately, we don't have such course, but we talk about APC in this screencast: https://knpuniversity.com/s... . However, if you're on PHP >=5.5 - you probably want to use OPcache instead of APC.
Cheers!
// composer.json
{
"require": {
"php": ">=5.5.9",
"symfony/symfony": "3.1.*", // v3.1.4
"doctrine/orm": "^2.5", // v2.7.2
"doctrine/doctrine-bundle": "^1.6", // 1.6.4
"doctrine/doctrine-cache-bundle": "^1.2", // 1.3.0
"symfony/swiftmailer-bundle": "^2.3", // v2.3.11
"symfony/monolog-bundle": "^2.8", // 2.11.1
"symfony/polyfill-apcu": "^1.0", // v1.2.0
"sensio/distribution-bundle": "^5.0", // v5.0.12
"sensio/framework-extra-bundle": "^3.0.2", // v3.0.16
"incenteev/composer-parameter-handler": "^2.0", // v2.1.2
"doctrine/doctrine-migrations-bundle": "^1.2", // v1.2.0
"snc/redis-bundle": "^2.0", // 2.0.0
"predis/predis": "^1.1", // v1.1.1
"composer/package-versions-deprecated": "^1.11" // 1.11.99
},
"require-dev": {
"sensio/generator-bundle": "^3.0", // v3.0.8
"symfony/phpunit-bridge": "^3.0", // v3.1.4
"doctrine/data-fixtures": "^1.1", // 1.3.3
"hautelook/alice-bundle": "^1.3" // v1.4.1
}
}
Hello!
Thanks for tutorial. It's great!
But, on this chapter I stacked.
Ansible works perfect, but my project does not work. In firefox browser I see
next error: "We can’t connect to the server at www.mootube.l".
May be I missed something?
I have a Ubuntu distribution 18.04, and the same on vagrant.