Laravel Scout & Algolia - can't create index on staging server after migrating from TNTSearch to Algolia [closed] - laravel-5.3

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
this is very weird. I've successfully created an index on my local server and it showed up in Algolia dashbord.
However, when I ran php artisan scout:import 'App\MyModel' on my staging server I get:
Imported [App\MyModel] models up to ID: 22
All [App\MyModel] records have been imported.
but the index doesn't show up in Algolia dashboard.
I've compared my .env files and these fields are the same on both of my apps:
SCOUT_DRIVER=algolia
SCOUT_PREFIX=staging_ //this one is "development_" on my local server
ALGOLIA_APP_ID=aaaaa
ALGOLIA_MONITORING_KEY=bbbbb
ALGOLIA_SEARCH=ccccc
ALGOLIA_SECRET=ddddd
my config/scout.php
'driver' => env('SCOUT_DRIVER', 'algolia'),
'prefix' => env('SCOUT_PREFIX', ''),
'queue' => true,
'algolia' => [
'id' => env('ALGOLIA_APP_ID', ''),
'secret' => env('ALGOLIA_SECRET', ''),
],
and here is my config/algolia.php
'default' => 'main',
'connections' => [
'main' => [
'id' => env('ALGOLIA_APP_ID'),
'key' => env('ALGOLIA_SECRET'),
],
'alternative' => [
'id' => 'your-application-id',
'key' => 'your-api-key',
],
],
Any help is appreciated. Thanks!
UPDATE
It seems that index file my_models.index in the storage folder gets updated when I run php artisan scout:import 'App\MyModel'
I believe this is a leftover from using TNTSearch before Algolia but I can't figure out why is my app using TNTSearch and not Algolia one on my staging server.
I concluded this because when I run php artisan scout:import 'App\MyModel' this index file gets updated on my staging server but not on my local machine.
UPDATE #2
ssh into server, inside of php artisan tinker I get algolia if I run env('SCOUT_DRIVER') or config('scout.driver').
UPDATE #3
Tried the php artisan config:clear and cache:clear but I still get new my_model.index file after I run the scout:import on my model.
Even after I've deleted all mention of TNT from .env, composer.json and AppServiceProvider.php.

Restarting the server fixed it!

Related

Upgrade drupal from version 7 to version 8

I tried to upgrade from Opigno LMS 1.38 to Opigno LMS 2.3
it's concerning to upgrade from drupal 7 to Drupal 8
I got this error at the upgrade page :
"The video plugin must define the source_module property."
Please, could someone help me ?
I followed this steps to run the upgrade :
*Step 2: Activate contrib modules for migration in Drupal 8 on page /admin/modules:
Migrate
Migrate Drupal
Migrate Drupal UI
Migrate Plus
Migrate Tools
Step 3: Activate custom module for migration in Drupal 8 on page /admin/modules:
Opigno Migration
Step 4: Add connection to the legacy base (Drupal 7) with target ‘default’ and key ‘legacy’ in your settings.php file.
Example
$databases['legacy']['default']= array(
'database' => 'opigno_drupal7',
'username' => 'root',
'password' => 'root',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
);
Step 5: Open page /upgrade on your Drupal 8 site and click on button ‘Continue’.*
I got the error after the step 5
thanks in advance
In case others are struggling, the video contrib module needs this patch to play nicely with migrate
Apply the patch in https://www.drupal.org/project/video/issues/2986682

How to set up SQLITE for laravel webserver?

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

How to make SQLite work in Laravel

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.

Getting install.php when export site from development server to production

I've copied files and imported DB dump to MySQL on production server but when I try to access website settings.php file loads. I've got settings.php file in my site subdirectory in /sites folder. Here's it's content:
$databases = array('default' => array('default' => array(
'driver' => 'mysql',
'database' => 'dmitry_dkkb',
'username' => 'root',
'password' => 'fg67klbn0',
'host' => '127.0.0.1')));
I guess i just missed something when i edited this file
Try setting the drive to mysqli. Also, follow this steps:
1) Take a back up of your db and save it to a safe place
2) Remove all the tables from the db, and remove the setting.php or rename it
3) Do you clean install of Drupal using those files
4) Once finished, import the db back up
This process always works on all platforms, in all the situation

How do I get Drush rsync to use site-aliases correctly?

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',

Resources