Symfony 2.3 Failed to remove file with php composer.phar update - php

I am following the guide on symblog: http://tutorial.symblog.co.uk/docs/doctrine-2-the-blog-model.html
I am trying to run: $ php composer.phar update after updating the composer.json but get the following error:
[Symfony\Component\Filesystem\Exception\IOException]
Failed to remove file
"/var/webroot/vhosts/mysite.co.uk/htdocs/Symfony/app/cache/dev_old/profiler/32/95/639532"
The permissions on this file is: 0644 were the owner is www-data and the group is sambashare which includes the user i am ssh'd in as (john).
As this is running php from command line, is php being run as 'john' thus in the group of the file wanting to be removed but not the user?
The runtime error at the end it:
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command.
After a bit of searching some people have just said clear this cache manually.. but how can i fix this issue at the root so i do not have to do this manually?
Thanks,
John

This is a common problem with Symfony2 you should run your commands under the apache2 user in most cases this is the www-data user.
You can switch to the www-data user with
su www-data -s /bin/bash
then you should set 755 to the cache folder that the www-data has enough permissions. There is a goof explanation in the Symfony2 documentation about that.
http://symfony.com/doc/current/book/installation.html
Here in the documentation is a section "Setting up Permissions" there you can see how you can configure ACLs and other user permissions.

The problem is PHP console commands use php-cli running under the current user as opposed to the web server's user (usually www-data), leading to permission errors.
The Symfony book explains several ways to avoid the issue.

Related

Which user:group for my website root folder to be able to run composer update?

I have a Pimcore project root folder which is recursively owned by www-data:www-data.
If I use sudo composer update, everything works fine, but many files will be set with root owner, which might cause further problems.
If I use sudo -u www-data composer update, I get a RuntimeException:
file_get_contents(/home/me/.composer/config.json): failed to open stream: Permission denied
If I use sudo -u me composer update, at some point, I get another RuntimeException:
An error occurred when executing the "'cache:clear --no-warmup'" command:
Fatal error: Uncaught RuntimeException: Unable to write in the cache directory (/var/www/html/pimcore/skeleton/var/cache/dev)
If I change ownership of the root folder to me:www-data, then I get RuntimeException error because some folders are not writable for the group www-data, like this folder /var/www/html/pimcore/skeleton/var/cache/dev/twig which permissions are set to drwxr-xr-x.
By which user:group should my root folder owned by and how should I run composer update?
It's better if you do not run composer as root.
Besides that, it's not particularly important which user do you use to run composer. As long as it has enough permissions to write on your project files (typically only on vendor, bin, var, and public; although it might need to write on different directories depending on the type of project.
Since you already run composer as root, it seems that /home/me/.composer/config.json has been created with root ownership, which is bringing you additional problems. Just sudo chown that file so it can be read by your own user.
Set the project so all the files belong to your (non-elevated privileges) user, and after running install fix the permissions as recommended in the documentation:
Pimcore: File Permissions
Symfony

Laravel 5 not getting any error logs

I installed Laravel 5 on a new VPS, I was running everything fine but I noticed I wasn't getting any Laravel errors the system would only fire a server 500 error at me which is no help when debugging my code.
When I looked in the laravel storage/log it was empty which was strange because I had set the correct file permissions of 777.
So how do I get laravel logs? Why aren't they being written to my storage/log file.
If you've set your file permissions correctly on the /storage file directory and you're running on a VPS not shared hosting you might want to check your apache log, inside var/log/apache2/error.log
Here you might just see a line that read something along the lines of /var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
Well this is strange because you have the correct file permissions...
Let's start by SSH'ing into your VPS head to the directory where laravel is installed normally cd /var/www/html
In here if you run ls -l You should get some results similar to this image below:
Notice how we've been accessing the site as the root user, this is our problem and we can confirm this by running ps aux | grep apache2
You can see here apache2 is running as the user www-data, which is normal for apache. Which means when our laravel installation trys to move files either using ->move() or just trying to write the log file it fails as the www-data user doesn't have permission. So you can change to this www-data user by running: chown -R www-data:www-data * (shorthand for same user/group chown -R www-data. *)
Now if you run ls -l in your www/html directory you should see root user changed to www-data:
This means were now editing the files as the www-data user which has permission, so any changes you make via SFTP should reflect this user change. Fixed!
Edit - This is the first time I answered my own question hopefully it's okay.

New Laravel Project Throwing 500 Error: require(): Failed opening required autoload.php

