PHP Artisan Tinker Cannot Write to Config Path - php

I have used Tinker before but suddenly it stopped working, no matter what project, what version, new or existing. I am on a macbook pro 2013, mac os Sierra, iterm2 with zsh. I have researched all over and not found anything of relevance with exception of one reference in stack overflow to https://github.com/bobthecow/psysh/issues/382 which doesn't show resolution, is not laravel specific but seems to be involving the psy shell (all other artisan commands are fine):
vagrant#homestead:~/Code/application$ php artisan tinker
[ErrorException]
Writing to /home/vagrant/.config/psysh is not allowed.
Is the error I am shown. Vagrant is set up through virtual box running homestead-7.
When I ssh into vagrant and ls -la I see the .config folder but cannot access it nor can I mkdir mvdir due to access denied errors. (Which if I am learning from the stack trace below is where the error is being triggered? Top of the trace where the touchfilemkdir is at?) The folder itself is owned by vagrant. I can make out where the error is triggering but I don't know why it could possibly be triggering regardless of what version of laravel I use, whether it is an existing project or a new download.
Within the laravel projects themselves, I have
"laravel/tinker": "~1.0",
in the composer.json and
/*
* Package Service Providers...
*/
Laravel\Tinker\TinkerServiceProvider::class
is located in app/cofig/app.php.
I did run a verbose stack trace though I'm not exactly sure just what it is pointing to as to what has broken or why.
Exception trace:
() at
/home/vagrant/Code/lightpointLP/vendor/psy/psysh/src/Psy/ConfigPaths.php:213
Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() at n/a:n/a
trigger_error() at /home/vagrant/Code/lightpointLP/vendor/psy/psysh/src/Psy/ConfigPaths.php:213
Psy\ConfigPaths::touchFileWithMkdir() at /home/vagrant/Code/lightpointLP/vendor/psy/psysh/src/Psy/Configuration.php:361
Psy\Configuration->setHistoryFile() at /home/vagrant/Code/lightpointLP/vendor/psy/psysh/src/Psy/Configuration.php:409
Psy\Configuration->getHistoryFile() at /home/vagrant/Code/lightpointLP/vendor/psy/psysh/src/Psy/Configuration.php:546
Psy\Configuration->getReadline() at /home/vagrant/Code/lightpointLP/vendor/psy/psysh/src/Psy/Shell.php:82
Psy\Shell->__construct() at /home/vagrant/Code/lightpointLP/vendor/laravel/tinker/src/Console/TinkerCommand.php:53
Laravel\Tinker\Console\TinkerCommand->handle() at n/a:n/a
call_user_func_array() at /home/vagrant/Code/lightpointLP/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29
Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at /home/vagrant/Code/lightpointLP/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:87
Illuminate\Container\BoundMethod::callBoundMethod() at /home/vagrant/Code/lightpointLP/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:31
Illuminate\Container\BoundMethod::call() at /home/vagrant/Code/lightpointLP/vendor/laravel/framework/src/Illuminate/Container/Container.php:539
Illuminate\Container\Container->call() at /home/vagrant/Code/lightpointLP/vendor/laravel/framework/src/Illuminate/Console/Command.php:182
Illuminate\Console\Command->execute() at /home/vagrant/Code/lightpointLP/vendor/symfony/console/Command/Command.php:264
Symfony\Component\Console\Command\Command->run() at /home/vagrant/Code/lightpointLP/vendor/laravel/framework/src/Illuminate/Console/Command.php:167
Illuminate\Console\Command->run() at /home/vagrant/Code/lightpointLP/vendor/symfony/console/Application.php:874
Symfony\Component\Console\Application->doRunCommand() at /home/vagrant/Code/lightpointLP/vendor/symfony/console/Application.php:228
Symfony\Component\Console\Application->doRun() at /home/vagrant/Code/lightpointLP/vendor/symfony/console/Application.php:130
Symfony\Component\Console\Application->run() at /home/vagrant/Code/lightpointLP/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:122
Illuminate\Foundation\Console\Kernel->handle() at /home/vagrant/Code/lightpointLP/artisan:35
If any other information may be required I'll be glad to provide it, I'm truly at a loss as to what has happened or how to fix it.
Thank you
UPDATE AUGUST 31
So I have found that when I am in vagrant#homestead and I sudo su when I then am in root#homestead:/home/vagrant# and I enter .config there is a configstore directory and a psysh directory but it was owned by root. I changed the owner to vagrant, exited, reloaded vagrant and the same error.
drwx------ 2 root root 4096 May 4 00:55 configstore
drwxr-xr-x 2 vagrant vagrant 4096 Aug 31 23:37 psysh
So then I tried sudo -i and got root#homestead but found that the contents of .config were different. This time it has .composer directory and no psysh existing. So I added the psysh directory with vagrant as owner
drwxr-xr-x 2 root root 4096 Feb 26 2017 composer
drwxr-xr-x 2 vagrant vagrant 4096 Aug 31 23:59 psysh
but this still also does not work. I also exited, reloaded vagrant, I config:cleared on both but I get the same unable to write error.
I am so at a loss, any insight would help, please. Thanks!

