I am using laravel 5.4, and I put all database details in .env file for connecting database, but unfortunately, this details can see my URL path, so what is the best solution for declare database details in Laravel,
thank you
this is the screen short of accessing .env file through URL
You can control it access by htaccess.
<Files .env>
order allow,deny
Deny from all
</Files>
This will prevent the access of .env file from url. Place this into your root htaccess file.
Thank you.
Related
Good day. I would like to seek for help regarding importing a .sql file on phpmyadmin on xampp. I can access my phpmyadmin via network however when I'm trying to import a .sql file it doesn't connect to the server. Export is possible.
This is my settings of the http-xampp.conf on xampp
<Directory "F:/xampp/phpMyAdmin">
AllowOverride AuthConfig
Order allow,deny
Require local
Require ip 10.10.10.100
Allow from all
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>
Hi common problem this is....this bug can occure from below:
1.if your importing file is more thn 250kb it won't import
2.another case is observe once inside ur file if there is any error like use database cmd and all....if its possible pls send ur error name let me see once
Thank u
I have a local database that I can connect to no problem using straight php
However, when I use the same settings in Laravel, I get an access denied error message
I checked stackoverflow for this type of error and most cases is solved by using 127.0.0.1. I made sure to try both 127.0.0.1 and localhost whenever asked for host/server.
Also, I made sure root had sufficient privileges
Here are my configuration settings, I tried to use different accounts, other than root, and also changing 127.0.0.1 to localhost (and the opposite)
database.php file
.env file
Hoping to learn this framework, I've heard great things. Appreciate any help
Sounds like you are trying the connection both with the script and laravel from a different Server like homestead.
Normally there are restrictions that you can't connect from remote (i.e. from a VM like homestead) to a certain server (i.e. localhost) with the root user.
Possible Solutions:
1. Create another user with the relevant permissions on mysql and connect with that one.
2. Look in the web for how to allow remote connections
3. Go the laravel way and use the homestead DB inside of the VM
First, are you sure you typed the password correctly?
Second, are you using the homestead virtual box? If yes, the default user is "homestead" and the pass is "secret" without quotes of course. Try putting that in the .env file
Is there any way to restrict access to phpmyadmin without adding a password to root (keeping root password as null). May be using Apache configuration files or other method?
As you enter username and password in phpmyadmin authentication screen, phpmyadmin directly try to access database from given username and passwords like
$conn = new mysqli(localhost, $username, $password);
If mysql returns any Databased associate with this user than phpmyadmin show complete information about this database.
So by default it's not possible to access phpmyadmin using root password null.
But still there are two option
Create new Mysql user with all database access privilege keeping your root password null
Phpmyadmin is open-source so make changes as per your need.
Sure, you can accomplish this with the normal Apache .htaccess authentication.
For instance, your .htaccess can contain:
AuthUserFile /home/Sanjay/.htpasswd-phpmyadmin
AuthName "My custom phpMyAdmin authentication"
AuthType Basic
Require valid-user
Then you just have to create the file /home/Sanjay/.htpasswd-phpmyadmin (you can use whatever path you wish here, in fact it may not be ideal to put it under your user home directory) using the htpasswd command-line program or one of the many online tools. Make sure both files are readable by the webserver and you should be all set.
Trying to understand why is happening this. When I query a different domain that I setted up on hosts file is like the data from the database is not being retrieved. I have a personal project with angular, spring-boot and mysql. Angular query an API that is exposed by Spring that is querying mysql. When I run the project and I go to the URL localhost:8080 I get all the information, but when I go to mysite.com:8080 seems that all the data from mysql is not retrieved.
I modified the file hosts like this
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 myownproject.com
and I granted all the privileges on mysql to the database mydb for the user#mysite.com
here is my spring configuration for the database
#override the spring parameter 'create-drop', 'create' creates the schema deleting the previous data
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.database=H2
database.driver=com.mysql.jdbc.Driver
database.url=jdbc:mysql://localhost:3306/expediente_electronico
database.username=user
database.password=user
Thank you
Finally I could fix the problem. I post the answer just in case is useful for someone else.
In the front end (in angular) I have http requests that have the url
http://localhost:8080/restservice
I changed this angular request to this url
http://myownproject.com:8080/restservice
Just works fine (obviously stop working for the previous URL). I am not sure, but I can imagine that this was because Spring allow the request for the given URL in the browser, but then when Angular tried to request a different URL wasn't allowed, that's why the data wasn't retrieved.
I have a cake installation on a webserver and a database on a separate server.
I am able to connect to the database remotely via shell, but my cake gives
Error: Mysql requires a database connection
Error: Confirm you have created the file : app/Config/database.php.
Notice: If you want to customize this error message, create app/View/Errors/missing_connection.ctp.
I checked and PDO is setup, mod_rewrite is enabled and I have a similar setup on development server running properly. I checked core.php and it echoes proper base site url, and database.php echoes proper database selection.
Any ideas what may be causing it?
Trying to cover all of the possibilities...
With regard to the database.php file, make sure that the database credentials are being set to the $default variable and not $test, unless of course you're trying to run database unit tests of course.
The file that handles all of the initializing is the webroot's index.php file. You'll want to verify that all paths within that file are using the proper paths. If all you did was extract the CakePHP framework without any folder rearrangements, it should be all correct.
You mention that you checked mod_rewrite is enabled - did you do this with a phpinfo() call to a file located on the same (sub)domain just to verify the settings in the same location?
Although not related to the errors you're experiencing, you'll also want to verify that the external DB allows connection from your webserver's IP.