Database (database/database.sqlite) does not exist. Database works from artisan tinker - database

I created my database.sqlite file in the database folder. My .env file contents are :
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=absolute\path\to\database\database.sqlite
DB_USERNAME=admin
DB_PASSWORD=
When I run php artisan tinker and DB::table('users')->get(); I get the info from the database.
My DatabaseController is:
class DatabaseController extends Controller
{
public function main()
{
$users = DB::table('users')->get();
return view('database',compact($users));
}
}
Yet when I request /database path I get the error:
QueryException in Connection.php line 647:
Database (database/database.sqlite) does not exist. (SQL: select * from "users")
UPDATE:
A temporary fix is to change the database.php from the config folder:
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => 'absolute\path\database\database.sqlite',
'prefix' => '',
],
Instead of using env('DB_DATABASE', database_path('database.sqlite')), which returns database/database.sqlite not my absolute path.

You need to use full path, something like:
DB_DATABASE=/home/laravel-project/database/database.sqlite

If you remove DB_DATABASE=... from your .env file and use the path in the config/database.php:
'database' => env('DB_DATABASE', database_path('database.sqlite')),...
(if your database.sqlite file is in database/ folder), it will work, too.

I ran the following commands:
php artisan config:cache
php artisan config:clear
php artisan serve - restarted the server

In config/database.php file:
'sqlite' => [
'driver' => 'sqlite',
'database' => dirname(__DIR__).'/database/database.sqlite',
],
Then run following command:
php artisan config:cache
php artisan config:clear

For those who still face this issue: https://laracasts.com/discuss/channels/general-discussion/database-databasedatabasesqlite-does-not-exist-error-on-running?page=1
Since sqlite only require DB_CONNECTION=sqlite in .env file so you just remove the other:
DB_HOST
DB_PORT
DB_DATABASE
DB_USERNAME
DB_PASSWORD
then save and run migration again. This was how I solved the problem. Cheers!

As Chris said in the comments, the main solution is to completely delete DB_DATABASE from the .env file (in fact, only the first line of the following code is needed).
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USERNAME=admin
DB_PASSWORD=

For Windows, you need to set up your path like this
DB_DATABASE="C:\\xampp\\htdocs\\project\\data\\database.db"

I think, that the problem here was because of Homestead.
Absolute path to the database.sqlite file on local machine is not the same as the virtual machine one has.
In my case a had to set:
DB_DATABASE=/home/vagrant/code/database/database.sqlite
Or, you can just comment out this line and you are ready to go.
#DB_DATABASE=

go to the PHP folder from your C: directory and open the file php.ini.
From there find extension=pdo_sqlite and remove ;

Faced the same problem.
Just had to create the database.sqlite file in the database directory and run my migrations

✅ When using sqlite as your db, remove other DB env variables and it should work fine.
I faced the same problem and this solved it perfectly.
DB_DATABASE=sqlite
Remove the others.

Related

Guys i am getting error as below while copying the file from puppet master to agents

1.when i used "puppet agent -t" command in agents it's not retrieving from puppet server and getting the error as below.
2.the below code i have used in modules path:/etc/puppetlabs/code/environments/production/modules/mailx/manifests/init.pp and i have included this class in site.pp file as below.
Error: 1.I
/Stage[main]/Mailx/File[/etc/mail.rc]: Could not evaluate: Could not retrieve information from environment production source(s) puppet:///modules/mailx/mail.rc
file { '/etc/mail.rc':
ensure => present,
mode => '0644',
owner => 'root',
group => 'root',
source => 'puppet:///modules/mailx/mail.rc',
}
node 'default', {
include mailx
}
Your code will be much easier to read if you present it like this.
#/etc/puppetlabs/code/environments/production/modules/init.pp
class mailx {
file { '/etc/mail.rc':
ensure => present,
mode => '0644',
owner => 'root',
group => 'root',
source => 'puppet:///modules/mailx/mail.rc',
}
}
And then the file
#/etc/puppetlabs/code/environments/production/modules/mailx/files/mail.rc
set smtp=your.smtp.server
set from="from email address"
The module should be in
/etc/puppetlabs/code/environments/production/modules/mailx/manifests/init.pp
Notice the "production" after the environments.
It may have just been a typo when you put the path in to here but you spelt puppetlabs as puppelabc.
And the file should be here
/etc/puppetlabs/code/environments/production/modules/mailx/files/mail.rc
Each directory under the environment directory is an environment and that error says Puppet is looking in the production environment for that file.

How to install a plugin manually in CakePHP 3?