Answer on https://laracasts.com/discuss/channels/servers/tinker-doset-work-in-shared-hosting?page=1&replyId=604794
#You need to create a config file for PsySH with runtimeDir variable.
# Just create a file ~/.config/psysh/config.php with:
<?php
return [
'runtimeDir' => '~/tmp'
];

Looks like it's an issue with PsySH http://psysh.org/.
I can't answer the question but it looks like this guy had the same issue. It may be worthwhile to get ahold of him and asked how he fixed it.
https://github.com/bobthecow/psysh/issues/382
Have you tried running composer update? Good luck.

I had this exact same issue and it persisted for days. I fixed it by running composer dump-autoload from the project directory. I previously tried the command but it didn't work because I was trying it without internet access, make sure you are connected to the internet when you run the command. Goodluck!

I tried composer update, dump-autoload but nothing worked. Simply changed the permission on the ~./config folder and it worked. You can set 755 or higher (I am not talking about the production environment here).

I've executed the next commаnd on my terminаl:
sudo chmod -R 775 ~/.config

Related

Laravel returning server error 500 on CentOS 7

As the title says, I have a VPS running on CentOS 7, I installed all the requisites for Laravel, PHP 7.3, but it still giving me 'Server Error 500'.
Note that this is a fresh installation of Laravel with composer.
My CentOS version is CentOS Linux release 7.2.1511 (Core)
PHP version is PHP 7.3.6 (cli)
I manually installed all the necessary modules from PHP
What I have already tried
I already did quite a lot of research:
Laravel giving 500 internal error on centos 7 with apache and php 7
I followed what the answer to that questions says and still the same for me.
I did also set up permissions correctly following this other post:
How to set up File Permissions for Laravel 5 (and others)
Also these ones
Getting a 500 Internal Server Error on Laravel 5+ Ubuntu 14.04
https://www.ionos.com/community/server-cloud-infrastructure/apache/how-to-fix-http-error-code-500-internal-server-error/
And a bunch of more articles I read on another websites.
These are the permissions for the project folder:
drwxr-xr-x 13 apache apache 4096 May 31 05:23 laravel
And for storage:
drwxr-xr-x 5 apache apache 4096 May 31 04:44 storage
Tried generating the key and got this:
[root#server laravel]# php artisan key:generate
ErrorException : file_get_contents(/var/www/laravel/.env): failed to open stream: No such file or directory
at /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/KeyGenerateCommand.php:96
92| {
93| file_put_contents($this->laravel->environmentFilePath(), preg_replace(
94| $this->keyReplacementPattern(),
95| 'APP_KEY='.$key,
> 96| file_get_contents($this->laravel->environmentFilePath())
97| ));
98| }
99|
100| /**
Exception trace:
1 file_get_contents("/var/www/laravel/.env")
/var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/KeyGenerateCommand.php:96
2 Illuminate\Foundation\Console\KeyGenerateCommand::writeNewEnvironmentFileWith("base64:soTdeaCmsY1ELnpJLCcYkBJjY6SWiLYwY+Mvoxl9wOw=")
/var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/KeyGenerateCommand.php:80
Please use the argument -v to see more details.
[root#server laravel]#
Seems like you miss the Laravel environment configuration file.
In a fresh Laravel installation you should have a .env.example file. Duplicate that one and rename it to .env then run the php artisan key:generate command.
Did you created the var/www/laravel/.env file from your var/www/laravel/.env.example file?
So, I fixed it configuring properly the .env and generating a key as #mdexp mentioned.
So for everyone having problems, check the links in my question and set everything correctly

Issues with cURL connections - error setting certificate verify location

We have been struggling with cURL since we've had our new server (no issues previously). In the last 6 months we've searched and tried to fix the issue at the root, with no success.
We are running an Ubuntu 16.04 server, with a Codeigniter project on PHP and Nginx.
The (composer) package we are currently having the issue with is the Mailgun API (which extends the composer package php-http)
Below is the error that we get when connecting via cURL
An uncaught Exception was encountered
Type: Http\Client\Exception\RequestException
Message: error setting certificate verify locations: CAfile: /etc/ssl/certs/ca-bundle.crt CApath: /etc/ssl/certs
Filename: /var/www/ domain /vendor/php-http/curl-client/src/Client.php
Line Number: 137
The only solution that has worked for us so far disabling CURLOPT_SSL_VERIFYPEER, but we've had to do that inside the composer package, which obviously is not a proper solution.
I'm hoping someone here can please shed some light on how we might be able to resolve the issue.
What we have tried so far:
Checked the date on the server
Disable CURLOPT_SSL_VERIFYPEER, but not a viable solution
Set .curlrc file (but issue is that webserver user is executing, so no place to put it?
Checked the /etc/ssl/certs/ folder to see if the files exist.
sudo update-ca-certificates --fresh
File permissions on the folder
root#Ubuntu-1604-xenial-64-minimal /etc/ssl/certs # ls -la ca*
lrwxrwxrwx 1 root root 37 Apr 26 11:17 ca6e4ad9.0 -> ePKI_Root_Certification_Authority.pem
-rwxrwxrwx 1 root root 274340 Mar 8 17:09 ca-bundle.crt
-rwxrwxrwx 1 root root 274340 Apr 26 11:25 ca-certificates.crt
-rwxrwxrwx 1 root root 261889 Jan 18 06:12 cacert.pem
-rwxrwxrwx 1 root root 261889 Jan 18 06:12 cacert.pem.txt
As I have been struggling with this for a long time and haven't been able to find the answer anywhere, but found it due to the help of # Deadooshka in a not so related post, I'll leave my question and answer here.
For me the solution what that the /etc/ssl folder needed execute permission. I have no idea where this has gone wrong, but the solution for me was the following:
$ /etc # chmod o+x ssl
When the permissions were wrong, I could not read the certificate file using file_get_contents(/etc/ssl/certs/ca-certificates.crt) in a PHP script in the web root, executed from the browser. After the fix, the file was read.

Laravel error - Unknown: Failed opening required '. ./public' (include_path='.;C:\php\pear\') in Unknown on line 0

I'm working on Laravel 5 and I'm using PHP function php -S localhost:8888 folder-name - t to show the web site.
Everything is working fine until I updated to Window 10. Now, I try to run the project in my browser, I get a blank page and this message in my cmd:
[Mon Aug 03 00:17:05 2015] PHP Fatal error: Unknown: Failed opening
required 'public' (include_path='.;C:\php\pear\') in Unknown on line 0
What is going wrong?
It sounds like a permissions issue. I don't have much experiencing working with Laravel on Windows, but I just fixed a similar issue on an Ubuntu box.
The source of trouble for me was that I installed composer as root, so I had to remove ./vendor, change the owner and group of ~/.composer to ubuntu:www-data (ubuntu is my user, www-data is the Nginx user), and rerun composer install. I also made sure the ./storage permissions were recursively set to 775, and change the owner of my entire Laravel project to ubuntu:www-data.
Some stuff will definitely be different if you're on Windows, but hope this helps!
It is a permission error actually. But if you try to run directly from your localhost server, it will work.
On windows 10 PHP Server will not be able to access PHP Pear extension that is why it is showing this error.
If you are running XAMPP. you have to go to your apache localhost with http://localhost/laravel-folder/public.

"End of script output before headers" on CentOS, but working on other LAMP stacks

I've set up a Centos 6 + CPanel 11 VPS, and everything is as it was out of the box. I've installed Phorum 5.2.20 in the public_html directory, but Phorum is causing an error 500. The error log reports:
[Mon Jul 27 11:21:57.770447 2015] [core:error] [pid 14342] [client x.x.x.x:42531] End of script output before headers: admin.php
The code works fine on my Debian LAMP server (and several other non-Centos/CPanel LAMP stacks I've used to test this), and Wordpress and some other stuff runs fine on the CentOS machine.
I've tried other code too, and it works on my other servers, but doesn't work on CentOS. Phorum is the only code that matters, so I made question focuses on that. I'm also reluctant to edit the core files of Phorum.
Any ideas?
Fixed: Permission Issue
I have also faced the same issue after installing fresh installation on VPS, later I found It's a permission issue, Directory should be 755 and files should be 644 then only it works.
sudo chmod -R 755 projectfolder
sudo chmod -R 644 index.php //projectfiles
I think there is an issues with the php handler. Can you please try to change your php handler through WHM >>Service Configuration >> Configure PHP and suEXEC and check your URL again.
For me the error was caused by file permissions. Luckily it was just the one file causing it so I used the same permissions as the working .php files and it worked.
In my case 644 worked with enough permission to run and not too much to trip the security settings.
I had same error for more than a day finally i found out that accidentally my /home/mysite_username/fcgi-bin/php7.0.fcgi file owner and group was changed to root. Restoring owner to mysite_username solved this issue. (I'm using Virtualmin)
Fix permissions from User Account Menu of CWP.

Zend Cache - problem with deleting cache files

I have an strange problem with Zend Cacke (File Backend) running on linux with apache and php 5.2
The files are stored in /myspace/tmp1
Directory has the persmission:
drwxrwxrwx 2 nobody nogroup 8192 2010-09-20 13:35 tmp1
The created temp file has the following permissions:
-rw------- 1 nobody nogroup 317 2010-09-20 13:40 content---a51607ba255692370eae1155c7f45856
If if i do:
$cache->clean(); inside my script, than the method returns true, but the file is not removed (no error in php error log).
On my local development machine running under win xp everything works fine. I think it is some kind of permission problem? The Apache is running as "nobody"
Any suggestions are welcome!
I think you need to use Zend_Cache::CLEANING_MODE_ALL as by default it cleans only outdated AFAIK.

Categories