I created my first App, using Laravel in the Backend. Everything was running on my localhost and I deployed everything to my Netcup Webhosting Server.
I run composer install successfully, generated the API key by using php artisan key:generate --ansi and set up my .env file. The File looks like:
APP_NAME="App Name"
APP_ENV=prod
APP_KEY=base64_key
APP_DEBUG=false
APP_URL=https://xx.xxxxx.de
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME="db_user"
DB_PASSWORD="db_user_password"
The I want to create all the database tables by using php artisan migrate. I tripple checked the values set in the .env and red a lot of solutions of other posts, but nothing worked. I keep getting the following error:
I already added quotes to DB_User and Pasword in .env file. I restarted the server several times and cleaned the cache.
It looks like some problems with auth on the Netcup Web hosting Server. Can you check list of user with access to db_name? Besides, by screenshoot I guessing that hosting add prefix ("k177581_") for db_name and db_user
Solved the issue:
As #N69S correctly suggested it was related to Netcup. For any other Netcup user the following solution.
Netcup devides its Webhosting and Database. Therefore you need to put you Database IP into your .env file. That can be found in the connection data.
Related
I just cloned a website project on GitHub. When I want to migrate, an error like this appears. I have filled in DB_DATABASE and DB_USERNAME many times but it has no effect
.env
APP_NAME="Simple Company Profile"
APP_ENV=local
APP_KEY=base64:HLQuGR0tT28YYt4eg/GPPQpW4L+mii71zIx65nFNxDE=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=cms_pasti
DB_USERNAME=
DB_PASSWORD=
there is also a simple console here to create an admin account, but that also doesn't work
I don't think that cloning a project will automatically replicate the database. You have to create it with a script/sql. Which should be part of the Github project.
So,
Either find the schema and create the database and tables manually.
Or find a sql backup and restore it
You have just cloned the repository but, that doesn´t mean that is ready to run. You have to create a database and connect with it.
Use PHPMyAdmin or any other Database management solution (HeidiSQL, MySQL WorkBench) in order to check if your Database credentials are working.
Another thing that is probably happening is that you have to create the database 'cms_pasti' first and then fill the .env:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=cms_pasti
DB_USERNAME=
DB_PASSWORD=
With the proper settings.
When done, you have to run in your console:
PHP artisan migrate
This command will do the migrations to build the database structure. But you have to be sure that the database is already created.
I'm trying to access a database (which exists on a different server) on my Laravel application. I keep getting the following error: SQLSTATE[HY000] [2002] Permission denied
My .env file is set up as follows (changed a bit to protect privacy):
DB_CONNECTION=mysql
DB_HOST= IP_ADDRESS
DB_PORT=3306
DB_DATABASE=DB_NAME
DB_USERNAME="laravel_user"
DB_PASSWORD="password"
I'm not sure if this is important or not but I can access the web server's database if I go to the link IP.ADDRESS/phpmyadmin
My web.php file is as follows:
Route::get('/test', function(){
return DB::select("select * from umts_list");
});
Additionally, I also went to IP_ADDRESS/phpmyadmin (where my database exists) and added a new user called laravel_user with the ability to SELECT all data and saved it with the 'password' as its password.
My attempt: I tried whatever I mentioned above and also cleared the cache since I made changes to the .env file by entering the following commands:
php artisan config: clear
php artisan cache: clear
Any help would be appreciated. Thank you.
Edit 1: On phpMyAdmin, I made sure to add the user as depicted by the following picture:
PhpMyAdmin User Account
Additionally, I also checked the port number on phpMyadmin and it is 3306 as depicted by the following image:
Port Number
just in case anyone else stumbles upon this post in the future, it turns out that I did not have to create an SSH tunnel or whitelist the IP. The problem was actually with SELinux. This post was the solution: Laravel permission denied on remote Mysql server (AWS aurora)
Specifically, I ran the command: sudo setsebool -P httpd_can_network_connect_db=1
This worked perfectly and it was actually blocking connection to remote databases.
First I will explain my setup: I run Laravel in WSL (Windows Subsystem for Linux) and I have XAMPP on Windows.
What I'm trying to do is to run MySQL service on XAMPP and connect it with my Laravel project. I have modified my .env file setting the root password and I have created the "laravel" database with phpMyAdmin.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=mypassword
With this setup I tried to run in WSL
php artisan migrate
But I got this error
SQLSTATE[HY000] [2002] Connection refused
Then I changed the DB_HOST to localhost, that is a common solution for this, but then I got this other error.
SQLSTATE[HY000] [2002] No such file or directory
Now I have no idea what else to do. I got stucked. Any help would be appreciated.
It seems you are running MySQL via XAMPP, under Windows, not in Linux (Ubuntu?). You should be running MySQL in the WSL2.
See this---
WSL stack overflow issue
After a lot of digging, I found a solution.
First, cannot use localhost to communicate with XAMMP, but it should use $(hostname).local. You can test it by typing ping $(hostname).local in the WSL terminal: the keyword will be replaced by the host name and IP.
Second point, the app will be connecting from a "foreign" address, not localhost. Therefore, go to your phpMyAdmin interface, select the MySQL user that Flask is using, go to "Login information" and select "Any Host: %" in the "Host" section. I found a guide here.
Note that now this user can be accessed by your network, so maybe choose a secure password.
More specifically, I had a similar problem with a python Flask app running in WSL, with XAMPP running in Windows. In the app, I had to change my SQLALCHEMY_DATABASE_URI variable to account for the different localhost. The variable should look something like this:
export SQLALCHEMY_DATABASE_URI="mysql+pymysql://sql_user:sql_password#$(hostname).local/YOUR_DATABASE"
I have 2 Laravel applications running on the same server. The server is Apache 2.4 and I have vhosts set up to serve each application on a different domain.
The first application is an API and it's .env file is set up like this:
APP_ENV=production
APP_KEY=YYYYYYYYYYYYYYYYYY
APP_DEBUG=false
APP_LOG_LEVEL=debug
APP_URL=https://notify.mysite.com
APP_DOMAIN=notify.mysite.com
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=notify
DB_USERNAME=YYYYYYYYYYYYYYYYYY
DB_PASSWORD=YYYYYYYYYYYYYYYYYY
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
The second application is a UI that among other things, utilizes the API from the first application. Its .env file is set up like this:
APP_ENV=local
APP_KEY=XXXXXXXXXXXXXX
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=https://asapps.mysite.com
APP_DOMAIN=asapps.mysite.com
APP_VERSION=1
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=asapps
DB_NOTIFY_DATABASE=notify
DB_FLIGHT_DATABASE=flights
DB_USERNAME=XXXXXXXXXXXXXX
DB_PASSWORD=XXXXXXXXXXXXXX
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
I can send messages to my API from my Swagger editor, from Postman, and from other servers and everything works as expected.
My second application by itself also works as expected.
However, if my second application sends a request to the API, the API application throws this error:
exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'asapps.preprocessor_config' doesn't exist'
in C:\notify\vendor\laravel\framework\src\Illuminate\Database\Connection.php:332
WTH?
The database for the API is set to DB_DATABASE=notify and it definitely does properly use that connection when I send messages from other servers. So why the heck is it trying to use the second application's database
connection when I call the API from that app??? Its almost like it's caching the DB connection and trying to keep using that same one.... How do I stop that?
Table 'asapps.preprocessor_config' doesn't exist'
After more digging (read frantic googling), I found the problem and solution here
The bottom line, when site A accepts a request, php loads it's .env variables for the entire length of the http request. During that request, when site A calls site B, since they are on the same server running the same php, php is still using the .env from site A and does not separately load site B's .env file at all.
The author's better explanation:
The .env file with the variables was created so that people would not push their credentials to github repositories and other places where they may share the source.
Now, being environment variables they become system wide for the entire duration of the http request (in this case script execution). The point is that you got a long running script.
To find a definitive solution you could go one of the three ways.
....
'namespace' the ENV variables.
I've looked through a bunch of other threads but can't find a solution. My .env file is set up correctly and I can access the database fine through the php artisan tinker command. However when I spin it up on the browser I get access denied. I've changed the password a few different times to make sure I was putting in the correct username/password but still nothing.
APP_ENV=local
APP_DEBUG=true
APP_KEY=rUzE03agyabewGSbhch7QFKE0jqZqifO5
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=username
DB_PASSWORD=password
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
I have reloaded the virtualbox and even forced provisioned it, ran php config:clear, stop and started the mysql db. tried different users/passwords/dbs, switched localhost to 127.0.0.1, followed the documentation on laravel.com. Nothing has worked.
I'm at a loss...help would be appreciated.
The tutorials were not very clear on this point but basically I had to access mysql on the VM by using "vagrant ssh" and then logging onto mysql through the cli to create the correct user. Also all the migrate commands needed to be executed while logged into the VM through the ssh.
While the artisan commands will add the appropriate "make:' objects in either only the VM cli will allow you to access the correct database. Hopefully this post will save someone a day of sifting through a lot of posts about the .env file.