I am admittedly new to Laravel and back end development but I'm trying to open a Laravel project in my browser and am receiving an error message instead. I'm inheriting this project from a client who was working with another group of developers and they have since gone AWOL so I'm on my own to try to figure out what the issue is here.
The first error messages were:
**Warning:** require(C:\xampp\htdocs\vizzue\bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in **C:\xampp\htdocs\vizzue\bootstrap\autoload.php** on line **17**
**Fatal error:** require():Failed opening required 'C:\xampp\htdocs\vizzue\bootstrap/../vendor/autoload.php' (include_path='C:\xampp\php\PEAR') in **C:\xampp\htdocs\vizzue\bootstrap\autoload.php** on line **17**
To try to fix that error (from a solution I found on here), I ran composer install in the terminal to try to download the missing files. That switched the previous error messages to Whoops, looks like something went wrong. (Not very helpful).
So then I found more advice on here to get more detailed errors for my problem and was outputted a long list of errors under four separate headings.
Heading 1
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from `sessions` where `id` = hA02gV6ShpNslkw0N8Wrgm8QmyA0ZxoXfCNHsVTK limit 1)
Heading 2
PDOException
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
Heading 3
QueryException
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from `sessions` where `id` = hA02gV6ShpNslkw0N8Wrgm8QmyA0ZxoXfCNHsVTK limit 1)
Heading 4
PDOException
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
My PHP version is: PHP 7.2.28
My Laravel version is: Laravel Framework 5.4.36
Also, I have created a .env by copying the .env-example file.
EDIT:
I found the database information inside of the database/migrations directory so I actually DO have the database files. I'm still having an error, however. I ran php artisan generate:key and that was fine. But when I ran php artisan migrate I got the following error:
In Connection.php line 647:
could not find driver (SQL: select * from information_schema.tables where ta
ble_schema = homestead and table_name = migrations)
In Connector.php line 68:
could not find driver
first you have change the name of .env.example to .env then configure your database names settings in it. after that run composer install to install your project dependencies. make sure your webserver is up and running
You should configure your .env file to enable laravel access on your database. If you don't have one just copy the .env.example file and rename it to .env.
And then change the following properties:
DB_DATABASE=YOUR_DATABASE_NAME
DB_USERNAME=USER_NAME
DB_PASSWORD=PASSWORD
and then you should run php artisan key:generate to generate a new encryption key
EDIT
For your new problem you should run composer update and then composer require doctrine/dbal
if that does not work
You might need to comment out the following in your php.ini file.
;extension=pdo_mysql.so
As said here
Here is the basic installation process for a laravel project. I'll try to explain each of them so that you'll be able to figure out your mistakes on your own.
Getting the source code
You first need to get the source code of your app . Most of the time it's done via git . For instance , you'll need to type git clone https://github.com/miracuthbert/saas-boilerplate.git yoursaasproject to clone the repository hosted on github here
Install dependencies
Go to the root of the directory of the source code you previously got by typing
cd projectname.
The laravel framework uses composer as its dependencies manager. So you need to install it . (What you already did)
Then, from the root of your project, type the following intructions in the same order :
composer install
composer update
Environment configuration
The environment variables of the laravel framework are managed through a dot env file. An example file named .env.example is generally provided. You'll find it at the root of your project's folder. Assuming you are using a terminal with a bash prompt, type the following command to copy the .env.example to a .env file :
cp .env.example .env
After getting your new .env file, type
php artisan key:generate
to generate secure key in your .env file
Depending on the type of database management system you intend to use, here are some specific configurations to add in your .env file :
MySQL
If you choose MySQL as your DBMS, set the following values in your .env file :
DB_CONNECTION
DB_DATABASE
DB_USERNAME
DB_PASSWORD
homestead is the default DB_USERNAME and localhost is the default database host. Localhost is totally fine for working locally but you need to change your DB_USERNAME to an actual user of your DBMS with the corresponding password.
Sqlite
If you use sqlite, create a new sqlite database by typing :
`touch database/database.sqlite`
After setting up your database, enter the following command to create and populate tables :
php artisan migrate --seed
You may also need to edit other variables in the .env. The official laravel documentation is your best companion for that.
This is to the best of my knowledge what you need to do.
As for the driver error, here are few potential solutions adapted from an answer to a similar problem question asked here :
Be sure to configure the 'default' key in app/config/database.php
For mysql, this would be 'default' => 'mysql',
If you are receiving a [PDOException] could not find driver error, check to see if you have the correct PHP extensions installed. You need pdo_mysql.so and mysql.so installed and enabled. Instructions on how to do this vary between operating systems.
For Windows, the mysql extensions should come pre-downloaded with the official PHP distribution. Just edit your php.ini and uncomment the lines extension=pdo_mysql.so and extension=mysql.so
Also, in php.ini, make sure extension_dir is set to the proper directory. It should be a folder called extensions or ext or similar inside your PHP install directory.
There are other instructions given in the original answer but I'm only recommending those I understand. It was initially written for a postgres dbms.
If there are still problems, take a look at laragon. It's a bit like xamp (that you appear to be using on windows OS), but more powerful and easier to use.
The main backend languages and frameworks can be set up easily in few minutes. That includes php with laravel/symfony, ruby and Ruby on Rails, python and Django.
It allows you to manage multiple versions of the same programming language without any hassle and is fully extendable.
If you're new to Laravel or backend development, and working on the windows operating system, this is a must have.
I transferred a Laravel project based on moving Laravel project between computers
Everything was fine at the first look. I could install the composer without any problems, then I set my environmental variables in my .env such as database name, database user and so on.
When I started using the following command,
php artisan cache: clear
I got these two errors,
In Connection.php line 664:
SQLSTATE[HY000] [1045] Acess denied for user 'root'#'localhost' (using password: Yes) (SQL: select * from information_schema.tables where tabale_schema = *** and table_name = ****)
In Connector.php line 67:
SQLSTATE [HY000] [1045] Access denied for user 'root'#'localhost' (using password: Yes)
Further Information:
It seems .env has not been read by the application because when I browse the homepage of the app, I got Whoops error which shows environmental variable is empty.
I tested my database connection such as its username, password, and other parameters, I know they are working properly.
In the end, I attached a photo in order to elaborate on the issue.
Interestingly, in my .env file, DB_DATABASE value is "nlp" and DB_USERNAME equals "Javad" but as you can see in the errors, they are not working, and the Artisan assumes the root as the user!
After you move a Laravel project to another location, The first thing you have to do is regenerate APP_KEY in the .env file by running the command from your application root directory:
php artisan key:generate
After that, you reconfigure your cache:
php artisan config:cache
Additionally, make sure all your database parameters in your .env file and config/database.php are correct and the same as your previous Laravel setup - You can change them manually and then reconfigure your cache as shown above. If not (for instance, the database name is changed), you may have to rerun your database migrations and seeders again:
php artisan migrate
and
php artisan db:seed
I think the configuration files are not writable by the apache user, considering you are using apache. Make sure you have given write permission to bootstrap/cache for the user. This directory contains the cached configuration files.If that is the case the congratulations will be loaded from here and your previously used configuration will be loaded which may be causing the issue.
Also you need to give write permission to the storage directory too. As there is the log file and apache user needs to write on that too.
Step 1: Go to the project path project_name\bootstrap\cache folder and remove the marked file config.php from the mentioned folder.
Step 2: Run the following command
composer dump-autoload
php artisan clear-compiled
php artisan config:clear
php artisan cache:clear
php artisan config:cache
I hope that it will work now!
Open the .env file and edit it. Just set up correct DB credentials:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // Your Database Name
DB_USERNAME= // Your Database Username, If no username has been set then by default there is a root as a username
DB_PASSWORD= // Your Database Password, If no password is set on the database, clear it
After completion of .env edit please enter this command in your terminal for clear cache:
php artisan config:cache
If there is still the same error then try another possible solution.
I had also face the same problem, I tried all the possible answers in StackOverflow but nothing could help me, this solution worked on the first try:
If you are using the PHP's default web server (eg. php artisan serve) you need to restart your server after changing your .env file values.
I found this solution from here laravel.io (Read the solution of Byjml)
I want to use mysql database with my laravel 5.2 framework. I'm not able to access phpmyadmin after I run 'php artisan serve' and open a localhost page.
My .env file :
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=people
DB_USERNAME=pftest
DB_PASSWORD="pftest_2016#9"
After doing this, I ran 'php artisan migrate' and got following error:
[PDOException] could not find driver
Following which, I have installed php-mysql extension and checked for its presence in php.ini file. But still I'm getting following error :
[PDOException] SQLSTATE[HY000] [2002] Connection refused
So what is the issue and how to solve it ?
I was told to check for php.ini locaton. I did,and after I ran php --ini , I found the configuration file pointing at this place: /etc/php/7.0/cli/php.ini. Where is it suppose to point ?? how to know which path its suppose to point ??
I have been through the links below in order to find answer :
Set path to php.ini
How is php.ini related to php.ini-development and php.ini-production?
Overriding global php.ini file
Yor are not define port in your .env file Db_PORT=3306
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=people
DB_USERNAME=pftest
DB_PASSWORD="pftest_2016#9"
At the beginning of this file bootstrap/autoload.php yuo
can try this file
[PDOException] SQLSTATE[HY000] [2002] Connection refused
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.https://laravel.com/docs/5.2/artisan#usage
Answer is addition to Ayaz's answer,
In .env file, set
APP_ENV=local
DB_PORT=3306
and the do php artisian migrate --env="local"
Same is valid for development,production environment.
After upgrading to Laravel 5.2, none of my .env file values are being read. I followed the upgrade instructions; none of my config files were changed except auth.php. They were all working fine in previous version, 5.1.19
.env contains values such as
DB_DATABASE=mydb
DB_USERNAME=myuser
config/database.php contains
'mysql' => [
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
]
I get this error:
PDOException: SQLSTATE[HY000] [1045] Access denied for user 'forge'#'localhost' (using password: NO)
Clearly not pulling in my env config. This is affecting every single one of my config files, including third party such as bugsnag.
I also tried
php artisan config:clear
php artisan cache:clear
Update
Trying php artisan tinker
>>> env('DB_DATABASE')
=> null
>>> getenv('DB_DATABASE')
=> false
>>> config('database.connections.mysql.database')
=> "forge"
>>> dd($_ENV)
[]
I have tried installing a fresh copy of Laravel 5.2. I basically only copied in my app folder; no additional composer packages are included. Still having the same issue. I have other Laravel 5.2 projects on the same server that are working fine.
If any of your .env variables contains white space, make sure you wrap them in double-quotes. For example:
SITE_NAME="My website"
Don't forget to clear your cache before testing:
php artisan config:cache
php artisan config:clear
From the official Laravel 5.2 Upgrade Notes:
If you are using the config:cache command during deployment, you
must make sure that you are only calling the env function from within
your configuration files, and not from anywhere else in your
application.
If you are calling env from within your application, it is strongly
recommended you add proper configuration values to your configuration
files and call env from that location instead, allowing you to convert
your env calls to config calls.
Reference: https://laravel.com/docs/5.2/upgrade#upgrade-5.2.0
For me it has worked this in this order:
php artisan config:cache
php artisan config:clear
php artisan cache:clear
And I've tried all the rests without luck.
Wow. Good grief. It's because I had an env value with a space in it, not surrounded by quotes
This
SITE_NAME=My website
Changed to this
SITE_NAME="My website"
Fixed it. I think this had to do with Laravel 5.2 now upgrading vlucas/phpdotenv from 1.1.1 to 2.1.0
I had a similar issue in my config/services.php and I solved using config clear and optimize commands:
php artisan config:clear
php artisan optimize
You can solve the problem by the following recommendation
Recommendation 1:
You have to use the .env file through configuration files, that means you are requrested to read the .env file from configuration files (such as /config/app.php or /config/database.php), then you can use the configuration files from any location of your project.
Recommendation 2: Set your env value within double quotation
GOOGLE_CLIENT_ID="887557629-9h6n4ne.apps.googleusercontent.com"
GOOGLE_CLIENT_SECRET="YT2ev2SpJt_Pa3dit60iFJ"
GOOGLE_MAP="AIzaSyCK6RWwql0DucT7Sl43w9ma-k8qU"
Recommendation 3: Maintain the following command sequence after changing any configuration or env value.
composer dump-autoload
composer dump-autoload -o
php artisan clear-compiled
php artisan optimize
php artisan route:clear
php artisan view:clear
php artisan cache:clear
php artisan config:cache
php artisan config:clear
Recommendation 4: When the syntax1 is not working then you can try another syntax2
$val1 = env('VARIABLE_NAME'); // syntax1
$val2 = getenv('VARIABLE_NAME'); // syntax2
echo 'systax1 value is:'.$val1.' & systax2 value is:'.$val2;
Recommendation 5: When your number of users is high/more then you have to increase the related memory size in the server configuration.
Recommendation 6: Set a default probable value when you are reading .env variable.
$googleClinetId=env("GOOGLE_CLIENT_ID","889159-9h6n95f1e.apps.googleusercontent.com");
$googleSecretId=env("GOOGLE_CLIENT_ID","YT2evBCt_Pa3dit60iFJ");
$googleMap=env("GOOGLE_MAP","AIzaSyCK6RUl0T7Sl43w9ma-k8qU");
I missed this in the upgrade instructions:
Add an env configuration option to your app.php configuration file that looks like the following:
'env' => env('APP_ENV', 'production')
Adding this line got the local .env file to be read in correctly.
I had the same issue on local environment, I resolved by
php artisan config:clear
php artisan config:cache
and then cancelling php artisan serve command, and restart again.
Same thing happens when :port is in your local .env
again the double quotes does the trick
APP_URL="http://localhost:8000"
and then
php artisan config:clear
Also additional to what #andrewtweber suggested make sure that you don't have spaces between the KEY= and the value unless it is between quotes
.env file e.g.:
...
SITE_NAME= My website
MAIL_PORT= 587
MAIL_FROM_NAME= websitename
...
to:
...
SITE_NAME="My website"
MAIL_PORT=587
MAIL_FROM_NAME=websitename
...
I solved this problem generating a new key using the command: php artisan key:generate
if you did call config:cache during local development, you can undo this by deleting the bootstrap/cache/config.php file. and this is work for me.
In my case laravel 5.7 env('APP_URL') not work but config('app.url') works. If I add new variable to env and to config - it not works - but after php artisan config:cache it start works.
if you did call config:cache during local development, you can undo this by deleting the bootstrap/cache/config.php file. and this is work for me.
#Payal Pandav has given the comment above.
I want to tell a simple workaround. Just edit the config.php file in the bootstrap/cache/ folder. And change the credentials. This worked for me. Please don't delete this file since this may contain other crucial data in the production environment.
I experienced this. Reason was that apache(user www-data) could not read .env due to file permissions.
So i changed the file permissions to ensure that the server (apache) had read permissions to the file. Just that and boom, it was all working now!
Update:How to do this varies, depending on who owns the .env file, but assuming it belongs to the Apache www-data group, you can do this:
sudo chmod g+r .env
Modify it depending on your permission structure.
In my case, I needed to restart my Supervisord jobs (i.e. my queue workers). After doing so, a new environment variable I had added to my .env file was successfully pulled into my application.
Remember, queue workers, are long-lived processes and store the booted application state in memory. As a result, they will not notice changes in your code base after they have been started. So, during your deployment process, be sure to restart your queue workers. In addition, remember that any static state created or modified by your application will not be automatically reset between jobs.
Source: Official Laravel Docs - Queues
I know this is super old, but today I discovered another reason why my .env was not loaded:
I had a (commited) .env.local
I recently switched APP_ENV from dev to local
With L8 (and maybe before), what happens is that it tries to find .env.<APP_ENV> and if it finds it, uses it.
Fun fact: in my case, .env.local was a blue-print file with non-sensitive information and not meant to be directly used, but that's what happened.
Removing the .env.local led to Laravel looking for .env instead.
In my case I was using VSCODE and it turned out my .env file was auto-dectected by the IDE as a shell script file and not an Ini which was causing me the issue. It's a rare occurrence, but I hope it will save someone time.
For Laravel coder. We can use config() to solve this problem
in file "config/app.php":
'same_url' => env('SAME_URL', 'http://localhost'),
in your code base:
$sameURL = config('app.same_url').'/orders/';
If you've come here because you have multiple .env.* files and php artisan config:cache resulted in incorrect settings, it's because it (tried to) read the .env file and not the one specific to your environment. Try this instead (where CODE corresponds to .env.CODE):
APP_ENV=CODE php artisan config:cache
I made the mistake by doing dd/die/dump in the index.php file. This causes the system to not regenerate the configs.
Just do dump in view files will do. The changes to .env file update instantly.
I had some problems with this.
It seemed to be a file permission issue somewhere in the app - not the .env-file.
I had to
- stop my docker
- use chown to set owning-rights to my own user for the whole project
- start docker again
This time it worked.
If you're using sail environment right after you change your environment variable just restart a server, otherwise it's going to show the old value.
In my case (Laravel 7.x) it happen because I had set environmental variable on server. To be precise in Docker container.
And because environments variables are higher priority than .env file, nothing changes during .env file edit.
Check if you set the env variable on the server:
echo $VAR_NAME
Tried almost all of the above. Ended up doing
chmod 666 .env
which worked. This problem seems to keep cropping up on the app I inherited however, this most recent time was after adding a .env.testing. Running Laravel 5.8
I am trying to get a laravel5-example project working. One of the steps seems very basic but I do not know how to do it:
Create a database and inform .env
With laravel 5 my .env file looks like:
APP_ENV=local
APP_DEBUG=true
APP_KEY=B0ST6bRoqxVJ2JtUNPtittJup6mRJef2
DB_HOST=127.0.0.1
DB_DATABASE=laravel_base
DB_USERNAME=root
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file
When I try to seed the database I get an error:
$ php artisan migrate --seed
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
How do I create a database so I can run my laravel application on my mac? I have postgres installed. The default for this application is mysql ('default' => 'mysql') in config/database.php. If I change it to 'default' => 'pgsql' I get a different error:
$ php artisan migrate --seed
[PDOException]
could not find driver
I don't really care if I have mysql or psql database, just want it to work. Mysql is the default though, so might be better to stick with that. What are the commands to set up mysql/psql databases for laravel projects?
You should make sure:
You have in your php.ini PDO PostgreSQL enabled (extension=php_pdo_pgsql.dll not starting with ;)
Set in .env DB_CONNECTION to pgsql (or default do pgsql in config/database.php depending what specific version of Laravel you use (5.0 or 5.1/5.2))
If you won't be able to make it work, you should think of installing Laravel Homestead that has everything needed to develop Laravel applications