I've just pushed a laravel application to an Ubuntu 16.04 VPS - the company is using SQL Server for record management - and I cannot get Laravel to connect to that database for authentication or anything else.
I'm getting errors that say that Laravel cannot find the drivers to connect.
I've searched in too many places.
There's no good tutorial that shows from start to finish, they're all using different packages and it's overwhelming.
Has anybody here successfully connected a laravel application (running on Ubuntu) to SQL Server?
I have managed using below configuration (on windows):
in .env file
DB_CONNECTION=sqlsrv
DB_HOST=hots
DB_PORT=1433
DB_DATABASE=dbname
DB_USERNAME=user
DB_PASSWORD=password
Database.php
'default' => env('DB_CONNECTION', 'sqlsrv'),
and in connections
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', ''),
'port' => env('DB_PORT', '1433'), // note the port
'database' => env('DB_DATABASE', ''),
'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''),
'prefix' => '',
],
Related
I am a student and current building a web application for my project.
While trying to host my Laravel application to Heroku my biggest problem at the moment is with the app failing to connect to the MSSQL database, I am using the MSSQL addon for Heroku.
it shows the error when I try to run the app via the App link
"could not find driver (SQL: select top 1 * from [sessions] where [id] = [idstring])"
I've had a similar issue before while setting up the app to run on local. Solved that by downloading the needed drivers on my local system. Now I am lost as to how to do the same for the hosted app on Heroku
Your config/database.php should look something like:
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
]
I want to use MongoDB for my Laravel project in Xampp but when I use the database it shows this error, I've checked the config many times and searched for it but I found no suitable answer, any solutions?
error:
No suitable servers found (serverSelectionTryOnce set): [connection refused calling ismaster on '127.0.0.1:27017']
.env file:
DB_CONNECTION=mongodb
DB_HOST=127.0.0.1
DB_PORT=27017
DB_DATABASE=mongotest
DB_USERNAME=
DB_PASSWORD=
config/database.php file:
'connections' => [
'mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', 27017),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'options' => [
// here you can pass more settings to the Mongo Driver Manager
// see https://www.php.net/manual/en/mongodb-driver-manager.construct.php under "Uri Options" for a list of complete parameters that you can use
'database' => env('DB_AUTHENTICATION_DATABASE', 'admin'), // required with Mongo 3+
],
],
i'm using Xampp, Laravel 6, PHP 7.4, mongodb 1.7.4
I think you didn't run mongodb service in your OS.
I think you can find a good guide here:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/#run-mongodb-community-edition-as-a-windows-service
Just go to Task Manger of your window(Alt + Ctrl + delete), and start the MongoDB service.
it might me stop due to some reasons.
I have successfully installed Laravel and it running in a http://127.0.0.1:8000/. when I run the php artisan migrate it gives me the following error.
PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=plantshop", "root", "", []) /Projects/blog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
I can able to access my php myadmin using http://192.168.64.2 port but not by http://127.0.0.1:8000/ and one more thing is I have a lamp/htdocs/abc directory if I go to this link the page is not displaying and it says
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
I have tried changing the port number and directly pointed unix_socket to php myadmin but none of its working. what is wrong with my configuration? I am using a mac, could anyone help me out?
my .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=plantshop
DB_USERNAME=root
DB_PASSWORD=
Databse.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
You're searching for the database at the address 127.0.0.1, but you most likely configured it to use address 192.168.64.2. In your .env, you need to direct DB_HOST to your actual DB server, in this case, 192.168.64.2.
In your case MySQL server is not running. Please restart the MySQL server, The issue will resolve.
if you are using an ubuntu server then run the below command.
sudo /etc/init.d/mysql start
I am using laravel 5.7 and i am getting this error. But its working fine for older versions. i am using xamp with php 7.3.* . Here is my code
.env
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3308
DB_DATABASE=project
DB_USERNAME=root
DB_PASSWORD=
DB_DEFAULT=mysql
database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3308'),
'database' => env('DB_DATABASE', 'project'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
'engine' => null,
'default' => env('DB_DEFAULT', 'mysql')
],
Database is fine and i tried connecting with test.php file, its connecting fine but have problem with laravel 5.7
This error usually means the target machine was reachable, but is not listening on that port.
Some things to check:
The default port for MySQL is 3306, not 3308. Was this change intentional?
XAMPP often requires that you start the database manually. Is it online?
If the database is on your local machine, is it also configured to listen on 3308 instead of 3306 like your Laravel code?
Make sure your config isn't cached: php artisan config:clear
If the database is not on your local machine, then it could easily be a firewall setting causing the problem.
XAMPP to check your PORT number then change DB_PORT. I hope it works
After a lot of research about laravel 5.7 and xamp, i found the solution. It was basically the cache issue in the file bootstrap/cache/config.php .
It was reading this config cache file instead of my new file. I removed it and not its working fine. I am very thankful all of you.
everyone. I've recently encountered problems trying to deploy my laravel app to production-like server. So far I've been using it in homestead environment and everything was just fine.
My .env contains something like this:
APP_URL=http://public.server.url
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=myusername
DB_PASSWORD=mypassword
In mysql (running on port 3306) I've set up user 'myusername'#'localhost' with mypassword and indeed I can connect using
mysql -u myusername -p
Even 'php artisan migrate' command works and modifies my database properly.
config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'myusername'),
'password' => env('DB_PASSWORD', 'mypassword'),
//'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
Problem is my http controllers don't behave correctly. I am getting 500 server error when sending requests on my routes (no matter how dummy logic they do) and 404 not found when trying to reach non-existing route. Also nothing is appended in the log file. So I am guessing as far as registering routes my app works, but right after that it fails. Any suggestions? I would really appreciate any tips.