Symfony Project, can't fixing file permissions - php

I regularly get file permissions errors when I try to update composer or to clear cache of my symfony project.
Yet my files are set correctly according to the doc of symfony : http://symfony.com/doc/current/setup/file_permissions.html
I'am under linux, Manjaro Budgie edition (last stable version)
server apache last version
For example :
composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
// Clearing the cache for the dev environment with debug true
[Symfony\Component\Filesystem\Exception\IOException]
Failed to remove file "/srv/http/PetitMur/var/cache/de~/annotations/1a/5b504d5c506c6174666f726d42756e646c655c456e746974795c41727469636c652474616773405b416e6e6f745d5d5b315d.doctrinecache.data": .
This file has this rights :
pierre $ la /srv/http/PetitMur/var/cache/de~/annotations...data
-rw-rw-r--+ 1 http http 234 29.09.2016 18:13 /srv/http/PetitMur/var/cache/de~/annotations...data
I know, this problem is recurrent. But I have already set the permission file according to the doc of symfony. Currently I have to run command on super user to make it work and this isn't normal.
You have an idea ?
edit :
php bin/symfony_requirements
Symfony Requirements Checker
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> PHP is using the following php.ini file:
/etc/php/php.ini
> Checking Symfony requirements:
.............................WW......
[OK]
Your system is ready to run Symfony projects
Optional recommendations to improve your setup
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* intl extension should be available
> Install and enable the intl extension (used for validators).
* a PHP accelerator should be installed
> Install and/or enable a PHP accelerator (highly recommended).
Note The command console could use a different php.ini file
~~~~ than the one used with your web server. To be on the
safe side, please check the requirements from your web
server using the web/config.php script.

