I don't know how I can do this.
I test my web app (php+mysql) in localhost and at the same time I test in Internet too. But I change the connection data everytime I change the test.
¿Can I to know when open the web app in internet or localhost?
Data connection are the same in both cases:
$host = "localhost";
$user = "myuser";
$password = "mypassword";
$database = "mydatabase";
This helps you.
http://www.w3schools.com/php/php_mysql_connect.asp
When you use localhost then your host is "localhost", your user is "root", left blank your password if you not set any password when you install phpmyadmin and put your database name which one you create in phpmyadmin.
$host = "localhost";
$user = "root";
$password = "";
$database = "Your_Database_Name";
I know it. But in my case, external and local connection have the same data except password. I want identify if I doing a local test or internet test to change de password.
Related
In development, I would like to replace localhost:3000 to something like "domain.com:3000" or "domain.com". I can achieve this by adding alias to /etc/hosts file, for ex:
# /etc/hosts
127.0.0.1 domain.com
^^^ this one works, i can now view my site locally using domain.com.
The problem is that rails itself still uses localhost:3000, for example when generating urls via router methods. I feel that there should be some config for this.
You have to set:
Rails.application.routes.default_url_options[:host] = 'domain.com:3000'
in your development environment.
Custom domain name for your IP Address can be created.
First of all find your IP Address using ifconfig.
Then open /etc/hosts file with sudo.
/etc/hosts file is in readonly, so need to open with sudo
sudo vi /etc/hosts
There you will find at least two entries for 127.0.0.1 and 127.0.1.1, below this, create your own domain name
<IP_Address> domain.com
Save the file.
Then start your rails server and bind with your IP Address.
rails s -b <IP_Address>
And you are done.
In browser,
<IP_Address>:3000 will be same as domain.com:3000
I check on internet but every answer to this problem failed on my case.
I'm using ruby on rail and Heroku on Cloud 9 IDE. everything is up to date.
I try to link the Ruby project to Heroku postgres (Postgresql). i followed postgres guide to first understand how it work but when i try to access my localhost, i get this message : fe_sendauth: no password supplied
I modified pg_hba.conf but it failed so I remove changes
local all postgres peer
local all all peer
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
in the postgresql.conf I replace Localhost by *
listen_addresses = '*'
on database.yaml i tried to let password empty. currentrly, in production and developpement i let it with "" empty
password: ""
I tried sudo service postgresql restart but still nothing, the issue is still here
I don't know what can i do after that
When using Heroku you should set an ENV variable called DATABASE_URL that will take precedence over whatever you add on the database.yml
When I execute heroku db:pull it finds my local dev db at:
postgres://127.0.0.1/myapp_development?encoding=utf8
once I confirm though, it fails with:
Sequel::DatabaseConnectionError -> PGError: fe_sendauth: no password supplied
I tried running the pull with the local db specified, e.g.
heroku db:pull postgres://root:#localhost/db_name
which gives the same no password supplied error.
I thought I may need to change root: to myname: because thats the user I granted superuser rights to when I setup postgres but neither root: or myname: works
My database.yml has username: and password: blank for all databases specified.
From the command line as myname#ubuntu I can type psql myapp_development and connect fine and run selects.
What am I missing here?
Is it related to my pg_hba.conf settings? I had a look inside that and it says:
# Database administrative login by UNIX sockets
local all postgres ident
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all ident
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
Should 'trusted' be used there? And if so if I edit that file do I need to restart postgres? And if 'trust' is necessary then how come rails and the psql command line tools work without passwords when logged in as my myname user?
Thank you!
Authentication method trust might do the trick, but as you are undoubtedly aware, this is not secure.
After editing pg_hba.conf, you don't have to restart. A reload is enough (quoting the manual):
The pg_hba.conf file is read on start-up and when the main server
process receives a SIGHUP signal. If you edit the file on an active
system, you will need to signal the postmaster (using pg_ctl reload or
kill -HUP) to make it re-read the file.
pg_ctl reload
See the fine manual. You might need the manual for version for 8.3. Shared db on heroku currently runs on PostgreSQL 8.3. (Also, I doubt you have access to pg_ctl on heroku.)
Be aware of this:
If no password has been set up for a user, the stored password is null
and password authentication will always fail for that user.
Emphasis mine. You might be able to log in locally, because the auth-methods ident or peer allow for that. But for your purpose you may need a password!
Starting to develop my first Ruby on Rails app with postgresql on Ubuntu. I have created a postgresql user with a password. In the database.yml, I put in the postgresql username and password.
Whenever I run a rake db:migrate it executes without error no matter what I change the password to in the database.yml - even if the password field is blank. If I change the username I get an authentication error.
How do I get Ruby on Rails database to use a password?
TIA
You're probably using ident or even trust authentication. A quick synopsis of the most common authentication methods:
trust - You can log in no matter what.
ident - You can log in if your UNIX username is the same as the PostgreSQL username.
md5 - You can log in if your password (encrypted with md5) is correct.
Edit: PostgreSQL 9.0 introduced the peer authentication method. From what I gather, ident and peer have the same purpose—your login is determined by your operating system username—but ident talks to an ident server listening on port 113, while peer looks up your credentials with a system call. See http://www.postgresql.org/docs/9.1/static/auth-methods.html#AUTH-IDENT
Locate your pg_hba.conf file, and see if you can find something that looks like this:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all ident
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
When you try to connect, PostgreSQL goes through this line-by-line. If the connection type (e.g. local, host), database, user (database user, not system user), and address all match up, it will use the given authentication method.
If you want to require a password to access your own PostgreSQL user, you could add a line like this at the top, before the local all all ident line:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
local mydbname myusername md5
Be sure to restart PostgreSQL after changing pg_hba.conf.
I've only barely used PostgreSQL, but I do know it has a feature called sameuser. If the name of the system user matches the name of the database user, the password is not required. So, if I logged into this computer with the username "matchu", and there is a user in PostgreSQL named "matchu", I could log in to that database user without additional authentication.
Could that be what's going on here?
Error ERROR [HY000] [MySQL][ODBC 5.1 Driver]Access denied for user (using password: YES) ERROR [HY000] [MySQL][ODBC 5.1 Driver]Access denied for user (using password: YES)
Must be the semicolon in the password
Make sure that your MySql server allows remote connections. If not you'll have to bind the database and user to the remote IP(s) You also need to check the servers firewall settings to make sure 3306 (or whatever you're using) is allowed and that incoming connections are permitted.
Try this: Connect your database using MySQL Workbench and try to run the following SQL statements:
GRANT ALL PRIVILEGES
ON <database>.*
TO '<user>'#'localhost' IDENTIFIED BY '<password>';
SET PASSWORD
FOR <user>#localhost = PASSWORD('<password>');
If nothing else works, it might be something you mistyped in the password etc. To fix, connect as root, and reset the database permissions, password and flush the privileges:
GRANT ALL PRIVILEGES
ON <database>.*
TO <user>#localhost IDENTIFIED BY '<password>';
SET PASSWORD
FOR <user>#localhost = PASSWORD('<password>');
Flush Priviliges;