php artisan migrate - Laravel - php

As soon, i press Enter 'php artisan migrate' command on ubuntu terminal. Error coming like:- [PDOException] Could Not Find Driver
I'm not able to fix this problem as i'm new to it.
Please help me to fix this issue.

Yo should be enable the PDO extension for you Database Manager in you php.ini
;extension=php_pdo_firebird.dll
;extension=php_pdo_mssql.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
extension=php_pdo_pgsql.dll //In my Case the extension enable is for pgsql
;extension=php_pdo_sqlite.dll
For enable you should delete the ; char in the line of the extension
restart the server and voila

I made changes in "Project-Folder-Name/config/database.php". And, it worked. Added 'unix_socket' => '/opt/lampp/var/mysql/mysql.sock',
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'DatabaseName'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => '/opt/lampp/var/mysql/mysql.sock', //Your sock got from above
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],

I think you have a seperated configuration file (php.ini) for your CLI.
Try to execute php -i | grep php.ini in your console. And enable the required modules in that file.
It should return something like this:
sander#sander-Laptop:~$ php -i | grep php.ini
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
As you can see it uses another php.ini file then what the phpinfo(); returns
Open that file and enable the required extensions there
so change the lines of the extensions that you require:
;extension=extension.so to extension=extension.so
Also a tip: If you use Laravel you can use the Homestead (vagrant, virtualbox) which is an virtual machine complete preinstalled for you laravel application
http://laravel.com/docs/5.1/homestead

Related

Laravel - Migration to PGSQL error

i started a project with Laravel and PostgreSQL but i can not make the migration.
[Illuminate\Database\QueryException]
could not find drive (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations)
[PDOException]
could not find driver
I checked my php.ini and i've uncomment the lines:
extension=php_pdo_pgsql.dll
extension=php_pgsql.dll
I restarted the server and when i tried again, the console gives me the same error. I checked my .env file in laravel and it's okay (i think)
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=laravelPSQL
DB_USERNAME=postgres
DB_PASSWORD=password
and also i checked the database.php and it's okay.
'default' => env('DB_CONNECTION', 'pgsql'),
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
]
The last thing i did, was make a file with the function phpinfo() to see if the files of pgsql was enabled and yes.
Honestly i don't know what is happening. I tried in Wamp64, and XAMPP...and nothing. PD. I using Windows 10
I faced the same problem but I solved it by editing my XAMP php.ini file
In php.ini file I un-comment this line:
extension=pgsql
and then it starts working.

connecting postgres with laravel

