I am trying my best to understand why the KnpSnappyBundle does not work at all. Inside of Symfony2.
This is the error I keep getting time and time again:
Warning: file_put_contents(/var/folders/l7/_w4sky2d457czb5v3d0133y40000gn/T/knp_snappy52eb2be7bf7915.98143786.html): failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/symfonydev/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php line 330
This is line 330:
file_put_contents($filename, $content);
I have done everything to the "T" with exactly how it explains how to install it.
I have installed WKHTMLTOPDF using HomeBrew and it now resides in my /usr/local/bin directory.
My config.yml file looks like this:
# Knp Snappy Configuration
knp_snappy:
pdf:
enabled: true
binary: "wkhtmltopdf"
options: []
My code looks like this:
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml("hello world"),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="'.$pdfTimeStamp.'.pdf"'
)
);
I can generate a pdf from command line when calling this code:
/usr/local/bin/wkhtmltopdf http://www.google.com/ /User/xxxxx/Desktop/thepdf.pdf
And yet I get this error everytime.
PLEEEEEASE HELP! Thanks so much!
Please check if your shell user has write permissions for /var/folders/l7/_w4sky2d457czb5v3d0133y40000gn/T/.
try to use these binary path /usr/local/bin/wkhtmltopdf instead of using the wkhtmltopdf.
Related
I am trying to rename a directory of google cloud using the SDK. I am getting error message of 404 No such object:buketname/previousDirName. Renaming a file works fine but only facing issue in renaming folder.
Here is the code i am using:
if(file_exists(dirname(__DIR__) .'/vendor/autoload.php')){
$selected_bucket = 'BucketName';
$key_file = dirname(__DIR__).'/authkey.json';
$client = new StorageClient([
'keyFilePath' => $key_file,
]);
$bucket = $client->bucket($selected_bucket);
$endpoint = 'https://storage.googleapis.com/'. $selected_bucket;
if(isset($subfolder)){
$adapter = new GoogleStorageAdapter($client, $bucket, $subfolder.'/'); // code to list specific subfolder of the bucket
} else {
$adapter = new GoogleStorageAdapter($client, $bucket);
}
$filesystem = new Filesystem($adapter, Array ( "url" => $endpoint ));
// rename a file
$filesystem->rename('filename.txt', 'newname.txt'); // works fine
// rename a directory
$response = $filesystem->rename('developer', 'developer123');
print_r($response);
die();
}
I tried to debug in the sdk but nothing found. I searched the issue if someone faced the same issue but didn't found any working solution. I found one but the solution was in gsutil.
Please please suggest me what I am missing in case of renaming directory.
Thanks
Google Cloud Storage does not not have the concept of "folder", there are only buckets that contain storage objects (flat namespace) and the meaning of "/" is really imposed by clients (and client libraries). As such, folders can't be renamed atomically and thus you would need to rename each of the contained files, by using the gsutil mv command as you have already figured out, like:
gsutil -d mv gs://my-bucket/folder1 gs://my-bucket/folder2
The -d option will cause it to output the sequence of requests gsutil generates to do the rename and additional debug info needed.
In addition, you could try using the -I option, which reads the file list from stdin and is supported with the mv command, as stated here.
Here you may find an example of code samples as well.
I am trying for quite some time now to disable the profiler in the test-environment. The only way it works is manually setting APP_ENV=test in file .env but I want to do this through the command line, not by editing a file.
Here's everything I tried:
I tried editing bin/console like described in Chris Brown's answer in this thread: Load different .env file with a Symfony 4 command (I also added the file .env.test, and according to xdebug it loads the appropriate file and runs through the appropriate code and also the variables $env and $debug get the appropriate value when I run the server with --env=test --no-debug)
I tried setting profiler: enabled: false like described in flu's answer in this thread: How to disable profiler in Symfony2 in production? (in config/packages/test/framework.yaml)
I tried setting the profiler line in bundles.php to
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true],
and to
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => false, 'test_cached' => false],
I tried those solutions separately and also all together, still the profiler keeps popping up. Does anybody have an idea?
EDIT:
After applying Alister Bulman's answer the command gives me this:
#php bin/console -e test debug:config framework profiler
Current configuration for "framework.profiler"
==============================================
enabled: true
collect: false
only_exceptions: false
only_master_requests: false
dsn: 'file:%kernel.cache_dir%/profiler'
EDIT 2:
Thanks to Jared Farrish I just found out the browser is receiving the website in "dev" mode although the server is started in test environment on cli. Obviously editing bin/console and public/index.php is not enough, they're not called when the server receives a request from the browser.
EDIT 3:
So I found out the http request goes first to public/index.php, but whatever I do, I cannot seem to make anything available there which was defined in bin/console although the whole server is started there in the first place. Anyone an idea how this can be done?
The profile can be enabled, or disabled in the framework configuration.
> bin/console -e dev debug:config framework profiler
Current configuration for "framework.profiler"
==============================================
only_exceptions: false
enabled: true
collect: true
only_master_requests: false
dsn: 'file:%kernel.cache_dir%/profiler'
In a newly generated project, these are best set (for the test environment) in the config/packages/test/framework.yaml file.
framework:
profiler:
enabled: false
collect: false
# optionally others
Documentation for the framework config (profiler, and the rest) is at https://symfony.com/doc/current/reference/configuration/framework.html#profiler
I found it myself. What I did was use a functionality of php.ini which is called "auto_prepend_file" where you can specify a PHP file which gets executed automatically before the actual PHP content is executed. So in there I put a path to a file with following content:
<?php
$_ENV['APP_ENV'] = 'test';
$_ENV['APP_DEBUG'] = 0;
I want to use SQLITE for my laravel5 project on my webserver. I migrated my local laravel 5 project onto my AWS ec2 lamp Ubuntu server. http://realtoraxe.com/realtoraxe/public/ but it shows
InvalidArgumentException in SQLiteConnector.php line 34: Database does not exist.
I changed the database.php set for sqlite
<?php
return array(
'default' => 'sqlite',
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => 'http://realtoraxe.com/realtoraxe/storage/database.sqlite',
'prefix' => '',
),
),
);
?>
and I changed the .env to
APP_ENV=local
APP_DEBUG=true
APP_KEY=mystring
DB_CONNECTION=sqlite
CACHE_DRIVER=file
SESSION_DRIVER=file
when I do
php artisan migrate
it says there is no database
I think what I wrote as the path for the database in the database.php is wrong and do I may need to somehow write where my ip adress is in the .env file? I have been googling all night and can't seem to figure this out.
You dont need to edit the .php files at all. You can all do it in the .env file, since the files in the config directory are written to first use the values from the .env file, and if they are not defined, fall back on what is defined there.
env('DB_CONNECTION','mysql') would yield the value from the .env file, and only if it is not defined fall back to mysql.
So in your .env file just put the following:
DB_CONNECTION=sqlite
DB_DATABASE=database/database.sqlite
and create a file called database.sqlite in your database directory (thats where its supposed to be by convention.). That's it.
For default laravel 5.2+ installation:
create an sqlite database file
$ cd storage
$ touch database.sqlite
$ cd ..
make it writeable
$ chmod -R 777 storage
at ".env" file:
DB_CONNECTION=sqlite
DB_DATABASE=storage/database.sqlite
and remove or comment all other DB_* records
If you prefer to use relative path, instead of absolute to database file
at "config/database.php"
instead of:
'database' => env('DB_DATABASE', database_path('database.sqlite')),
write:
'database' => __DIR__ . '/../' . env( 'DB_DATABASE' ),
now, laravel app will be able to find sqlite file, and php artisan will work too
Why are you using HTTP link? I guess it should link to a .sqlite DB file:
'database' => __DIR__.'/../database/production.sqlite',
http://laravel-recipes.com/recipes/118/setting-up-the-sqlite-database-driver
Whenever I run php artisan migrate, the following error is shown in the console:
[PDOException]
SQLSTATE[HY000] [14] unable to open database file
The database.sqlite file is located at database/. I'm running Windows 10, Laravel 5.2. Here is .env file config:
.env:
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database
DB_USERNAME=homestead
DB_PASSWORD=secret
I have looked everywhere, but could not find what causes this error and how to resolve it.
Update
I managed to make migrations run successfully by replacing DB_DATABASE=database with DB_DATABASE=database/database.sqlite in .env file. However, new error occurs whenever I try to retrieve items from the database:
public function index()
{
// cause of the error
$cards = Card::all();
return view('cards.index', compact('cards'));
}
The above action throws following error:
InvalidArgumentException in SQLiteConnector.php line 34:
Database (database/database.sqlite) does not exist.
The strange thing is, that the command Card::all() works flawlessly in php artisan tinker mode. What kind of magic is that?
Anyway, I've also found out, that the line:
'database' => env('DB_DATABASE', database_path('database.sqlite')),
in database.php file needs to be replaced with just database_path('database.sqlite') and everything starts to work normally.
It seems, that the root of the problem is env('DB_DATABASE') call. I went to SQLiteConnector.php file and dumped the output of both env('DB_DATABASE') and database_path('database.sqlite'). Here are their outputs respectively:
dd(env('DB_DATABASE')) // => 'database/database.sqlite'
dd(database_path('database.sqlite')) // => 'D:\www\project\database\database.sqlite'
As you see, their output differs, and the second one is what is expected. Is this a Laravel bug? Or did I misunderstood something?
Short Solution
Though not answering the question, the way to fix "Database not found" issue is to replace the following line in database.php:
'database' => env('DB_DATABASE', database_path('database.sqlite')),
with
'database' => database_path('database.sqlite'),
By using the relative path, migrations will fail because they use project directory as root directory...
To correct everything, I suggest setting:
DB_DATABASE=database\database.sqlite
and tweaking the sqlite connections in config/database.php as follows:
'database' => env('DB_DATABASE/..', database_path('database.sqlite')),
Original Answer
The .env file should contain this:
DB_DATABASE=..\database\database.sqlite
With some testing you can verify that the link included in DB_DATABASE
is relative to the 'public' directory (at least on my Windows machine). That's why we should introduce ..\ before your link.
And of course, using an absolute link should do it too:
DB_DATABASE=D:\www\project\database\database.sqlite
as #Josh suggests
Create file called database.sqlite in this folder as database/database.sqlite
Open the .env file and change MySQL to SQLite
Comment password and username and databaseName using '#'
run php artisan migrate enjoy
env file like this:
DB_CONNECTION=sqlite
#DB_HOST=127.0.0.1
#DB_PORT=3306
#DB_DATABASE=database
#DB_USERNAME=homestead
#DB_PASSWORD=secret
Complementing the awnser by our friend #alexander-lomia
Change:
'database' => env('DB_DATABASE', database_path('database.sqlite'))
To:
'database' => database_path(env('DB_DATABASE'))
in database.php
:)
Instead of a relative path you need to use an absolute path in your .env file.
DB_DATABASE=/var/www/project/database/database.sqlite
or in your case:
DB_DATABASE=D:\www\project\database\database.sqlite
I got the same problem as you did. You have to use the absolute path in ENV file.
Please check the official documentation about this https://laravel.com/docs/5.4/database
DB_CONNECTION=sqlite
DB_DATABASE=/absolute/path/to/database.sqlite
This worked for me in Laravel 5.5
In .env file just have the connection name and remove all other DB_ related settings: DB_CONNECTION=sqlite_testing
Define your sqlite settings in the config/database.php file:
'connections' => [
'sqlite_testing' => [
'driver' => 'sqlite',
'database' => database_path('testing-db.sqlite'),
'prefix' => '',
],
...
]
My file is in the database/testing-db.sqlite.
Shortest and easiest solution is to remove default mysql settings in .env and work in database.php. That's what worked for me at least.
Remove the following...
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
I found the following works rather well, if you prefer to use relative paths:
replace the 'database' line under SQLite with the following:
'database' => database_path(env('DB_DATABASE', 'database.sqlite')),
This was the setting I had used,
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
I also had to run touch database.sqlite in the database folder.
The problem is that php artisan migrate will use the DB_DATABASE from the root of the project, while serving the project with php artisan serve will run from the public directory.
The best solution for me is to create a link to database inside public directory:
UNIX: ln -s database public/database
Windows: mklink /J public\database database
Of course then you would have to deny access to database folder from HTTP requests but that should be easily done.
I'm using Drush 4.2 and I'm trying to rsync files from a the dev server to my local machine. My aliases.drushrc.php is located in the root of my local drupal installation and has the following in it:
$aliases['local'] = array(
'root' => '/Users/christian/Sites/site-root',
'path-aliases' => array(
'%files' => 'sites/default/files'
),
);
$aliases['dev'] = array(
'root' => '/var/www/vhosts/some-domain.com/subdomains/dev/httpdocs',
'remote-host' => 'some-domain.com',
'remote-user' => 'root',
'path-aliases' => array(
'%drush' => ' /var/tools/drush/drush',
'%files' => 'sites/default/files',
),
);
As a test I try to run this from the local drupal root:
drush rsync #dev:%files ~/Desktop/test/
I expect #dev:%files to expand to the remote file path but instead I get:
You will destroy data from /Volumes/MacintoshHD/Users/christian/Desktop/test/ and replace with data from #dev:/Volumes/MacintoshHD/Users/christian/Sites/site-root/%files
Any ideas?
UPDATE:
I've also found that when I'm try the command:
drush dd #dev:%files
I get
Target '#dev:%files' not found.
UPDATE 2
I've found that the issue seems to be coming from the location of the aliases.drushrc.php file. I had it in the drupal root of the site I was working on. I found that if I moved it to ~/.drush/ then everything worked perfectly.
I'd prefer to have it under source control though. I tried putting it in sites/default/ but it had the same problems as before. I'll award the bounty to whomever tells me where to put this file so it's under the source controlled site root.
You can set the alias path in your drushrc.php config file.
If this is not set, then drush searches these locations (in this order) for the alias file.
/etc/drush
drush installation folder
$HOME/.drush
insides the sites folder of your drupal site
Check the readme for more details.
BTW: You have a comma missing in your declaration of 'local' alias.
Modify it as:
'%files' => 'sites/default/files',