After successfully making WSL2 work with Docker Desktop (v3.1.0)
NAME STATE VERSION
* Ubuntu-20.04 Running 2
docker-desktop Running 2
docker-desktop-data Running 2
I followed steps from the Laravel Docs: https://laravel.com/docs/8.x#getting-started-on-windows but the error:
[ErrorException]
file_get_contents(): Read of 8192 bytes failed with errno=13 Permission denied
showed up, and i couldn't find the docker-compose.yml file in the directory either, after running ./vendor/bin/sail up:
ERROR:
Can't find a suitable configuration file in this directory or any
parent. Are you in the right directory?
Supported filenames: docker-compose.yml, docker-compose.yaml
This is probably a Linux permission problem. The safest way to fix it is to chown the directory and make it owned by the same user / group as the php process is running under.
The default user is called sail: https://github.com/laravel/sail/blob/1.x/runtimes/8.0/Dockerfile#L46
And the group is read from a .env variable called WWWGROUP
So what you want to do is open your WSL2 console, cd to your project.
And run
chown -R sail:<whatever your group from the env is WWWGROUP> .
. means current directory.
Many beginners would do things like chmod 777, however this is a bad practise.
Related
Almost always, when I am starting a Codeigniter 4 project, I am getting the following error:
"CodeIgniter\Cache\Exceptions\CacheException Cache unable to write to "/path/to/codeigniter-project/writable/cache/."
SYSTEMPATH/Cache/Handlers/FileHandler.php at line 61
which points at the below line:
throw CacheException::forUnableToWrite($this->path);
What is the best way to solve this?
After doing a research, I've concluded into two options
Option 1:
The very quick way to just solve the above issue is to go to the command tool (e.g. terminal) and change the permissions of the folder to be writable and also to change the owner of the folder to be the one that is used from your server application. For example, I am using Apache and the user for apache is www-data:
chmod -R 755 writable/
chown -R www-data:www-data writable/
or for macOS:
chmod -R 755 writable/
chown -R _www:_www writable/
Pros:
A quick copy-paste solution
Those commands - most of the times - works out of the box
Even if you don't have access to command tool, you can change the permissions and ownership of the folder through FTP (e.g. through FileZilla UI interface)
Cons:
You always need to add those commands into a new project
You may experience issues on development when you are trying to access the folder with your username
Option 2 (suggested for local development):
Add the www-data or _www (for macOS) to be at the same group role as your user.
for Linux and Apache:
sudo usermod -aG www-data your_username
or for macOS and Apache:
sudo dseditgroup -o edit -a your_username -t user _www
If you are still getting the error also make sure that you have the folder as writable with the following command:
chmod -R 755 writable/
I don't know why but it may also need to do a restart of the Apache.
Pros:
It works for new projects with no extra effort
You don't need to change the owner of the folder so you can have access to the folder for development
Once this change is available to the server or locally, you don't need to use sudo anymore if the chmod command is required
Cons:
Not that safe for production environments (especially if you don't know what you are doing) since you would prefer to have specific users with specific roles rather than have users to have access everywhere
It requires more effort and it is not that straight forward for beginners
It needs more permissions to the server (e.g. sudo access)
The OP has a good answer. Though sometimes you don't have access to the terminal or a secure shell (ssh), especially in a shared hosting environment to be able to run those commands.
I got a similar issue while working on a new project. I noticed that this normally happened because my application failed to write session files in the writable/session folder of my root project directory because of permission restrictions. I was using the CodeIgniter\Session\Handlers\FileHandler as my configured "session storage driver".
I managed to solve it by instructing the application to write these temporary files in the server's tmp directory.
This is by default in the /tmp directory.
Excerpt from php-src/php.ini-production
; Directory where the temporary files should be placed.
; Defaults to the system default (see sys_get_temp_dir)
;sys_temp_dir = "/tmp"
Solution
I opened my .env file residing at the root of my project directory and added the line below.
app.sessionSavePath = '/tmp/my_project_name/ci4_session'
If you don't have this .env file, create one starting with this default file content:
Notice the dot (.) in front of the filename.
CodeIgniter4 env file
Addendum
Similarly, in your case, the application fails to write cache files in the writable/cache folder of your root project directory because of permission restrictions. You most certainly are using file as your cache handler.
Solution
Open your .env file residing at the root of your project directory and add the line below.
cache.storePath = '/tmp/my_project_name/ci4_cache'
TIP(S)
These and more configurations can be found/modified in your .env file using the rules below:
The configuration class file name, in lower case. I.e cache.
Followed by a dot(.).
Then the public configuration class's property name. I.e storePath.
Steps 1,2,3 combined makes, cache.storePath, which becomes your .env file's key declaration. Then an equals sign =. And lastly, the .env file's value ('/tmp/my_project_name/ci4_cache') declaration. Finally coming up with, cache.storePath = '/tmp/my_project_name/ci4_cache'.
The configuration classes can be found in the app/Config folder of your root project directory. I.e:
app/Config/Cache.php
app/Config/App.php
This worked for me, U should try this
Firstly cd into where your file is Example
cd /opt/lampp/htdocs/
This is where my file is
Secondly Write this command below in your command prompt
sudo chmod -R 777 file-name
I just create a folder inside "writable" folder with name "cache" and my project properly running.
Running the command "php artisan key:generate" on the docker container it shows:
file_get_contents(/var/www/.env): Failed to open stream: No such file or directory
However the .env file exists. Do you know what can be the issue?
Found someone with the same problem (and solution) here
If, like me, you did have a .env file, you may find it has permissions that are too tight to allow your current user to write to it (and by implication the php artisan command your current user is attempting to run). I had changed all my Laravel files to be owned by www-data:www-data and made my current user a member of the www-data group, and was thus a little stumped by this error.
However, I soon realised that my .env file has the following permissions:
-rw-r--r--
...meaning the user which owns the file gets read-write, but the group and world can only read. Since my current user is a member of the group www-data, it can only read, not write.
(You can check your file permissions by doing $ ls -la)
If you have the same situation, you have two choices; loosen the file permissions on that file (with chmod) or use sudo to run your php artisan commands. I chose the latter, since this is a production server for me and I like the tight permissions.
appreciate if you could help me.
I'm running docker VM in a MAC OS X and seems okay until i reach a permissions error when my app is trying to write files in the assets folder in the server:
CAssetManager.basePath "/var/www/html/assets" is invalid. Please make sure the directory exists and is writable by the Web server process.
I ran ls -l in the docker container shell ($ docker exec container) and saw that my folder permissions are set to
drwxrwxrwx 1000 staff assets. Following that, i tried to set it to www-data as i though it might work , so i ran usermod -u 1000 www-data. Now folder becomes: drwxrwxrwx www-data staff assets but the error persists.
In the shell, I also tried to run chmod and chown commands but i get these errors:
chown: changing ownership of 'assets': Read-only file system
chmod: changing ownership of 'assets': Read-only file system
How can i enable my directory to be writable by the web server process in docker?
UPDATE:
$ docker ps returns
$ docker info## Heading ## returns
UPDATE 2:
$ docker inspect returns
http://pastebin.com/wM3tT51v
Looking at the docker inspect output
"Mounts": [
{
"Source": "/Users/joelkoh/Sites/merrymaker/php-app",
"Destination": "/var/www/html",
"Mode": "ro",
"RW": false,
"Propagation": "rprivate"
}
],
It looks like your directory is read only, I'm not familiar with elastic beanstalk, but you will need to change that volume so it isn't read only.
You might consider using http://docker-sync.io for mounting shares. Since it is not mounting, but syncing, it solved the user permission-problems by mapping your desired uid/guid to the container https://github.com/EugenMayer/docker-sync/blob/master/example/docker-sync.yml#L47
This way you have a very performant share, but also, having a proper user mapping to never care about permission issues in the container ( for host-mounted folders )
Well, this error is so know but in my case I could not mitigate it in my side. I have migrated a laravel-4 installation to another server and for the first time accessed I get this error:
file_put_contents(/var/www/html/MyApp/app/storage/meta/services.json): failed to open stream: Permission denied
I have followed different googled aswers as below
https://stackoverflow.com/a/17971549/1424329
Can't make Laravel 4 to work on localhost
http://laravel.io/forum/05-08-2014-failed-to-open-stream-permission-denied
Laravel 4: Failed to open stream: Permission denied
However, any of them could not fix my problem. I also tried cleaning the cache and dump autoclass command:
php artisan cache:clear
chmod -R 777 app/storage
composer dump-autoload
Also, I have thought that the webserver process might be considered in the problem, so I seek for its user like this:
$ ps -ef|grep httpd
apache 11978 11976 0 11:14 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
Then, I added apache to the directory group owner and the problems persists.
I do not know what else to do, I am going insane because dancing naked under full moon neither fixed the problem.
I have discovered the cause of this problem. Looks like selinux does not allow to httpd service (apache web server) write in my app folder. So, I did:
setsebool -P httpd_unified 1
Now everthing is working fine!
Happens to me some times, but I just delete it and Laravel recreates it. As far as I know, this is just a cache list of services and can be safely removed.
I have recently installed FC13 and am attempting to write a mechanism in my PHP code that caches gathered data into a specific directory (for our purposes here, let's call it /var/www/html/_php_resources/cache).
I copy my files over to the /var/www/html directory and then run chown -R apache:apache /var/www/html/* and chmod a+w /var/www/html/_php_resources/cache on the new data. For right now I am just using the global write permission for convenience. I will tweak the permissions later.
When I attempt to use the chmod or mkdir PHP functions I wind up with:
Warning: chmod(): Permission denied in /var/www/html/_include/php/CacheInit.php
or
Warning: mkdir(): Permission denied in /var/www/html/_include/php/CacheInit.php
Now, when I disable SELinux everything works just fine. The problem is that I would prefer not to disable SELinux and actually get the permissions set up correctly so that I can port it over to servers where someone does not have such explicit control.
As an example: my personal site host allows me to set read/write permissions on directories but will not allow for SELinux policy changes.
FYI:
uname -r = 2.6.34.7-56.fc13
*php -version * = PHP 5.3.3
rpm -qa | grep httpd = httpd-2.2.16-1.fc13
Does anyone have any suggestions?
I had the same problem, trying to mkdir from php. Not so much information on google but this is what I found and I guess this is the correct solution. One have to label the dir in which apache should create directories.
Label should be "httpd_sys_script_rw_t" and I found that info here: http://docs.fedoraproject.org/en-US/Fedora_Core/5/html/SELinux_FAQ/index.html#id672528
Here's how to label the dir: chcon -R -t httpd_sys_script_rw_t <dir>
Reference somewhere here: http://www.centos.org/docs/5/html/Deployment_Guide-en-US/rhlcommon-chapter-0017.html
Hope this help someone out there.