I am unable to use Composer and thus have to install CakePDF plugin manually, but following examples from official CakePHP documentation does not seem to work.
So here is installation flow that I have followed:
1.) Copied the plugin to app/plugins/CakePdf
2.) Updated the app's composer.json file, like following:
"autoload": {
"psr-4": {
"CakePdf\\": "./plugins/CakePdf/src",
"CakePdf\\Test\\": "./plugins/CakePdf/tests"
}
},
"autoload-dev": {
"psr-4": {
"App\\Test\\": "tests",
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
"CakePdf\\": "./plugins/CakePdf/src",
"CakePdf\\Test\\": "./plugins/CakePdf/tests"
}
}
3.) Loaded the plugin in bootstrap.php:
Plugin::load('CakePdf', ['bootstrap' => true, 'routes' => true, 'autoload' => true]);
4.) Added router extensions:
Router::extensions(['pdf']);
5.) Tried a very simple sample from plugin's doc:
$cakePdf = new CakePdf(array(
'engine' => 'CakePdf.DomPdf',
'pageSize' => 'A4',
'orientation' => 'portrait'
));
$html = '<html><head><body><p>Pdftest</p></body></head></html>';
$rawPdf = $CakePdf->output($html);
However the code breaks at the first line and the following error message is provided:
Class 'App\Controller\CakePdf' not found
I would really appreciate any help or guidance for how a plugin should be installed manually.
If there is any other information that I need to provide, just ask.
You are getting this error because inside vendor/composer/ you can see some autoload_*.php files. These files hold the paths to load your classes. I think no one can safely tell you what to update and where in these files.
So you have two solutions:
1 - Copy composer.json on a local machine and run composer update. Then move the files created inside your app. I would suggest to take a backup before. Most probably the things that you will have to move are:
vendor/
composer.json
composer.lock
2 - Start updating the files inside vendor/composer/autoload_*.php with the paths from the plugin. Most probably you will only need to update the following two files:
vendor/cakephp-plugins.php and vendor/composer/autoload_psr4.php. Personally I wouldn't choose the second solution I am just adding it as an alternative just in case.

Creating sub-folders in Caching, Cakephp

I have a Cache folder in tmp.
I want a sub-folder in the cache folder, to store cache files of a particular page ONLY in that folder.
What should I do?
Find bootstrap.php in your app/config
Replace the following lines
Cache::config('users_cache', array( // users_cache is the custom cache log name
'engine' => File,
'prefix' => 'cake_',
'path' => CACHE . 'users' . DS, // added sub-directory in users in tmp/cache
'serialize' => true,
'duration' => '+360 minutes'
));
Now, create a directory in your app/tmp/cache/users
Then use it as the following format
Cache::write('enter_name', $users,'users_cache');
For best reference read the following article Cache::write

Cakephp: issue with permissions when using the Apc cache

When using the file cache, this config let me write/read the cache from a shell script
Cache::config('default', array(
'engine' => 'File',
'mask' => 0666
));
However, when using something like this
Cache::config('default', array(
'engine' => 'Apc',
'mask' => 0666 // I don't think this is used by Apc cache.
));
I get permission errors when saving/reading the cache from a shell script. The Apc cache is working fine when running from regular page loads though. I understand that shell scripts aren't executed from the same user as regular page loads, but I don't know how to set the Apc cache permissions correctly.
Here's my shell script:
class HelloShell extends AppShell {
public function main(){
Cache::write('Hello', 5);
}
}
Here's the error
Warning Error: default cache was unable to write 'hello' to Apc cache in [/home/pi/MyProject/lib/Cake/Cache/Cache.php, line 325]
You need to enable APC for php-cli
http://www.php.net/manual/en/apc.configuration.php#ini.apc.enable-cli
because shell jobs runs as command line php
Well, you just answered your question. Have you tried changing the permissions of the App/tmp/ directory to 777?
#chmod -R 777 app/tmp

An internal error has occured

I'm Vaijanath. I'm using cakephp installed on lamp. Now i have created a blog application, but when i run this on localhost/cakephpproject/cakephp/ it is showing an error:
"An Internal Error Has Occured".
And i had changed the "routes.php" in "/app/Config/routes.php" from
"Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));"
to
"Router::connect('/', array('controller' => 'posts', 'action' => 'index'));"
This is an internal error and i'm not able to solve it. Could you please help me in this?
Is your project in your user's public_html dir ?
If so, you must update the three .htaccess files, located in <projectBase>/, <projectBase>/app/ and <projectBase>/app/webroot, and add the following code after each RewriteEngine on statement :
RewriteBase /~<yourUserName>/<projectBase>/
Hope that helped.
In your CakePHP app in the ‘config’ folder change the following setting in the ‘core.php’ file
Configure::write(‘debug’, 0);
Change the ’0′ value to a ’2′ and CakePHP will print all debug errors.
It will display all the errors.. and when the functions works then again change it back to 0.

Resources