Vagrant vm + apache permission denied for mkdir() - php

I am using vagrant to run my vm using ubuntu, apache, etc.
This is running on my OSX host.
Everything works fine until my php application tries to create a folder, files within that folder, etc.
I get Permission denied.
What am I missing on the provision / configuration of the vagrant file?

in this case, if you're using Vagrant + Apache2.
the solution is:
edit /etc/apache2/apache2.conf;
Search for User and Group directives
Change these lines to:
User vagrant
Group vagrant
run sudo service apache2 restart
its not possible to change /vagrant directory owner to www-data (apache user);
Anyway, it works for me.

Edit Vagrantfile
config.vm.synced_folder "./", "/var/www", owner: "www-data", group: "www-data"

You need to set the owner on the folder that php is trying to write to, to the apache user which is normally www-data... ssh into the vagrant box and try:
sudo chown www-data:www-data <dirname>
That should work... if it does then just add that to what ever provisioner you are using.

Related

Laravel not rendering sample blog, permissions to directories already given

I'm testing Laravel on a Arch Linux ARM, to which I'm connecting through SSH.
Going throughout the Laravel's docs
I created a new blog. So far so good.
The Docs mention the following:
After installing Laravel, you should configure your web server's document / web root to be the public directory. The index.php in this directory serves as the front controller for all HTTP requests entering your application.
After installing Laravel, you may need to configure some permissions. Directories within the storage and the bootstrap/cache directories should be writable by your web server or Laravel will not run. If you are using the Homestead virtual machine, these permissions should already be set.
This post says that 'writable by my webserver' means that it must be writable by the user/group which is running apache. I was able to get the group that apache is running from using
ps -ef | grep httpd | grep -v grep.
The user turned out to be http. I checked both /etc/group and /etc/password and the user and group exist with the same name. So I changed the permissions of both bootstrap/cache and the directories inside storage with
sudo chown http bootstrap/cache/
sudo chown -R http storage
sudo chgrp http bootstrap/cache/
sudo chgrp -R http storage
And gave writting permissions to the http group, I realize that this is overkill, since permissions are additive but I still had to try.
sudo chmod g+w bootstrap/cache/
sudo chmod -R g+w storage/
I've read plenty of threads and most of them mention Virtual Hosts so I thought I might as well attempt that, I went throughout the Arch Apache wiki
If you want to have more than one host, uncomment the following line in /etc/httpd/conf/httpd.conf:
Include conf/extra/httpd-vhosts.conf
To test the virtual hosts on your local machine, add the virtual names to your /etc/hosts file:
127.0.0.1 domainname1.dom
<VirtualHost *:80>
DocumentRoot "/srv/httpd/blog/public"
ServerName www.mytest.com
</VirtualHost>
And on my local Ubuntu computer I have <my_Linux_ARM_IP> www.mytest.com on /etc/hosts/
So, whenever I type www.mytest.com on my local computer I get.
I changed the DocumentRoot to test a simple and pure index.html file and it rendered just fine, so I figure the issue is with Laravel.
I was able to manage all this on a local WAMP system beforehand, write the vhosts, change the hosts file so that localhost points to the vhost. And blog rendered just fine.
So it's not Laravel but Apache and the LAN connection? I'm not sure where to go next. Should I read more Apache docs? Should I read more Laravel docs? Should I read more networking stuff? If so, could someone provide some good resources?
Thank you.
Thank you #langbox.
I just followed the steps of this wiki, I chose to use libphp and now it renders correctly.

Plesk Onyx & Nextcloud PHP Errors

I tried to install Nextcloud 13 in Plesk, but if I try to open the link I get a HTTP 500 error.
PHP version: 7.0.27
PHP modules: click here
php_error.log: too long (I can send the pastebin link)
Please tell me if you need more info. I would really appreciate any help.
You might have set the wrong file permission on your Nextcloud installation.
If you created the Nextcloud directory with root permission, you need to change the ownership of the directory to a user or a group, that Plesk has permissions for.
Use these commands to change the ownership (replace myPleskUser with the username you specified during the Plesk installation)
cd /var/www/vhosts/mydomain.tld/
chown -R myPleskUser ./nextcloud
chgrp -R psaserv ./nextcloud

Vagrant file_put_contents permission denied

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

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

Lamp Server 403 Forbidden

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

Categories