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.
Related
I'm working on a Laravel 5.8 project using Homestead. The project works fine with database port is set to 3306 but I can't run artisan commands. When I change database port to 33060 database stops working but artisan commands work. with port 3306 whe I run any artisan command I get this message
And when I switch to 33060 error disappears and can run artisan commands but database stops working
APP_DEBUG=true
APP_URL=http://127.0.0.1
APP_ENV=local
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33060
DB_DATABASE=forums
DB_USERNAME=homestead
DB_PASSWORD=secret
config/database.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'),
]) : [],
],
Never used Homestead myself, but check out this related question:
Strange behaviour Laravel Homestead Database Connection
It seems that the error could be relative to whether or not you are running the commands in the VM or on your physical machine.
By default, a MySQL server listens to the port 3306, that's why it works. But if you wish another port, then you have to change your MySQL server setup.
How to change the default port of mysql from 3306 to 3360
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.
So for some reason I get this error in my browser when using Laravel. I feel like I got everything set up correctly:
This is my .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=ictinder
DB_USERNAME=root
DB_PASSWORD=secret
This is my database.php file:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'ictinder'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'secret'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
This is a screenshots from my phpMyAdmin, it's Dutch so if you don't understand something, let me know
This is what the error looks like in my browser
Thank you for taking your time to help out, or at least read my question!
EDIT 1:
I already tried php artisan cache:clear and php artisan config:clear, both didn't work. I can use php artisan migrate.
If you are using vagrant to run your project. you have to change your db port into 33060 and change your db username into homestead
if you are running your program using php artisan serve, your db port should be 3306 into your db username
see the docs laravel homestead
Hope this can help you
What you need to do in your case is to remove the ictinder from your database and also from your .eve file. then recreate the ictinder again from where it was been remove, it's adventurous to leave the empty DB_PASSWORD like this DB_PASSWORD=, if your MySQL does not have a password, also remember that
If you are using the PHP's default web server (e.g. php artisan serve) you need to restart your server after changing your .env file values.
I just started a new Laravel project and I am having some database connectivity problem. First of all, I have only the User model which comes with the package. It has a migration as well. I updated my env file for the database path like this:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=laravel_project1
DB_USERNAME=root
DB_PASSWORD=''
The problem is, when I ran migrate command
php artisan migrate
It created those migrations in my database. But now when I am simply trying to do User::all(); I am having some trouble with this error:
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from `users`)
I have even cleared my config cache with this command:
php artisan config:clear
I don't understand what's wrong.
EDIT:
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'port' => env('DB_PORT', '3306'),
'database' => 'laravel_project1',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
This seems to solve the problem but I don't understand why env file is not working as it is the recommended way I believe.
The way Laravel's database config works is reading the /config/database.php file, so if you wan't Laravel to read your configuration from your .env file, you just have to make some changes in the /config/database.php for example:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'laravel_project1'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
So now the /config/database.php file will read your .env file and if it fails to read it will have the default config (Which is the second argument of each env() function above...)
To close this question, as Vasil Gerginski said in comments below my question. Restarting solved the problem.
When artisan starts, it caches your config. So even if you change it, it won't take affect until you restart artisan server.