I've never had a problem with either Symfony2 or Vagrant before this point and I'm absolutely lost as to what is happening.
Without any warning my environment died completely and will only produce the following error:
ContextErrorException: Warning:
file_get_contents(/Users/Paul/Sites/Project/htdocs/project-web/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception_full.html.twig):
failed to open stream: No such file or directory in /var/www/project-web/vendor/twig/twig/lib/Twig/Loader/Filesystem.php line 130
The reason this is strange is that Symfony is referring to my local file system...
/Users/Paul/Sites/Project/htdocs/project-web/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception_full.html.twig
....instead of the box environement which is running Ubuntu, then referring to the unix filesystem location of 'Filesystem.php'...
/var/www/project-web/vendor/twig/twig/lib/Twig/Loader/Filesystem.php
I cannot get past this screen. I have just created a brand new environment and packaged it as a its own box, then using that box I still get this error.
Can anyone help?
My first guess is you have run it locally first and the paths are in the cache. If so it should be fixed by running the following in your vagrant environment:
php app/console cache:clear
Add --env=prod if you are running the app.php rather then app_dev.php.
Always use the command line IN your vagrant box (via ssh), never cmd on the windows path.
vagrant up
vagrant ssh
... some auth ...
cd /your/project/path
php app/console ...
I'm using Homestead with Symfony 3.1.
I had to delete var/cache folder from the root of my project in the host machine.
rm -rf var/cache/ solved it.
Before, I tried out php app/console cache:clear with no results.
Related
I am deploying a Symfony 4.4 app to AWS ElasticBeanstalk and noticed that the cache wasn't cleared after each deploy.
The app was running fine though, exception made to the stale cache.
To resolve the cache issue I added the following file:
/.ebextensions/deploy.config
container_commands:
01-clear-cache:
command: php bin/console cache:clear --no-warmup --env=prod
That seems to clear the cache but then somehow it changes permissions so that I then get the error when trying to access the app.
Fatal error: Uncaught RuntimeException: Unable to write in the cache directory (/var/app/current/var/cache/prod)
Why does running cache:clear changes permissions and is there a way to avoid that happening, or at least how to resolve afterwards, ie, in the same/another .ebextensions file?
These commands are run by the root user, as specified in the docs.
The specified commands run as the root user, and are processed in alphabetical order by name. Container commands are run from the staging directory, where your source code is extracted prior to being deployed to the application server. Any changes you make to your source code in the staging directory with a container command will be included when the source is deployed to its final location.
(Emphasis mine).
When re-creating the cache, the new directories are owned by root, and your PHP process can't write there if it needs to.
Execute your command so it runs using the same user than your PHP runtime. E.g. if it runs under the www-data user:
container_commands:
01-clear-cache:
command: sudo -u webapp php bin/console cache:clear --no-warmup --env=prod
When using Ansible you can actually just use become: true as a mechanism to become a root user and become_user: xxx to become the desired user.
Example:
---
# roles/app/tasks/main.yml
- name: Run composer install
become: true
become_user: ubuntu
composer:
command: install
working_dir: "{{ deploy_path }}"
Note that you have to define a variable called deploy_path.
I got a php project which is already done and for starters I have to put it up on a server (planning to use Heroku). I am new to PHP virtual boxes, Laravel, etc. The person who made the project recommended to use Laravel so I started to get things going that way. I am running on Windows 10 and using cmder as my terminal.
I downloaded VirtualBox & Vagrant.
Then using commander I added the Laravel/Homestead box
by doing:
vagrant box add laravel/homestead
in the folder c:\Users\Jacky\vagrant\ubuntu (At least I think that is where I added it)
Afterwards I believe I did
vagrant init
or vagrant init laravel/homestead
whatever I did afterwards I was able to run
vagrant ssh
and get into the system. There I was able to check and I had php and composer installed.
I then followed laravels instructions and created a homestead folder at c:\Jack\Homestead
ran git checkout for v7.19.2
ran init.bat
and configured the Homestead.yaml file
I made the following folder map
- map: C:\Jack\myapp\public
to: /home/vagrant/myapp
and the following site map
- map: myapp.test
to: /home/vagrant/myapp/public
I am a bit confused with the directory structure of this whole thing and not sure if I was supposed to put the myapp directory inside c:\Jack\Homestead\myapp or if just doing it like i did in c:\Jack\myapp is fine.
Anyways that still worked and I could see it in my web browser. So far all was good.
Then the project instructions told me to do the following
run composer install
There was an env.example file I had to change to .env and change some setting
run php artisan key:generate
run php artisan migrate --seed
run php artisan passport:install
run php artisan storage:link
At this point I got an error that the Symlink could not be created, so I googled and found in Stack Overflow to restart as admin. I ran cmder as admin and have been having a heart attack for the last 30 minutes since it told me I had to vagrant up and when I did so it couldnt find my box and even doing vagrant box list
I would get no results and it wanted to redownload which takes over 3 hours.
I just restarted without admin and I do find that my Laravel/Homestead box is listed so I assume it was installed for my user and not admin so I guess I cant run cmder as admin.
So now I am trying to connect again, I am not sure in which folder I should be running the vagrant commands but I only seem to have a VagrantFile in my C:\Jack\Homestead folder so if I run a vagrant command anywhere else it gives me an error that a vagrant environment is required, etc.
So I tried the following inside my homestead folder:
vagrant ssh - I get:
VM must be running to open SSH connection. Run `vagrant up to start the virtual machine.
(In my VirtualBox Manager i see my homestead-7 VM running though)
vagrant up - I get:
Bringing machine 'homestead-7' up with 'virtualbox' provider...
==> homestead-7: Importing base box 'laravel/homestead'...
==> homestead-7: Matching MAC address for NAT networking...
==> homestead-7: Checking if box 'laravel/homestead' is up to date...
A VirtualBox machine with the name 'homestead-7' already exists.
Please use another name or delete the machine with the existing
name, and try again.
vagrant ssh 'homestead-7' I also get
VM must be running to open SSH connection. Run vagrant up
to start the virtual machine.
And the problem is once I do connect I assume I will still have the same problem running:
php artisan storage:link
So my questions are as follows:
Where should I have my projects myapp folder, should it be where it is at C:\Jack\myapp or am I supposed to put it in C:\Jack\Homestead\myapp
Is the VagrantFile supposed to be only in my Homestead folder and is that where I should be running all my Vagrant commands from? Like vagrant ssh and vagrant up
How do I connect again now that I am getting those errors running vagrant ssh and vagrant up
Once I connect I assume I will get the same error running php artisan storage:link since to run as administrator seems to not work what do I do?
I Assume that I should run git init and heroku create inside the myapp folder is this correct?
1) I always keep my apps folders outside of the Homestead folder. Your Homestead folder contains a git project, so if you put your apps inside you should include the folder in the .gitignore file. I think it's easier if you just put your apps elsewhere.
2) Vagrantfile is suposed to only be inside of your Homestead folder ( c:\Jack\Homestead). You should run all your vagrant commands inside the Homestead folder.
3) I used to get this error when I tried to run 'vagrant up' to a project that used the same box name 'homestead-7'. If you have version control, check if the file c:\Jack\Homestead\.vagrant\machines\homestead-7\virtualbox\id has been changed. If so, try restoring the old value and running 'vagrant up' again.
4) You are running in a windows environment, right? Windows can be a little temperamental with symlinks inside vagrant. You'll get the same problem if you try to npm install something. What I do to solve this is to run npm (and php artisan storage:link) outside of the virtual machine, in the host pc, inside the root of the app folder. Just a reminder: to do that you will need php installed in your host machine.
5) All commands related to the app (and not the virtual machine) should be run inside the virtual machine, in the folder app (ex: /home/vagrant/code/myapp) or inside the app folder of your host machine. Those two folders are in sync, thanks to vagrant.
I've recently upgraded Symfony to the new Symfony4.1. As seen over here we no longer need to setup file permissions anymore. I ran the command:
php bin/console cache:warmup
And no errors came while running that. However when I try and view the website. I get the following error.
Uncaught RuntimeException: Unable to write in the cache directory (/var/www/mywebsite.com/var/cache/prod)\n in /var/www/mywebsite.com/var/bootstrap.php.cache
Obviously this means that the new feature of Symfony4.1 is not working for me. Any idea what might be causing this?
Give permissions to cache directory with bash command:
sudo chmod -R a+rw /path/to/cache_directory/
I get the error in the title when I try to run composer require "illuminate/html":"5.0.*" in my terminal (Git Bash) under my current project file path. Even if I type something like composer -v I get the same error.
I've even tried reinstalling composer and it installs fine but the commands still don't work.
In the PhpSTORM terminal, running the same commands gives this error: 'composer' is not recognized as an internal or external command, operable program or bath file.
I have VirtualBox, Vagrant and Laravel all installed correctly with Composer (I know it's all good because my code is great and works fine when trying it live and what not)... unless I'm missing something here (Laravel noob).
Why is this happening?
If you installed composer outside your virtual box (in your host system) and you want to use it without ssh into your vagrant box:
Make sure you add composers directory to your PATH. Then close your current terminal and reload a new one. Closing the terminal is necessary to reload the PATH.
The error sh.exe": composer: command not found indicates that the composer is not found in the current folder or the PATH.
Found out why I was getting the error: forgot to ssh.
The fix was this: vagrant ssh in the terminal.
I am trying to install Laravel for first time. I installed it on my desktop with the following composer command
composer create-project laravel/laravel laravel-app
The command completed successfully without any error but with some messages like
symfony/var-dumper suggests installing ext-symfony_debug ()
symfony/translation suggests installing symfony/config ()
I now did chmod -R 777 larvel-app to make whole folder writable by everyone. I now started php server with following command
cd laravel-app
php artisan serve
and it gave following message
Laravel development server started on http://localhost:8000
When viewed from web browser in address http://localhost:8000, there is nothing, only blank page. When I browse this address, the server seems to quit.
I have following environment:
OSX Mavericks;
MAMP with php 5.4.10 and apache2;
following extensions in php.ini file
extension=imap.so
extension=yaz.so
extension=mcrypt.so
extension=gettext.so
extension=pgsql.so
extension=pdo_pgsql.so
extension=pdo_mysql.so
;;;;;Following are added by me ;;;;no error when starting server
extension=openssl.so
extension=mbstring.so
When I run which php from command line, I get following.
/Applications/MAMP/bin/php/php5.4.10/bin/php
When I tried to run this in mamp ie localhost:8888, it gave 500 internal server error.
Please suggest me, where I might have made mistake.
As a OSX user i strongly recommend you to use Laravel Homestead to develop your applications.
http://laravel.com/docs/5.0/homestead
You only need to install:
Virtualbox
Vagrant
I have my projects in ~/code folder, so everytime i create a new project, i just:
Add project test domain to my local host file (my-project.app pointing to localhost 127.0.0.1)
ssh into the homestead virtualmachine (homestead ssh)
run built in serve command (serve my-project.app /path/to/project/public)
VoilĂ
The most common reason for this is that the web server process does not have write access to the storage folder and its subfolders.
Set the permissions on the storage folder so that the web server can create files.
You don't have to use php serve, mamp does that for you. Make sure you point your directory to public folder. You can also use custom domain for each of your projects.
Also for Mac there is laravel valet. Easy to get started with many php projects.
I think you should move your Laravel Application to
/Applications/MAMP/htdocs/
and then you can access it on
http://localhost:8888/laravel-app