How do I fix this symfony config.php permission error? - php

I am trying to set up symfony. I am running ubuntu, I have apache2, phpmyadmin and phpstorm installed. I am getting this error under config.php of my project:
MAJOR PROBLEMS Major problems have been detected and must be fixed
before continuing: Change the permissions of either "app/cache/" or
"var/cache/" directory so that the web server can write into it.
Change the permissions of either "app/logs/" or "var/logs/" directory
so that the web server can write into it.
so I went to /var
I tried a few things:
sudo thunar and then changed all the permissions to writeable. This didn't work and the permissions changed right after.
I went on this site, it says to use certain commands to fix permissions: sudo chmod 754 /var/cache and sudo chmod 754 /var/log and sudo chmod -R 775 /var/cache and sudo chmod -R 775 /var/log
This also did not work
I should also note that I have cleared my cache and restarted apache2.

Glad you figure it out by your self.
In any case you can read more about it here: Setting up Permissions / Symfony2
Let me know. Ciao!

I figured it out. The cache and log are within the app themselves. This did not make much sense to me initially considering that the permissions of the folder they are in (the root, the www folder) had already had all their permissions set appropriately. All I did was set chmod -R 755 on those folders IN my app.

Related

Laravel root permission messed up

I have this Laravel project on my Ubuntu machine, and i accidentally gave chmod -R 777 to Ubuntu root. I did manage to cancel it, but it was to late. Now, like half of my root is green.
I have nothing useful on this machine except that Laravel project, and I have no problem with re-installing it. Is there a way to rebuild it? If not, when i backup my project, how to give it normal permission?
I've been through this before
Just run
sudo chmod 0644 -R * in your application's root directory
it will set the default permission level to -rw-r--r-- (0644). As new laravel application comes with this permission level.
and you need to give write permission to storage folder and its files so run
sudo chmod 0755 storage and sudo chmod 0755 storage/* -R
You are good to go now. and for more about file and its permission level, I would recommend you to go through this https://askubuntu.com/questions/638796/what-is-meaning-of-755-permissions-in-samba-share it will help.
When you reinstall the project it will gain the regular permissions. Remember that you only have to give 777 permissions to the "storage" folder.
And as far as I know, there is no way to set your Ubuntu files as they were before.
Just change and update permissions of public/ folder inside your Laravel app/ folder to 0775, and then change permissions of files inside public_html/ folder to 0644. Also what is worth of noticing is user:group. What server and how do you run PHP handler?

phpMyAdmin "Cannot load or save configuration"

I have been trying to setup phpMyAdmin on a macbook pro running yosemite 10.10.2. I have created a config folder in phpmyadmin and have given it the permissions required:
chmod o+wr ~/Sites/phpmyadmin/config
However, when I then go onto "localhost/phpmyadmin/setup" I get an error:
Cannot load or save configuration
Please create web server writable folder config in phpMyAdmin top level
directory as described in documentation. Otherwise you will be only able to
download or display it.
(I have tried attaching an image, but can't due to my reputation points)
I have tried resetting the permissions, tried deleting and recreating the folder. Tried redownloading the phpmyadmin zip but nothing seems to work.
Could anyone kindly advise me what I am doing wrong and how I am best placed to solve this issue?
I have had similar issue on my Ubuntu 16.04. I made a research and in the end I found a resolution of the issue. Maybe my case solution will help somebody else.
Background: For security reasons I have non privileged user and group apache:apache (sudo groupadd apache | useradd -g apache apache). They are preset by directives (User apache; Group apache) in /etc/apache2/apache2.conf. This user apache:apache owns Apache2 main directory (sudo chown -R apache:apache /etc/apache2) and some other files, for example: sudo chown -R apache:apache/etc/phpmyadmin/htpasswd.setup
In this manual: http://docs.phpmyadmin.net/en/latest/setup.html - I found that...
Debian and Ubuntu have changed way how setup is enabled and disabled,
in a way that single command has to be executed for either of these.
To allow editing configuration invoke:
/usr/sbin/pma-configure
To block editing configuration invoke:
/usr/sbin/pma-secure
Note! In the content of the two files listed above we talk about /var/lib/phpmyadmin/config.inc.php instead of /etc/phpmyadmin/config/config.inc.php. It was the key.
In my case I was modified the content of these scripts (see below) and now I can use localhost/phpmyadmin/setup properly.
/usr/sbin/pma-configure:
#!/bin/sh
echo "Unsecuring phpMyAdmin installation..."
echo "Setup script can now write to the configuration file."
echo
echo "Do not forget to run /usr/sbin/pma-secure after configuring,"
echo "otherwise your installation might be at risk of attack."
sudo sudo chown -R apache:apache /var/lib/phpmyadmin/config.inc.php
chmod 0660 /var/lib/phpmyadmin/config.inc.php
/usr/sbin/pma-secure:
#!/bin/sh
echo "Securing phpMyAdmin installation..."
echo "Setup script won't be able to write configuration."
sudo sudo chown -R root:root /var/lib/phpmyadmin/config.inc.php
chmod 0640 /var/lib/phpmyadmin/config.inc.php
I was able to use phpMyAdmin in my ~/Sites directory and remove the warning by giving the config folder writable access as such:
chmod 756 ~/Sites/phpmyadmin/config
Does it work if you try setting up PHPMyAdmin in system root versus user root? On OSX that server web root should be under /Library/WebServer/Documents?
I used this guide when I set mine up, and it works fine, although I did not use Sites as my root.
http://www.dingendoen.com/osx-installs-configuration-examples/install-apache-mysql-php-on-osx-yosemite/
For local development, changing permissions worked for an OSX Sierra install:
sudo chown -R _www:_www ~/Sites/phpmyadmin

Setting up Laravel, getting PDO and permission problems

So on my linux AWS instance, I am trying to install a laravel application and am running into an awful amount of permission problems.
By default, when I cloned my project into var/www/, the owner was Root. I changed the owner to apache, and added ec2-user to apache. From what I've read, this seems correct.
From there, I tried to run php composer.phar install, which resulted in a permissions error unless I ran it sudo, and then the error was that "Class 'PDO' not found in /var/www/Mumble/app/config/database.php".
So from there, it looked like PDO wasn't installed, so I used yum to install it, which got me the typical laravel error log, but it is now saying "could not find driver". Looking at php info, pdo is configured for mysqli. Could that be my problem? Does anybody know of some places I could look for resources?
First things first, the latest version of laravel is 4.3, compatible with PHP >= 5.4 (Source: Laravel Installation).
The bad news is, the yum package of apache on AWS comes with PHP 5.3. Check your php version using php phpinfo() in your ssh console.
If you have the proper PHP version, you will have to make sure PHP is running underneath the user apache.
Go to /etc/php.ini and search for the parameter user=. Make sure it says user=apache, and group=apache.
If all of this checks out, your final step is to make sure that your /app/storage directories are on a 777 permission with owner being apache. Only laravel uses these for internal purposes, so it's alright.
I suspect you need to give the permission to access, is it accessible the /var/www directory?
if not try this,
sudo chmod -R 777 /var/www
for secure permission use 775 for the directories.
perhaps permission you need to set:
# Set group to www-data
sudo chgrp www-data /var/www
# Make it writable for the group
sudo chmod 775 /var/www
# Set GID to www-data for all sub-folders
sudo chmod g+s /var/www
# Add your username to www-data group
sudo usermod -a -G www-data username
# Finally change ownership to username
sudo chown username /var/www/
# Your account shouldn't have any more permission issues
Note: please read about the file permission before you go further .

file_put_contents(meta/services.json): failed to open stream: Permission denied

I am new to Laravel. I was trying to open http://localhost/test/public/ and I got
Error in exception handler.
I googled around and changed the permission of storage directory using chmod -R 777 app/storage but to no avail.
I changed debug=>true in app.php and visited the page and got Error in exception handler:
The stream or file "/var/www/html/test/app/storage/logs/laravel.log"
could not be opened: failed to open stream: Permission denied in
/var/www/html/test/bootstrap/compiled.php:8423
Then I changed the permissions of storage directory using the command chmod -R 644 app/storage and the 'Error in exception handler' error was gone and a page is loaded. But in there I am getting this:
file_put_contents(/var/www/html/laravel/app/storage/meta/services.json):
failed to open stream: Permission denied
Suggestion from vsmoraes worked for me:
Laravel >= 5.4
php artisan cache:clear
chmod -R 775 storage/
composer dump-autoload
Laravel < 5.4
php artisan cache:clear
chmod -R 775 app/storage
composer dump-autoload
For those facing this problem with Laravel 5, this is a permission issue caused by different users trying to write at the same log file within the storage/logs folder with different permissions.
What happens is your Laravel config probably is setup to log errors daily and therefore your web server (Apache/nginx) might create this file under a default user depending on your environment it can be something like _www on OSX or www-data on *NIX systems, then the issue comes when you might have run some artisan commands and got some errors, so the artisan will write this file but with a different user because PHP on terminal is executed by a different user actually your login user, you can check it out by running this command:
php -i | grep USER
If your login user created that log file your web server you will not be able to write errors in it and vice-versa because Laravel writes log files with 655 permissions by default which only allows the owner to write in it.
To fix this temporary you have to manually give permissions for the group 664 to this file so both your login user and web server user can write to that log file.
To avoid this issue permanently you may want to setup a proper permissions when a new file is create within the storage/logs directory by inheriting the permissions from the directory this answer https://unix.stackexchange.com/a/115632 can help you to tackle with that.
You should not give 777 permissions. It's a security risk.
To Ubuntu users, in Laravel 5, I sugest to change owner for directory storage recursively:
Try the follow:
sudo chown -R www-data:www-data storage
In Ubuntu based systems, www-data is apache user.
For everyone using Laravel 5, Homestead and Mac try this:
mkdir storage/framework/views
some times SELINUX caused this problem;
you can disable selinux with this command.
sudo setenforce 0
NEVER GIVE IT PERMISSION 777!
go to the directory of the laravel project on your terminal and write:
sudo chown -R your-user:www-data /path/to/your/laravel/project/
sudo find /same/path/ -type f -exec chmod 664 {} \;
sudo find /same/path/ -type d -exec chmod 775 {} \;
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
This way you're making your user the owner and giving privileges:
1 Execute, 2 Write, 4 Read
1+2+4 = 7 means (rwx)
2+4 = 6 means (rw)
finally, for the storage access, ug+rwx means you're giving the user and group a 7
Problem solved
php artisan cache:clear
sudo chmod -R 777 vendor storage
this enables the write permission to app , framework, logs Hope this will Help
For vagrant users, the solution is:
(in vagrant) php artisan cache:clear
(outside of vagrant) chmod -R 777 app/storage
(in vagrant) composer dump-autoload
Making sure you chmod in your local environment and not inside vagrant is important here!
Try again with chmod -R 755 /var/www/html/test/app/storage. Use with sudo for Operation not permitted in chmod. Use Check owner permission if still having the error.
As per Laravel 5.4 which is the latest as I am writing this, if you have any problem like this, you ned to change the permission.
DO NOT LISTEN TO ANYONE WHO TELLS YOU TO SET 777 FOR ANY DIRECTORY.
It has a security issue.
Change the permission of storage folder like this
sudo chmod -R 775 storage
Change bootstrap folder permission like this
sudo chmod -R 775 bootstrap/cache
Now please make sure that you're executing both commands from your application directory. You won't face problems in future regarding permission. 775 doesn't compromise any security of your machine.
Suggest the correct permission, if for Apache,
sudo chown -R apache:apache apppath/app/storage
FOR ANYONE RUNNING AN OS WITH SELINUX: The correct way of allowing httpd to write to the laravel storage folder is:
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/path/to/www/storage(/.*)?'
Then to apply the changes immediately:
sudo restorecon -F -r '/path/to/www/storage'
SELinux can be a pain to deal with, but if it's present then I'd STRONGLY ADVISE you learn it rather than bypassing it entirely.
If you have Laravel 5 and looking permanent solution , applicable both php artisan command line usage and Apache server use this:
sudo chmod -R 777 vendor storage
echo "umask 000" | sudo tee -a /etc/resolv.conf
sudo service apache2 restart
See detailed explanation here.
I had the same issue and the below steps helped me fix the issue.
Find out the apache user - created a test.php file in the public folder with the code
<?php echo exec('whoami'); ?>
And run the file from the web browser. It would give the apache user. In my case, it is ec2-user as I was using the aws with cronjob installed in /etc/cron.d/. It could be different user for others.
Run the below command on the command line.
sudo chown -R ec2-user:<usergroup> /app-path/public
You need to identify and use the right "user" and "usergroup" here.
I had the same problem but in the views directory:
file_put_contents(/var/www/app/storage/framework/views/237ecf97ac8c3cea6973b0b09f1ad97256b9079c.php): failed to open stream: Permission denied
And I solved it cleaning the views cache directory with the following artisan command:
php artisan view:clear
Xampp for use:
cd /Applications/XAMPP/htdocs
chmod -R 775 test/app/storage
From Setting Up Laravel 4.x on Mac OSX 10.8+ with XAMPP
Any time I change app.php I get a permission denied writing bootstrap/cache/services.json so I did this to fix it:
chmod -R 777 bootstrap/cache/
rm storage/logs/laravel.log
solved this for me
Setting permission to 777 is definitely terrible idea!
... but
If you are getting permission error connected with "storage" folder that's what worked for me:
1) Set "storage" and its subfolders permission to 777 with
sudo chmod -R 777 storage/
2) In browser go to laravel home page laravel/public/ (laravel will create necessary initial storage files)
3) Return safe 775 permission to storage and its subfolders
sudo chmod -R 775 storage/
If using laradock, try chown -R laradock:www-data ./storage in your workspace container
In my case solution was to change permission to app/storage/framework/views and app/storage/logs directories.
After a lot of trial and error with directory permissions I ended up with an epiphany...there was no space left on the disk's partition. Just wanted to share to make sure nobody else is stupid enough to keep looking for the solution in the wrong direction.
In Linux you can use df -h to check your disk size and free space.
This issue actually caused by different users who wants to write/read file but denied cause different ownership. maybe you as 'root' installed laravel before then you login into your site as 'laravel' user where 'laravel' the default ownership, so this is the actually real issue here. So when user 'laravel' want to read/write all file in disk as default, to be denied, cause that file has ownership by 'root'.
To solving this problem you can follow like this:
sudo chown -hR your-user-name /root /nameforlder
or in my case
sudo chown -hR igmcoid /root /sublaravel
Footnote:
root as name first ownership who installed before
your-user-name as the default ownership who actually write/read in site.
namefolder as name folder that want you change the ownership.
If you use Linux or Mac, even you can also run in ssh terminal. You can use terminal for run this command,
php artisan cache:clear
sudo chmod -R 777 storage
composer dump-autoload
If you are using windows, you can run using git bash.
php artisan cache:clear
chmod -R 777 storage
composer dump-autoload
You can download git form https://git-scm.com/downloads.
If anyone else runs into a similar issue with fopen file permissions error, but is wise enough not to blindly chmod 777 here is my suggestion.
Check the command you are using for permissions that apache needs:
fopen('filepath/filename.pdf', 'r');
The 'r' means open for read only, and if you aren't editing the file, this is what you should have it set as. This means apache/www-data needs at least read permission on that file, which if the file is created through laravel it will have read permission already.
If for any reason you have to write to the file:
fopen('filepath/filename.pdf', 'r+');
Then make sure apache also has permissions to write to the file.
http://php.net/manual/en/function.fopen.php
Just start your server using artisian
php artisian serve
Then access your project from the specified URL:
I have the same issue when running vagrant on mac. solved the problem by changing the user of Apache server in https.conf file:
# check user for php
[vagrant] ubuntu ~ $ php -i | grep USER
USER => ubuntu
$_SERVER['USER'] => ubuntu
[vagrant] ubuntu ~ $
Run apache under php user instead of user daemon to resolve file access issue with php
# change default apache user from daemon to php user
sudo sed -i 's/User daemon/User ubuntu/g' /opt/lampp/etc/httpd.conf
sudo sed -i 's/Group daemon/Group ubuntu/g' /opt/lampp/etc/httpd.conf
now, php created cache file can be read and edit by apache without showing any access permission error.
I got same errors in my project...
But found out that I forgot to put enctype in my form.
<form method="#" action="#" enctype="multipart/form-data">
Hopes it helps somewhere somehow...
While working on Windows 10 with Laragon and Laravel 4, it seemed to me there was no way to change the permissions manually, since executing chmod-commands in the Laragon-in-built-terminal had no effect.
However, it was possible in this terminal to go to the storage folder and manually add the desired folders like this:
cd app/storage
mkdir cache
mkdir meta
mkdir views
mkdir sessions
The cd-command in the terminal brings you to the folder (you might need to adjust this path to suit your file structure).
The mkdir-command will create the directory with the given name.
I did not have the opportunity to test this approach in Laravel 5, but I expect that a similar approach should work.
Of course there might be a better way, but at least this was a reasonable workaround for my situation (fixing the error: file_put_contents(/var/www/html/laravel/app/storage/meta/services.json): failed to open stream).
First, delete the storage folder then again create the storage folder.
Inside storage folder create a new folder name as framework.
Inside framework folder create three folders name as cache, sessions and views.
I have solved my problem by doing this.

Unpacking the update... Could not create directory. Wordpress

When I instal nextgen-gallery plugins. This error message appears
Downloading update from https://downloads.wordpress.org/plugin/nextgen-gallery.zip…
Unpacking the update…
Could not create directory.
How can I fix this problem ?
This is a permissions issue. Ensure the directory is writable by apache. Plugins are unpacked into the wp-content/plugins directory, so I would first attempt writing to the directory as apache:
sudo -u apache touch /path/to/wp-content/plugins/test.txt
Set permissions accordingly to correct the issue. You can read about permissions here: https://www.pluralsight.com/blog/it-ops/linux-file-permissions
You can read about the correct file permission scheme for Wordpress here: https://wordpress.org/support/article/changing-file-permissions/
#skrilled and #knutole's answer was great but I found that when attempting to fix the issue on the plugins folder, everything was ok and the answer did not work for me.
If anyone else has this issue, try looking at the upgrades folder also. This folder (from what I can see) is used as a folder to store temporary files for when WP upgrades or plugin updates are being ran.
If you simply receive the message stating 'Could not create directory' and there is no path specified, it could actually be talking about the upgrades folder.
Most likely, if you have configured it correctly, the http server associated to your wordpress site belongs to the group www-data. That's how one should configure it correctly.
Try members www-data and ps aux | grep www-data to be sure. In the latter command you should see on the last columns either nginx or apache.
In this case, you just need to set that group to the directory
sudo chgrp -R www-data <your_wordpress_root_dir>/
and then add full group permissions to such directory
sudo chmod -R g+rwx <your_wordpress_root_dir>/
Now it works perfectly :)
for nginx people
if you have php-fpm installed you have to tell it that its user and group is nginx. /etc/php-fpm.d/www.conf . find user which is assigned to apache by default and change it to nginx. also do it for group. then run this command :
sudo service php-fpm restart
also inside of your wordpress directory execute these commands
sudo chown nginx:nginx * -R
sudo usermod -a -G nginx username
change username into what your current username is.
yet you have to apply propper permissions.
run these commands inside your wordpress directory
sudo find . -type f -exec chmod 664 {} +
sudo find . -type d -exec chmod 775 {} +
If you are using vsftpd as your FTP server and have enabled passive connections, you need to add pasv_promiscuous=YES to /etc/vsftpd/vsftpd.conf.
I was having a similar issue. It started with me trying to update a plugin on a migrated WP install. I didn't get it, all my permissions were EXACTLY the same as the old server. In my situation, I started to see that not much was working properly. I couldn't install/delete plugins or themes as well as uploading media would error out. Then I found the fix via some research.
If you are still having this issue, and changing permissions DID NOT fix the problem try this:
Go in to your hosting control panel and find your hosting settings, wherever you can edit your scripting settings. In Plesk (as in my example), this would be under Websites & Domains. Click on your domain name at the bottom. On the next screen, where it says "PHP support (run as..." change the dropdown from "Apache module" over to "FastCGI application". Everything should be fixed up now!
(Re)setting the permissions via ftp didn't make a difference for me either. There is no SSH available, so I had to log in the control panel (directadmin in my case), the File Manager where I could "Reset Owner" to "File ownership reset" the /wp-contents directory.
I'm running Nginx with Wordpress. I deleted the upgrade folder in wp-content and then ran the upgrade from the wordpress GUI again. I noted the linux user for the upgrade folder created was www-data. I then did a {sudo chmod -R www-data:www-data .} Ran the upgrade again from the GUI and it worked.
Probably need to change the permissions on most of the folders so they can't be modified by www-data but I'll figure that out tomorrow.
A permission issue, make sure apache (www-data) has write permissions.
All the above is great, but I think you missed the simplest issue. Your website is using more space than it has allotted, and therefore it is broke. Wordpress makes more files as is in use. If you are on the margin of going over, a simple overnight issue where you did nothing is possible. Go to bed, everything fine. In the morning website is broke.
I own my websites so I go into the reseller part of Hostmonster or Hostgator (I have sites on both hosting platforms) and I reallocate more space and the problem goes away usually. Try that first, or look into it before messing around with permissions. If you changed a permission and the issue came up, could be permissions, otherwise, check this first.
I had the same issue when I tried to install wp plugin(s). However, I managed to solve the problem with the following command:
sudo wp plugin install [plugin name] --allow-root

Categories