Hello i'm trying to connect laravel 5.4 with postgres, after updating the database configuration file and running php artisan migrate, the following error appears:
[Illuminate\Database\QueryException]
could not find driver (SQL: select * from information_schema.tables where t
able_schema = public and table_name = migrations)
[PDOException]
could not find driver
this is my .env file
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=Portail
DB_USERNAME=php
DB_PASSWORD=php
and this is my database.php file
'default' => env('DB_CONNECTION', 'pgsql'),
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'Portail'),
'username' => env('DB_USERNAME', 'php'),
'password' => env('DB_PASSWORD', 'php'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer', ],
and i use phpPgAdmin normally
sudo apt-get install php-pgsql. This is the command to install php pgsql driver in linux
I had a similar problem using on Ubuntu18.04 using php7.4
Solution:
First check you PHP version with php -v, in my case the version come out to be php7.4 so installed the necessary driver with apt-get install php7.4-pgsql
Finally restart the PHP server
I found the solution there are two php.ini files
C:\wamp64\bin\apache\apache2.4.9\bin
C:\wamp64\bin\php\php7.0.10
i must do uncommented php_pdo_pgsql.dll and php_pgsql.dll in the two files
thanks for your help all

Laravel to SQL Server (sqlsrv). [PDOException] could not find driver

Intro. My laravel app was using mysql, now it needs to be hosted in the network of the company I am working ( I am a remote-worker). And this company are Microsoft peeps, so I need to integrate the laravel to their SQL Server.
I have this in my .env
DB_CONNECTION=sqlsrv
DB_HOST=ip.address.of.server
DB_PORT=3306
DB_DATABASE=my_db
DB_USERNAME=my_username
DB_PASSWORD=my_password
After using the php artisan migrate
Error:
[PDOException]
could not find driver
I am using Ubuntu, a remote box dedicated for me (from my employer). I have tried using sql server in my laravel app before (using my Windows PC). As far as I remember, I edited some texts in the xampp php.ini. As a newbie Linux user, it is too hard for me (since i was using only CLI).
EDITED ( new version )
So I already got the connectivity from Ubuntu to the Database server. I used the the sqlcmd -S <host> -U <username>
and I tested the queries (such as SELECT * from users_data) and it works.
Now, I modified the config/database.php and I added this.
'sqlsrv' => [
'driver' => 'MSSQL',
'host' => env('DB_HOST', 'host.of.the.database'),
'database' => env('DB_DATABASE', 'my_database'),
'username' => env('DB_USERNAME', 'my_username'),
'password' => env('DB_PASSWORD', 'my_pass'),
'port' => '1433',
'prefix' => '',
],
but I got an Error:
[InvalidArgumentException]
Unsupported driver [MSSQL]
"MSSQL" is the name I use to configure the FreeTDS.
For those who came after
Make sure of the PHP version you use (for me homestead currently using php 7.1, so I installed php7.1-sybase)
sudo apt-get install freetds-common freetds-bin unixodbc php7.1-sybase
And the driver is
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'port' => env('DB_PORT', '1433'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
]
You can make sure that the connection information is correct using tsql
TDSVER=8.0 tsql -H Host -U Username -D DatabaseName -p 1433 -P Password
Note: After that you need to re-run command php artisan serve.
Also had the could not find driver error, resolved the issue after installing following packages:
sudo apt-get install freetds-common freetds-bin unixodbc php5-sybase
However i am using the sqlsrv driver, here's my config/database.php:
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
When installing sybase, ensure that it matches up with the version that your VM uses.
Run
php --version
and then install the right sybase version:
sudo apt-get install freetds-common freetds-bin unixodbc php7.#-sybase
If you're getting encoding errors, you'll need to update your freedts and php.ini configuration as well. Change the /etc/freetds/freetds.conf so that it looks like:
[global]
# TDS protocol version
tds version = 8.0
# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
; dump file = /tmp/freetds.log
; debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
client charset = UTF-8
# A typical Sybase server
[egServer50]
host = symachine.domain.com
port = 5000
tds version = 5.0
# A typical Microsoft server
[egServer70]
host = ntmachine.domain.com
port = 1433
tds version = 7.0
[mssql]
host =
Port = 1433
tds version = 8.0
Add this to your php.ini:
client charset = UTF-8
Always run sudo apt-get upgrade before trying to run these commands.
Thanks, these answers helped great. Please let me explain what I did using laravel/homestead vagrant box version 7.1.0 and PHP 7.3.
I ran the command sudo apt-get install freetds-common freetds-bin unixodbc php7.3-sybasein my vagrant homestead virtual box.
This command prompted me twice to either keep the local php.ini configuration file or use the "installer's version". I chose to use the installer's version both times, and everything worked great. Here is my database.php file in my laravel config folder. Also, I set default => env('DB_CONNECTION', 'sqlsrv')

PDOException SQLSTATE[HY000] [2002] No such file or directory

I believe that I've successfully deployed my (very basic) site to fortrabbit, but as soon as I connect to SSH to run some commands (such as php artisan migrate or php artisan db:seed) I get an error message:
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
At some point the migration must have worked, because my tables are there - but this doesn't explain why it isn't working for me now.
One of simplest reasons for this error is that a MySQL server is not running. So verify that first. In case it's up, proceed to other recommendations:
Laravel 4: Change "host" in the app/config/database.php file from "localhost" to "127.0.0.1"
Laravel 5+: Change "DB_HOST" in the .env file from "localhost" to "127.0.0.1"
I had the exact same problem. None of the above solutions worked for me. I solved the problem by changing the "host" in the /app/config/database.php file from "localhost" to "127.0.0.1".
Not sure why "localhost" doesn't work by default but I found this answer in a similar question solved in a symfony2 post. https://stackoverflow.com/a/9251924
Update:
Some people have asked as to why this fix works so I have done a little bit of research into the topic. It seems as though they use different connection types as explained in this post https://stackoverflow.com/a/9715164
The issue that arose here is that "localhost" uses a UNIX socket and can not find the database in the standard directory. However "127.0.0.1" uses TCP (Transmission Control Protocol), which essentially means it runs through the "local internet" on your computer being much more reliable than the UNIX socket in this case.
The error message indicates that a MySQL connection via socket is tried (which is not supported).
In the context of Laravel (artisan), you probably want to use a different / the correct environment. Eg: php artisan migrate --env=production (or whatever environment). See here.
I got the same problem and I'm running Mac OS X 10.10 Yosemite. I have enabled the Apache Server and PHP that already comes with the OS. Then I just configured the mCrypt library to get started. After that when I was working with models and DB I got the error:
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
The reason I found is just because PHP and MySQL can't get connected themselves.
To get this problem fixed, I follow the next steps:
Open a terminal and connect to the mysql with:
mysql -u root -p
It will ask you for the related password. Then once you get the mysql promt type the next command:
mysql> show variables like '%sock%'
You will get something like this:
+-----------------------------------------+-----------------+
| Variable_name | Value |
+-----------------------------------------+-----------------+
| performance_schema_max_socket_classes | 10 |
| performance_schema_max_socket_instances | 322 |
| socket | /tmp/mysql.sock |
+-----------------------------------------+-----------------+
Keep the value of the last row:
/tmp/mysql.sock
In your laravel project folder, look for the database.php file there is where you configure the DB connection parameters. In the mysql section add the next line at the end:
'unix_socket' => '/tmp/mysql.sock'
You must have something like this:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'SchoolBoard',
'username' => 'root',
'password' => 'venturaa',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'unix_socket' => '/tmp/mysql.sock',
),
Now just save changes, and reload the page and it must work!
I encountered the [PDOException] SQLSTATE[HY000] [2002] No such file or directory error for a different reason. I had just finished building a brand new LAMP stack on Ubuntu 12.04 with Apache 2.4.7, PHP v5.5.10 and MySQL 5.6.16. I moved my sites back over and fired them up. But, I couldn't load my Laravel 4.2.x based site because of the [PDOException] above. So, I checked php -i | grep pdo and noticed this line:
pdo_mysql.default_socket => /tmp/mysql.sock => /tmp/mysql.sock
But, in my /etc/my.cnf the sock file is actually in /var/run/mysqld/mysqld.sock.
So, I opened up my php.ini and set the value for pdo_mysql.default_socket:
pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock
Then, I restarted apache and checked php -i | grep pdo:
pdo_mysql.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock
That fixed it for me.
The answer from #stuyam solved the "No such file or directory" issue for me
Short answer: Change "host" in the /app/config/database.php file from "localhost" to "127.0.0.1"
But then I had a "Connection refused" error. If anyone had the same issue, my solution for this was to update the app/config/local/database.php file so the port is 8889:
'mysql' => array(
'driver' => 'mysql',
'host' => '127.0.0.1',
'port' => '8889',
'database' => 'databaseName',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
In my case i had no problem at all, just forgot to start the mysql service...
sudo service mysqld start
If you are using Laravel Homestead, make sure you're calling the commands on the server.
homestead ssh
Then simply cd to the right directory and fire your command there.
It worked after I change from DB_HOST=localhost to DB_HOST=127.0.0.1 at .env file
This is because PDO treats "localhost" host specially:
Note: Unix only: When the host name is set to "localhost", then the
connection to the server is made thru a domain socket. If PDO_MYSQL is
compiled against libmysqlclient then the location of the socket file
is at libmysqlclient's compiled in location. If PDO_MYSQL is compiled
against mysqlnd a default socket can be set thru the
pdo_mysql.default_socket setting.
(from http://php.net/manual/en/ref.pdo-mysql.connection.php)
Changing localhost to 127.0.0.1 will "force" the use of TCP.
Note: mysqli_connect is working fine with localhost.
Add mysql.sock path in database.php file like below example
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
Eample
'mysql' => [
'driver' => 'mysql',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '8889'),
Mamp user enable option Allow network access to MYSQL
Building on the answer from #dcarrith ...
Instead of editing the config files, I created an alias in the location that PHP is looking that connects to the real mysql.sock. (source)
Just run these two commands (no restart needed):
mkdir /var/mysql
ln -s /tmp/mysql.sock /var/mysql/mysql.sock
Step 1
Find the path to your unix_socket, to do that just run netstat -ln | grep mysql
You should get something like this
unix 2 [ ACC ] STREAM LISTENING 17397 /var/run/mysqld/mysqld.sock
Step 2
Take that and add it in your unix_socket param
'mysql' => array(
'driver' => 'mysql',
'host' => '67.25.71.187',
'database' => 'dbname',
'username' => 'username',
'password' => '***',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'unix_socket' => '/var/run/mysqld/mysqld.sock' <-----
),
),
Hope it helps !!
I'm running on MAMP Pro and had this similar problem when trying to migrate (create db tables). Tried a few of these mentioned suggestions as well but didn't do it for me.
So, simply (after an hour googling), I added two things to the /config/database.php.
'port' => '1234',
'unix_socket' => '/path/to/my/socket/mysqld.sock'
Works fine now!
Just i do one change in .env file
I have following line of code.
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=database_name
DB_USERNAME=root
DB_PASSWORD=
Change host name localhost to 127.0.0.1
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_name
DB_USERNAME=root
DB_PASSWORD=
That is work in my case because that can't find any hostname like localhost
And after changing hostname write following command
php artisan config:clear
php artisan migrate:install
php artisan migrate
I had this problems when I was running my application using docker containers.
The solution was put the name of the MySQL service container I was using in docker_compose.yml on DB_HOST. In my case, it was db :
DB_HOST=db
Hope it helps.
I ran into this problem when running PHPUnit in Elixir/Gulp, and Homestead as my Vagrant enviroment.
In my case I edited the .env file from DB_HOST=localhost to DB_HOST=192.168.10.10 where 192.168.10.10 is the IP of my Vagrant/Homestead host.
Check your port carefully . In my case it was 8889 and i am using 8888.
change "DB_HOST" from "localhost" to "127.0.0.1" and vice versa
I had similar problems accessing my Drupal website. I fixed it by opening the command line, and restarting my MySQL server or service:
service mysqld restart
This should work. If it doesn't, restart your local webserver:
service httpd restart
That should be enough. Hope it works for other environments, too. Note that these commands generally require superuser privileges.
I had the same problem using Docker and MySQL service name db in docker_compose.yml file:
I added the following in the .env file:
DB_HOST=db
you should also assure that your host is discoverable from the php app.
It was because PHP didn't figure out which host to use to connect.
I got the same problem in ubuntu 18.04 with nginx. By following the below steps my issue has been fixd:
First open terminal and enter into mysql CLI. To check mysql socket location I write the following command.
mysql> show variables like '%sock%'
I got something like the below :
+-----------------------------------------+-----------------------------+
| Variable_name | Value |
+-----------------------------------------+-----------------------------+
| mysqlx_socket | /var/run/mysqld/mysqlx.sock |
| performance_schema_max_socket_classes | 10 |
| performance_schema_max_socket_instances | -1 |
| socket | /var/run/mysqld/mysqld.sock |
+-----------------------------------------+-----------------------------+
4 rows in set (0.00 sec)
In laravel project folder, look for the database.php file in the config folder. In the mysql section I modified unix_socket according to the above table.
'mysql' => array(
'driver' => 'mysql',
'host' => '127.0.0.1',
'database' => 'database_name',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'unix_socket' => '/var/run/mysqld/mysqld.sock',
),
Now just save changes, and reload the page and it worked.
As of Laravel 5 the database username and password goes in the .env file that exists in the project directory, e.g.
DB_HOST=127.0.0.1
DB_DATABASE=db1
DB_USERNAME=user1
DB_PASSWORD=pass1
As you can see these environment variables are overriding the 'forge' strings here so changing them has no effect:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
More information is here https://mattstauffer.co/blog/laravel-5.0-environment-detection-and-environment-variables
solved
in my case it was a logic issue in code, the connection values are in a if statement:
if($_SERVER['HTTP_HOST'] == "localhost")
so the solution was to add a pipe and add 127.0.0.1, that solved the problem for me
if($_SERVER['HTTP_HOST'] == "localhost" || $_SERVER['HTTP_HOST'] == "127.0.0.1")
If you are using Laravel Homestead,
here is settings
(include Vagrant-Virtual Machine)
.bash-profile
alias vm="ssh vagrant#127.0.0.1 -p 2222"
database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Terminal
vm
vagrant#homestead:~/Code/projectFolder php artisan migrate:install
Attempt to connect to localhost:
SQLSTATE[HY000] [2002] No such file or directory
Attempt to connect to 127.0.0.1:
SQLSTATE[HY000] [2002] Connection refused
OK, just comment / remove the following setting from my.cnf (on OS X 10.5: /opt/local/etc/mysqlxx/my.cnf) to obtain:
[mysqld]
# skip-networking
Of course, stop and start MySQL Server.
If anyone are still looking for the answer, just check your .env file. For some reason laravel create a .env.example file, so all this answers didn't work for me. I fixed my issue renamming .env.example to .env
This happened to me because MySQL wasn't running. MySQL was failing to start because I had a missing /usr/local/etc/my.cnf.d/ directory.
This was being required by my /usr/local/etc/my.cnf config file as a glob include (include /usr/local/etc/my.cnf.d/*.cnf).
Running mkdir /usr/local/etc/my.cnf.d, and then starting MySQL, fixed the issue.
In my case, I was running php artisan migrate on my mac terminal, when I needed to ssh into vagrant and run it from there. Hope that helps someone the headache.
In my case I had to remove the bootstrap/cache folder and try it again.
My cenario was after a server migration.
When using a VirtualMachine make sure you ssh into that machine and navigate to your App folder and call the php artisan migrate command from there.

Setting up Laravel on a Mac php artisan migrate error: No such file or directory [duplicate]

This question already has answers here:
MySQL connection not working: 2002 No such file or directory
(23 answers)
Closed 7 years ago.
Pulled a perfectly working laravel project from a git into a mac running MAMP. Project ran perfectly on a linux machine.
composer install
php artisan migrate, got the following error:
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
NB:
php -v is 5.5 and mysql -v is 5.5 from the terminal
Here is part of my config/database.php
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'essays',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
I tried replacing localhost with 127.0.0.1 with no avail. Kindly help..
Edit:
I added these three lines in my php.ini
mysql.default_socket = /var/run/mysqld/mysqld.sock
mysqli.default_socket = /var/run/mysqld/mysqld.sock
pdo_mysql.default_socket = /var/run/mysqld/mysqld.sock
I also added this symlink:
sudo mkdir /var/mysql
cd /var/mysql && sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
But that didnt solve. I also pulled a fresh new laravel project from git and ran into the same error after composer install then php artisan migrate
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
The mac version is 10.7.4
If you are using MAMP be sure to add the unix_socket key with a value of the path that the mysql.sock resides in MAMP.
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'database' => 'database',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
Do not assume your unix_socket which would be different from one to another, try to find it.
First of all, get your unix_socket location.
$ mysql -uroot -p
Enter your mysql password and login your mysql server from command line.
mysql> show variables like '%sock%';
+---------------+---------------------------------------+
| Variable_name | Value |
+---------------+---------------------------------------+
| socket | /opt/local/var/run/mysql5/mysqld.sock |
+---------------+---------------------------------------+
Your unix_soket could be diffrent.
Then you got 2 solution to solve your issue:
(1) Change your config/database.php
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'essays',
'username' => 'root',
'password' => 'root',
'unix_socket' => '/opt/local/var/run/mysql5/mysqld.sock', //Your sock got from above
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
(2) Change your php.ini, find your php.ini file from
<? phpinfo();
You maybe install many php with different version, so please don't assume your php.ini file location, get it from your 'phpinfo';
Change your php.ini:
mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock
pdo_mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
Then restart your apache or php-fpm.
Had the same problem, but it's working for me now.
If anybody is still having problems, try this:
Make sure your bootstrap/start.php contains your actual hostname, not the name of your virtual host. Enter hostname in the terminal to get your hostname. As it's an array I believe you can enter both your hostname and the name(s) of your virtual host(s).
Replace "localhost" with "127.0.0.1".
If you are using XAMPP, the solution is:
'mysql' => array(
'driver' => 'mysql',
'unix_socket' => '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock',
'host' => 'localhost'
)
This works for me in Laravel 5.0, change the DB_HOST=127.0.0.1:33060 in .env file.
Others answers don't work...
If you are using Laravel 5.1.11 version + MAC + MAMPP
you have to add "Unix_socket " in file "yourapp"/app/config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Unix_socket param was added to above mysql config drive.
For Laravel 5.0+ change localhost to 127.0.0.1 in your .env file as well before you go playing around with Unix Sockets etc - this worked for me.
Noobs beware: For anyone using Laravel 5 and using older learning material be aware that there was quite a marked shift in folder structure from previous versions though this seems to be for the better- check out this article https://mattstauffer.co/blog/laravel-5.0-directory-structure-and-namespace
Another solution is to add the port number in the host key. In this case MAMP uses the 8889 by default:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost:8889',
'database' => 'essays',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),

Categories