I suspect permission and possibly user group settings may be incorrect.
Go into your Apache httpd.conf file to check the User/Group settings. You'll see lines like this:
User apache
Group apache
The above was from my system which is CentOS 6, and httpd.conf is under /etc/httpd/conf/ folder. Yours may be in a different location and may be the user httpd instead (check it).
Then set the proper user/group for your Symfony3 project:
sudo chown -R apache:apache /srv/http/PetitMur
The above command sets the user:group both to apache, you may have to use httpd
Now delete your old cache files & logs, since they may have been created before with the wrong user:
sudo rm -rf var/cache/*
sudo rm -rf var/logs/*
Then run the setfacl again, make sure you cut & paste (there is a capital X) and use the correct user (either apache or httpd):
$ sudo setfacl -R -m u:apache:rwX -m u:`whoami`:rwX var
$ sudo setfacl -dR -m u:apache:rwX -m u:`whoami`:rwX var
Then test out your system and see it the problem got fixed.

I have try this "sudo chown -R http:pierre Myproject" and for the moment this works for clear the cache but not for composer.

Related

yii2 not installing with correct permissions with composer

I am running windows 10 with the ubuntu subsystem installed as my localhost. I have composer installed on that and when I try to install the yii2 basic application it goes through the process correctly but when i open the yii2 basic application in my browser I get:
Failed to change permissions for directory "/mnt/c/Users/andre/zype/staff-tools/web/assets/89851207": chmod(): Operation not permitted
If I then change permissions on the yii2 installation file structure with
sudo chown -R www-data:www-data .
the application loads but the web/assets folders are missing so my application has no styling. I am unsure if this is a composer issue or a yii2 issue but it looks like permissions to me.
Try changing the permission of 'assets' folder most likely to 777 (all users can access this file)
your-project/web/assets
Well this solution works for Linux users. Will require to check for windows
Follow Steps
Step 1- Install Composer (I installed it through bash)
Step 2- Now in cmd use following command
composer create-project --prefer-dist yiisoft/yii2-app-basic yii2-basic-check
Output (Last Lines)-
chmod('runtime', 0777)...done.
chmod('web/assets', 0777)...done.
chmod('yii', 0755)...done.
Step 3 - Open "http://localhost/yii2-basic-check/web/" URL in browser.
It worked fine for me
Important: Windows Subsystem for Linux has many serious problems with file permission. So, I advise not to install Linux programs and it's files in Windows drives i.e. DRVFS (/mnt/c). Also as PHP frameworks need many files, it will be better if you install distributions in another internal NTFS drives other that C:\ drive.
Steps: Place/clone the required project files/repositories in current user's home folder e.g. /root, /home, /home/user. Do not place the files in C:\ drive aka. /mnt/c otherwise WSL will not follow their permissions correctly. Here is an example of the installation procedure from YiiFramework: The Definitive Guide to Yii 2.0.
Install required packages: sudo apt-get install php php-cli php-common php-mbstring php-xml php-zip zip unzip
Go to user folder: cd ~
Download composer: curl -sS https://getcomposer.org/installer | php
Install yii2-basic: ~/composer.phar create-project --prefer-dist yiisoft/yii2-app-basic basic
Go to project folder: cd ~/basic
Run PHP server: php yii serve
Open server in browser at localhost:8080 (default port 8080).

Composer: file_put_contents(./composer.json): failed to open stream: Permission denied

I'm trying to install Prestissimo to an Ubuntu 16.04 server, but that leads to an error:
$ composer global require "hirak/prestissimo:^0.3"
Changed current directory to /home/kramer65/.composer
[ErrorException]
file_put_contents(./composer.json): failed to open stream: Permission denied
require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] [<packages>]...
I'm logged in as user kramer65, so I wouldn't know why it can't write to my home folder. My normal reaction to a permission denied is to use sudo, but composer then always says:
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Any idea how I can solve this?
I had this problem to install laravel/lumen.
It can be resolved with the following command:
$ sudo chown -R "$(id -un)" "$(composer config --global home)"
What this command does: Execute as privileged user (root) the command to change file owner (not group) to the current user (by name) recursively to the COMPOSER_HOME directory.
As the user-name as well as the composer home directory can be different on each system, the following two commands are in use to obtain the ...
... username: id -un
... composer home directory: composer config --global home
This is an old question, and so a reader of the answer may want to become aware of the following:
Prestissimo was dedicated to be used with Composer 1
As of today, Composer 2 has been released which already didn't benefit from Prestissimo any longer.
But even further as of today, Composer 2.2 has been released which is a Long Term Support (LTS) version you should replace Composer 1 with immediatly if you deemed it to require Presstissimo in the past as it is in general and overall much more faster than Composer 1 ever was - with or without Prestissimo.
How to continue:
Remove Prestissmo from any of your systems.
Replace Composer 1 with Composer 2.2 on any of your systems.
Enjoy.
To resolve this, you should open up a terminal window and type this command:
sudo chown -R user ~/.composer (with user being your current user, in your case, kramer65)
After you have ran this command, you should have permission to run your composer global require command.
You may also need to remove the .composer file from the current directory, to do this open up a terminal window and type this command:
sudo rm -rf .composer
For me, in Ubuntu 18.04. I needed to chown inside ~/.config/composer/
E.g.
sudo chown -R $USER ~/.config/composer
Then global commands work.
In my case I don't have issues with ~/.composer.
So being inside Laravel app root folder, I did sudo chown -R $USER composer.lock and it was helpful.
I faced this issue as well but in my case, I was in wrong directory. Check the directory you are working
In my case, .composer was owned by root, so I did sudo rm -fr .composer and then my global require worked.
Be warned! You don't wanna use that command if you are not sure what you are doing.
In my case all the permissions were correct at all the locations manetioned in other answers here, but I was still getting this error.
Turned out there were some vendor directories that were owned by root. Composer writes composer.lock files all over the place when it's doing an update or install.
So solving my case - and this is specifically for a laravel sail container - all ownerships were switched to user sail in the project:
Enter the sail container as root:
vendor/bin/sail root-shell
Set the file ownership for all files in the project:
chown -R sail:sail /var/www/html
You may just want to do the vendor directory only as a first try:
chown -R sail:sail /var/www/html/vendor
The ownership was wrong after switching from a hand-rolled docker-compose.yaml setup to Laravel Sail, which IMO handles file ownership and permissions in a sensible way, separating root from the application user sail.
This might be super edge case, but if you are using Travis CI and taking advantage of caching, you might want to clear all cache and retry.
Fixed my issue when I was going from sudo to non sudo builds.
I was getting the same exception, but in my case I am using PowerShell to run commands
So, I fixed this with an instruction to unblock multiple files first.
PS C:\> dir C:\executable_file_Path\*PowerShell* | Unblock-File
and then use the following to load the package
& 'C:\path_to_executable\php.exe' "c:\path_to_composer_.phar_file\composer.phar "require desired/package
I was getting the same error when using it with WSL Windows 10. I used the following command to solve it:-
sudo chown -R $USER /home/<username>/.config/composer
I had same issue in windows version of composer that has installed in
C:\composer
When I was trying this command
C:\composer require aws/aws-sdk-php
then simply I got into composer installed folder and try it again
C:\composer>composer require aws/aws-sdk-php
the package installed quickly .
In my case I used sudo mkdir projectFolder to create folder. It was owned by root user and I was logged in using non root user.
So I changed the folder permission using command sudo chown mynonrootuser:mynonrootuser projectFolder and then it worked fine.
I was facing the same issue when I was running the composer require inside /var/www/html ,the default root folder of the apache web server and I was able to solve it by making the current user the owner of this html directory by
sudo chown -R $USER /var/www/html
But you definitely want to set the permissions
chmod 755 -R /var/www/html
There are 2 components to consider.
Composer wants you to run it as the logged in user. However, your webserver wants to have permissions over your application.
The solution is to add your user to the webserver group, then update the permissions of your application.
For Ubuntu running Apache webserver, use the following command to add yourself to the Apache group, replacing <username> with your username
sudo usermod -a -G www-data <username>
Now you need to update your permissions on your application. Navigate to the root folder of your application and use the following command
sudo chown -R $USER:www-data .
Composer now has the necessary permissions to pull in the packages you need and Apache has the necessary permissions to deliver your application.

Symfony2 NGINX Unable to create the cache directory

I know this may seem as a repeated question but so far I have 4 hours digging around unable to find a straight answer to this. I have setup a brand new CentOS 7 and I installed NGINX (https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7) + PHP 5.6 (https://webtatic.com/packages/php56/) and MariaDB.
Following the guides I was able to make the NGINX serve PHP files successfully.
I have a project in Symfony2 which I am trying to get in this server, my problem is when I try to open up http://server/web/app.php. I get the following error:
Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to create the cache directory (/usr/share/nginx/html/app/cache/prod) ' in ................
I read in the documentation (http://symfony.com/doc/current/book/installation.html) that I should work around my permissions so I was able to apply the following:
$ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
$ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
$ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
Since I have CentOS 7 from scratch that was the option that I was able to apply. However, I still have the same issue, after this approach these are the other options I've tried:
changed the owner for app/cache and app/logs to nginx:nginx
changed the permissions to 777 to the above folders
verified and re-verified that PHP is running under the nginx user, I had to change this in the www.conf
if I do ls -Al it shows that app/cache and app/logs are owned by nginx
restarted services after each single change
restarted the server completely
cleared the cache and performed warmup and still
Tried the umask option provided by symfony and still.
So after all these options I still get the same issue, to other people out there with this problem it's simply following the Symfony2 guidelines for applying the ACL and puff, done. But this is not the case.
What am I missing?
Ps: I double checked the permissions of the folder..and I am in the server as root.
Update 1
I re-installed CentOS 7 from scratch and followed https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7 and in combination with Symfony's suggestion for the configuration file and still I get the " Uncaught exception 'RuntimeException' with message 'Unable to create the cache directory" error
You might be running into SELinux issues, since CentOS 7 ships with SELinux running by default.
You can test by executing setenforce 0 to see if that solves the problem. If that works, you need to configure SELinux to allow the nginx user to write to the cache directory, and then re-enable SELinux. SELinux does provide some good security, so it would be best to figure out how to configure it properly, as opposed to turning it off completely.
You need to add a local custom rule (policy module), suppose you have your application under the /usr/share/nginx/www directory:
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/www/.+/app/(cache|logs)(/.*)?'
You need to restore the contexts for all the files in that dir:
restorecon -Rv /usr/share/nginx/www/your-app-dir
Change the group of the cache and logs directories and add permissions for the group:
chgrp -R apache /usr/share/nginx/www/your-app-dir/app/{cache,logs}
chmod -R 775 /usr/share/nginx/www/your-app-dir/app/{cache,logs}

How to install IonCube Loader on Amazon Linux x64 instance

I'm having trouble installing IonCube Loader on my Amazon Linux x64 instance.
I'm following these instructions below but the paths are way off and I can't seem to locate the right ones on my install.
For x64:
wget http://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
tar xfvz ioncube_loaders_lin_x86-64.tar.gz
Proceed as follows:
cp ioncube/ioncube_loader_lin_5.3.so /usr/lib/php5/20090626/ioncube.so
Now edit to match:
zend_extension = /usr/lib/php5/20090626/ioncube.so
nano /etc/php5/conf.d/ioncube.ini
First, there is no /usr/lib/php5/20090626/ folder. I changed these paths to /usr/lib64/php/modules and included the .so file in there.
However, I cannot seem to locate any ioncube.ini file to edit. Any help is appreciated...
Thank you!
For future readers sake, there is a difference between Amazon's Linux and other versions that most articles online refer to.
You can follow the first two steps above to get the installer, I like to use a temporary folder. Do this as root:
sudo -i
cd /tmp
wget http://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
tar xfvz ioncube_loaders_lin_x86-64.tar.gz
Copy the required extension to a slightly different folder under EC2 linux instances, and the loader wizard to your webroot:
cp ioncube/ioncube_loader_lin_5.4.so /usr/lib64/php/modules/ioncube.so
Create your ini file:
echo "zend_extension=/usr/lib64/php/modules/ioncube.so" > /etc/php.d/ioncube.ini
Reload Apache (if you're using it):
service httpd restart
I'm using NGINX and PHP-FPM, in this case you'd probably want to restart PHP-FPM as well as NGINX.
Lastly, use the loader wizard to test it by navigating to http://example.com/loader-wizard.php, and delete the temp files and loader wizard when finished:
rm -rf /tmp/ioncube*
rm /var/www/html/loader-wizard.php
I followed the instructions provided here in the first answer, making allowance for the fact that I'm runnning PHP 5.6:
sudo cp ioncube_loader_lin_5.6.so /usr/lib64/php/5.6/modules/ioncube.so
echo "zend_extension=/usr/lib64/php/5.6/modules/ioncube.so" > /etc/php.d/ioncube.ini
However, when restarting Apache, I found that it started then failed immediately. The Apache log gave me this error:
PHP Fatal error: [ionCube Loader] The Loader must appear as the first entry in the php.ini file in Unknown on line 0
I changed the name of the file from ioncube.so to 00-ioncube.so and restarted Apache. This solved the problem by making this file load before the other modules.

installing PHP module from Elastic Beanstalk

I am trying to configure my AWS Elastic Beanstalk to work with mongo, all I need to do is install the mongo driver for PHP and update the php.ini file
To do this, usually I would ssh into the EC2 and run:
sudo pecl install mongo
But this would require using a custom AMI which isnt the best way to go.
It is better to use config files to install the software required onto the standard AMI.
So to do this, I have done the following:
created directory .ebextensions
created file mongo.config
in it I have put the following:
packages:
pecl: install mongo
However upon deployment, I get the following error:
"option_settings" in one of the configuration files failed validation. More details to follow.
and
'null' values are not allowed in templates
So I am wondering how this config file needs to be laid out in order to install the mongo extension?
I have read the info here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
but I am not quite understanding how to do this specific task
Help would be appreciated , thanks! :)
pecl is not a valid package manager on Amazon Linux and therefore cannot be used under the packages key of an .ebextensions config.
To install a PECL package it is enough to add a single command under the commands key. To avoid that Beanstalk tries to install the extension twice on follow-up deployments add a PHP console command to the test key that checks if the extension is already installed:
commands:
install_mongo_driver:
command: pecl install mongo
test: "php -r \"exit(extension_loaded('mongo') ? 1 : 0);\""
If the test result is true, i.e. exit(0), then the command gets executed - otherwise not. Please note that a exit code of 0 means "No errors" in a shell context.
See also the description at http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-commands.
I have figured it out and thought I would share what I found. Thanks to Hudku (http://blog.hudku.com/2013/02/innocuous-looking-evil-devil.html#elastic-beanstalk.config) for the excellent article:
1) Create myapp.config
2) enter the following into it
packages:
yum:
dos2unix: []
container_commands:
01-command:
command: rm -rf /myapp/ebextensions
02-command:
command: mkdir -p /myapp/ebextensions
03-command:
command: cp -R .ebextensions/* /myapp/ebextensions/
04-command:
command: dos2unix -k /myapp/ebextensions/mongo.sh
05-command:
command: chmod 700 /myapp/ebextensions/mongo.sh
06-command:
command: bash /myapp/ebextensions/mongo.sh
Then create mongo.sh file and put in it something like:
#!/bin/bash
if [ ! -f /mongostatus.txt ];
then
pecl install mongo
echo "mongo extension installed" > /mongostatus.txt
apachectl restart
fi
This will install mongo php extension and restart apache so the install takes affect.
I just accomplished the same thing thanks to the answer above, and figured out it can be done with less lines and less files for those interested...
# ~/project/.ebextensions/project.config
# Logger messages can be viewed in /var/log/messages
files:
"/tmp/test.sh":
content: |
# This file will be created and can then
# be executed by a command call below.
logger TEST FILE CALLED
commands:
01-command:
command: logger CALLING TEST FILE; sh /tmp/test.sh;

Categories