I trying to learn laravel and I am attempting to set it up on my server.
I have meticulously followed all the instructions in this tutorial while changing some variables based on the names of my own directories:
http://davidmyers.name/post/laravel-on-digital-ocean
The 500 error only is thrown when I visit the laravel project's public folder. When I attempt to visit any other page such as PHPMyAdmin or any other PHP or HTML page, the page pulls up just fine.
Is there anything I could be missing that is not included in the tutorial that I referenced? I double checked that I am following all the steps correctly.
Also, running composer update in the directory throws this error:
[RuntimeException]
Error Output: PHP Warning: require(/var/www/html/testproj/bootstrap/../vendor/autoload.php): failed to open stream: No
such file or directory in /var/www/html/testproj/bootstrap/autoload.php on line 17
PHP Fatal error: require(): Failed opening required '/var/www/html/testproj/bootstrap/../vendor/autoload.php' (include
_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/testproj/bootstrap/autoload.php on line 17
I found this related stackoverflow article:
Laravel 5 Failed opening required bootstrap/../vendor/autoload.php
but the solution did not work for me, since my phpinfo() shows that OpenSSL is enabled.
The problem is that the server does not have access to those locations.
Run the following commands
sudo chmod 755 -R "your project name"
and then
chmod -R o+w "your project name" /storage
if it still doesn't work try running:
sudo chmod 775-R "your project name"
sudo chmod 775-R "your project name"/storage
or
sudo chmod 777-R "your project name"
sudo chmod 777-R "your project name"/storage
Have you run composer install ? This should automatically run php artisan optimize after install, which I believe is the command to create the file in question.
You must install dependencies by composer using:
composer install
and then give right permission to storage directory:
chmod 777 -R storage
or
sudo chmod 777 -R storage
It turns out that I was doing everything right, but when I went to run composer install I didn't see that it was throwing an installation error due to my server not having enough memory. Increasing my server's memory fixed the problem.
There are 2 things to consider,
1. Web server throwing 500 error (as if text and font were from Chrome) or
2. The application is showing 500 error (with beautiful image and text)
Case 1: you probably need to install composer
sudo composer install
Case 2: Check appropriate permission on storage/ (as suggested on other answers) and check if you have .env file. if not copy .env.example and rename to .env and you also need to generate application key.
sudo php artisan key:generate
PS: You may be in this situation mostly if you have used git to deploy your code on server and your development machine is different. This answer is based on the scenario which I faced and how it was solved.

Clone Laravel 4 Project - Permission Problems

I cloned a project on my local machine and used it as a starting point for another project. I've been plagued by permission problems ever since.
Whenever I clear the cache, I notice that nothing happens. I get no error, but the cache doesn't in fact clear. Trying to manually delete the files is not allowed. Trying to change permissions on the files is not allowed.
$ chmod -R 777 app/storage
chmod: Unable to change file mode on app/storage/cache/14: Operation not permitted
The only thing that works is using sudo:
$ sudo chmod -R 777 app/storage
$ php artisan cache:clear
And this will only work for a single page load. All future attempts to clear that cache fail silently and again require the above procedure.
How can I fix this issue and get the permissions working properly again?
SOLUTION:
I made a change to my local Apache settings following this procedure:
http://paulmason.name/item/change-apache-user-group-in-lion-os-x
A final sudo chmod got me up and running.

php symfony2 installation cache permissions

I've downloaded 2.0.4... I can't get pass the "can't create cache directory" cause of permissions problem...
I've tried chmod 777 -R symfony
-- to all folders, still can't create cache dir
I've tried setfacl but it says unrecognized -m option....
My system does not support chmod +a
I've done chown -R myuser:apache symfony
-- still nothing
I've tried umask(0000) and umask(0002) in console.php/app_dev.php/app.php
-- still nothing
When I refresh the page to http://localhost/symfony/web/app_dev.php, I get a SElinux alert... is this causing something? I'm not sure... all symfony content is word writable.
I'm not sure if it's me... but it's driving me nuts, maybe I just should stop using symfony2.
I'm using Fedora 13.
It seems that you will need to switch SELinux to Permissive state. You can do so executing as root user:
setenforce 0
PHP's umask may have no effect when default apache umask is different.
Originally I used to use setfact, but this adds overhead for deployment.
What worked for me on ubuntu servers is:
Set default apache umask.
Edit /etc/apache2/envvars and add this line in the end of file:
umask 0002
Reload apache service
Add your deploy user to www-data group, add www-data to your deploy user group.
adduser www-data `whoami`
adduser `whoami` www-data
Logout or restart server for this to take effect.
Remove app/cache, app/logs dirs
Try to load page in browser, notice how app/cache dir is created by www-data user and has write group permission. Try to clear cache in console and verify that no errors occurred.
Remove app/cache, app/logs dirs
Run cache:clear, notice how app/cache dir is created by user deploy user and has write group permission. Try to load page in browser, and verify that no errors occurred.
Now you can forget about cache and logs permissions on this particular server for all subsequent projects.

Categories