I cannot seem to allow permissions in vagrant. I am attempting to run importbuddy.php in order to migrate a WordPress instance. I get the following error.
file_put_contents(/path/): failed to open stream: Permission denied
I have setup permissions to 777 on the www directory, but that changes nothing. Any idea on how to fix this?
While recursively setting folder and file permissions to 777 should fix your problem (instructions for doing so here), the root of this is probably an issue with the ownership of the files and folders.
The owner of shared folders is usually 'vagrant' but the server itself (if you're using Ubuntu) runs as user and group 'www-data'. You can view the user/group of your files by sshing into your VM (vagrant ssh), navigating to the directory in question and entering ls -l in your console.
If you're running apache, then you can update the user to 'vagrant' by editing the following file (/etc/apache2/envvars) like below:
Find this section
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
And change it to
export APACHE_RUN_USER=vagrant
export APACHE_RUN_GROUP=vagrant
Afterward just be sure to restart apache (with this command sudo service apache2 restart) and the file permission errors should be fixed
Related
Everytime I use file_put_contents in my PHP script on DigitalOcean's LAMP server, I get this error message:
file_put_contents(test_digitalocean.json): failed to open stream:
Permission denied in /var/www/html/test_digitalocean.php
How can I properly set permissions?
I access my scripts by entering the server's IP address followed by /test_digitalocean.php into the browser.
All scripts are uploaded to /var/www/html/
If I look at www folder from FileZilla, I can see that the permissions are 775 with the owner and group both as www-data.
Your web server needs to have write permissions on the file. Apache on any linux system runs as some particular user. You can find out which user by putting this script on your server and accessing it:
<?php
passthru("whoami");
On Debian/Ubuntu, this user is www-data. So the directory or file you'd want to write would need to have write privileges granted to that group. These commands might be useful, but will require root or sudo privileges:
sudo chgrp www-data /path/to/file.json
sudo chmod 664 /path/to/file.json
Or, if you want to grant write access to a directory where you might upload many files, try this:
sudo chgrp www-data /path/to/directory
sudo chmod 775 /path/to/directory
I would NOT run that command on your /var/www/html directory if you can help it. It's generally a bad idea security-wise to grant apache write permissions inside your web root.
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.
I'm logging in to my server with my ec2-user account (using FileZilla). I want to replae the PHP.ini that is in the /etc folder with a pre-made file of my own.
The thing is I don't have permissions to do so and I can't figure a way to replace this file.
I can't login with the root to FileZilla (is there a way to do it?) and I'm not sure if I can use sudo as part of the FileZilla application.
I tried to chown the whole /etc folder under ecw-user, but that endedup with me getting /etc/sudo.conf is owned by uid 500 should be 0 message for every command I'm trying to do.
What should I do?
I ended up changing the permission just to the PHP.ini and not the whole etc directory using:
sudo chown ec2-user <file_name>
This enabled me to replace the file.
I get this error while trying to do file_put_contents().
Apache is working as apache group, started with sudo rights. My user is in apache group. All dirs and files have 755 chmod.
File exists.
Locally it works fine, on remote CentOS server not. Why? How to debug that thing?
Sometimes SELINUX will prevent writing as was my problem serving from Fedora. Run:
sudo setenforce 0
This can be solved by changing directory permission.
Run the command like
chmod 777 database (the directory)
You can use getcwd()" to find the directory path.
Please have a look here
Hi I just installed ubuntu alongside my Win 7 and I have been using xampp and am very familiar with it, but I just installed lamp and am using the apache2, php, and mysql from terminal and I copied a web folder over from my xampp side and it is saying that I do not have permission to access that file.
I know that on my pc I had some htaccess files but on Ubuntu I am yet to figure out how to view those. Is this a product of those .htaccess files or something else?
That happens if you install WAMP/XAMMP on system partition.
so you copied the files form windows to linux?
sounds like a classic file permissions problem.
per default the www folder is in /var/www, so you can simply set the owner of this folder to the apache user which is called www-data, run this in terminal:
sudo chown -R www-data:www-data /var/www
but now you will no longer be able to write to those files yourself, because they are owned by www-data. checkout this answer for more details and how to get write access: https://askubuntu.com/a/51337
or you make it writeable for everyone (which is a bad idea): sudo chmod -R 777 /var/www
about editing .htaccess files:
I don't use linux with a graphical user interface, but you can edit them with the terminal editor of your choice, on ubuntu you have nano installed by default:
nano /var/www/.htaccess
or if you want a more advanced editor, I suggest vim https://help.ubuntu.com/community/VimHowto
vim /var/www/.htaccess