LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-05-2016, 02:03 PM   #1
koby82
LQ Newbie
 
Registered: Mar 2016
Posts: 6

Rep: Reputation: Disabled
Help needed with /etc/hosts


Hi everyone!

I'm a newbie in Linux Servers, and I have a big problem.

After installing everything I need (at least I hope) on my Debian 8, when setting up Wordpress for example, everything is copied, but than suddenly I get a "Error establishing database connection" when I'm using "localhost" in my wp-config.php file.

If I use 127.0.0.1 or even my main IP it just gives me a Blank Page (500 error?)

Every kind HTML file I put on my server, it works..so it could be some kind of a mysql issue too...

So, I think it has to do with some hostname setup on my Debian, but also some settings in my /etc/hosts file, where it could be that I didn't manage to allocate the localhost to the IP or hostname?

Eventually could someone show me a clear /etc/hosts file?

How it should look like?

And also about the Hostname...how should I rename my hostname? What kind of rules are there for a hostname?

Thank You very much!
 
Old 03-05-2016, 02:46 PM   #2
jefro
Moderator
 
Registered: Mar 2008
Posts: 22,001

Rep: Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629
Hello and welcome to LQ.

I get the feeling that you are on wrong track with hosts file. Leave it as last possible choice.

Command hostname should tell you the local hosts name but that should have no effect if you use an actual IP address to connect to. This leads me to suspect wordpress config or wp-config.php or ports/firewall open.


Reference. Hosts file is a simple way to resolve an ip address to a name. You can look at it and it should be there and may/should include a few IPv6 entries. Localhost ought to be there so a command ping localhost would resolve to that usually.

You might also check wordpress issues for IPv6.
 
Old 03-05-2016, 03:38 PM   #3
koby82
LQ Newbie
 
Registered: Mar 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hi Jefro!

And thank you for your answer and help.

This is how iptables looks like:

Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


So, I assume, that everything is allowed there...it shouldn't be a firewall problem, am I wrong?

About your previous answer, I'm confused a bit about the following:

"Command hostname should tell you the local hosts name but that should have no effect if you use an actual IP address to connect to"

I can command the hostname, it's actually named, as part of the Debian version etc...,(hostname can be any kind of keyword, or keyword combination???) and what's with the using an actual IP address to connect to?

Thank You!
 
Old 03-05-2016, 03:44 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
A little something I found on the internet on how to set up a webserver. I do hope you know how to use your command line well enough to get things done. and how naming schemes actually work.

Code:
Using Unix Groups

Most users will want to be able to modify their content without being root.
The easiest way to achieve this is through the use of Unix Groups; you create
a group to which you add your content editing user, then you add the httpd 
user to that group.

Note that this doesn't easilly extend to more than one user who needs to
edit the files, since at that point you need to set Group write on the files.
One would need to use ACL's to achive this.

For example, we have a user "alice" who needs to edit our content, stored
in /var/www/html/

First we create the content group, then we add both alice and apache to it.

# groupadd www-content 
# usermod -G www-content <user-name>
# usermod -G www-content apache

Now we need to set the right permissions on our files.

# chown -R alice:web-content /var/www/html
# find /var/www/html -type f -exec chmod 640 {} \;
# find /var/www/html -type d -exec chmod 750 {} \;

What we've done here is to set all files to 640, or rw-r----- and directories
to rwxr-x---. Because the group "web-content" is applied to all the files
and directories, httpd can read these files, but cannot write to them.
host naming what ever you named it when you installed it, but it can be changed.

Code:
cat /ect/hostname
whatever your host name is plus your new created domain name.plus???
Quote:
%userx@voided 03:37:34 ~ >>$ cat /etc/hosts
#
# /etc/hosts: static lookup table for host names
#

#<ip-address> <hostname.domain.org> <hostname>
#127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost ip6-localhost
the hostname of your system, domanname

127.0.0.1 voided.pissoffwanker.ur voided
#add another virtual server
127.0.1.1 voided.NoyoupissoffWanker.org voided


# End of file
you have to set it up in your server conf file as well so it knows too.

is this an in house server? if yes then you can name it whatever you want. if it is going out into the world. you have to obey first come first serve. unless you install a Name server onto your system too. then haaa never mind. it is first come first serve.


if you install a proxy server onto your system as well...

I dont think you actually said what server you are using either. Apache???? 4+

Last edited by BW-userx; 03-05-2016 at 03:58 PM.
 
Old 03-05-2016, 03:59 PM   #5
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
The /etc/hosts file is used to map machine addresses to a system name and, if desired, an alias.

A "real" /etc/host file looks like this:
Code:
cat /etc/hosts
#
# hosts		This file describes a number of hostname-to-address
#		mappings for the TCP/IP subsystem.  It is mostly
#		used at boot time, when no name servers are running.
#		On small systems, this file can be used instead of a
#		"named" name server.  Just add the names, addresses
#		and any aliases to this file...
#
# By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
# should NEVER be named with the name of the machine.  It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#

# For loopbacking.
127.0.0.1		localhost
# Local servers
192.168.1.10		fubar.lan fubar
192.168.1.15		OfficeJet
192.168.1.20		snafu.lan snafu
192.168.1.30		pita.lan pita
192.168.1.2		hicl01.lan hicl01
# Public servers
75.126.162.205		linuxquestions.org
74.125.224.70		maps.google.com
74.125.224.111		maps.gstatic.com

# End of hosts.
The above named servers all have fixed IP addresses and system names "something.lan" and the OfficeJet is an Ethernet connected network printer. The public servers are their addresses and name just to avoid a DNS look up for frequently used external servers.

The name and alias: fubar.lan is the actual name of a server, its alias is fubar. If I am on fubar and wish to connect to, say pita, I simply
Code:
ssh pita
and I'm there quick like a bunny. /etc/hosts is where that sort of thing is done; the fields are separated by white space (spaces or tab). The comment at the top of the file bears reading.

I'm sorry that I have no clue how Debian does things. So I can't help you with that, nor can I help you with Wordpress other than to echo @jefro's suggestions.

Hope this helps some.
 
Old 03-05-2016, 03:59 PM   #6
koby82
LQ Newbie
 
Registered: Mar 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hi

This is my etc/hosts

# nameserver config
# IPv4
127.0.0.1 localhost.localdomain localhost
XXX.XXX.XXX.XXX (EXTERNAL IP) Debian-83-jessie-64-LAMP
#
# IPv6
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
2a01:4f8:136:308d::2 Debian-83-jessie-64-LAMP

what is wrong there?
 
Old 03-05-2016, 04:18 PM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
How To Set Up A Linux Network on Debian

How To Set Up A Debian Linux Proxy Server

How To Set Up Linux DNS Services
How To Set Up A Debian Linux Firewall


That should be enough to keep you busy for a little while

enjoy ...
 
Old 03-05-2016, 04:21 PM   #8
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by koby82 View Post
Hi

This is my etc/hosts

# nameserver config
# IPv4
127.0.0.1 localhost.localdomain localhost
XXX.XXX.XXX.XXX (EXTERNAL IP) Debian-83-jessie-64-LAMP
#
# IPv6
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts


2a01:4f8:136:308d::2 Debian-83-jessie-64-LAMP <-- that looks like a MAC address and not an IP Address for one.

what is wrong there?
look at the links I left for you above this post. and that dudes Host Listings to get an idea then you really need to get a basic understadning of tcp/ip
not trying to blow you off but, did someone say youtube?

H**king Tip: How To Use Proxies

Last edited by BW-userx; 03-05-2016 at 04:37 PM.
 
Old 03-05-2016, 08:24 PM   #9
jefro
Moderator
 
Registered: Mar 2008
Posts: 22,001

Rep: Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629
You said you used an IP address in browser correct? That would bypass hosts file. You can see that your hosts file is normal and has localhost for loopback ip.

Debian-83-jessie-64-LAMP of course is an entry both in IPv4 and 6 so you may have to consider how your wordpress config is set. As I don't know about setting up wordpress I can't help.

Last edited by jefro; 03-07-2016 at 03:11 PM.
 
Old 03-05-2016, 09:03 PM   #10
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Quote:
Help needed with /etc/hosts
Is a red herring and probably has nothing at all to do with your error:

Quote:
Originally Posted by koby82 View Post
I get a "Error establishing database connection"
To get that message you are already connected to the handling page on the host, and your web server is working.

The problem is a misconfigured database connection.

What is in your wp-config.php file for the database connection parameters?
Have you created the database?
Have you granted user permissions to that database?
Can you connect to that database from the shell?

Troubleshoot the error you are getting, not some other imaginary problem.
 
Old 03-05-2016, 11:39 PM   #11
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
as above from "astrogeek"

i am guessing you did not install " phpmyadmin "
a web based GUI for mysql ( well MariaDB )
mysql is basically dead - killed off
MariaDB replaces it

setting up a

Linux
Apache
MriaDB
PHP

-- running Wordpress--

install is a VERY complex undertaking

easy but VERY VERY COMPLEX

it is also VERY VERY VERY EASY to set up a VERY VERY INSECURE!!! SERVER!!!


i refer to it a a 400 CS class with only a "pass / FAIL" and you MUST get a 4.0 in it

and as much studying is needed


is the database running ?
did you set up the needed tables ?
is apache running ?
is it securely set up ?
and is the system LOCKED DOWN ( not really needed yet in the set up and debugging stage )
 
Old 03-06-2016, 01:32 AM   #12
koby82
LQ Newbie
 
Registered: Mar 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
when trying to connect to a database user through shell, I receive the following message:

ERROR 1045 (28000): Access denied for user 'test123'@'localhost' (using password: YES)
 
Old 03-06-2016, 01:57 AM   #13
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Quote:
Originally Posted by koby82 View Post
when trying to connect to a database user through shell, I receive the following message:

ERROR 1045 (28000): Access denied for user 'test123'@'localhost' (using password: YES)
So, is there a test123@localhost user defined in the database? Has this user been granted any access rights and had a password defined?

It is important to note that MySQL users are not related in any way to system users. It is common to define MySQL users with the same name as system users, but that is only a convenience and no actual connection exists between the two.

Also, if a MySQL user 'test123' exists, it is not the same user as 'test123@localhost'.

So you must be very specific in your creation and use of MySQL users and their access rights.
 
Old 03-06-2016, 12:34 PM   #14
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
How to's

LAMP

WORDPRESS

MOD:

here is a really cool app I just found and installed for my proxy server ... (still learning how to manipulate it).

it is simple to install it helps deal with various Servers. It is a big differently worth a look. I know it will come in handy ...

Webmin

I used the .tar to install it after I unzipped it then moved it into my /opt directory before installing it.

Last edited by BW-userx; 03-06-2016 at 04:05 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
hosts.deny vs arno ip tables blocked hosts D0zer Linux - Security 2 12-07-2014 02:07 AM
[SOLVED] dnsmasq: how to prevent upstream queries for hosts in /etc/hosts? catkin Linux - Networking 2 02-18-2013 10:50 AM
[SOLVED] Can ping Ubuntu hosts but not Debian hosts by hostnames garyozzy Linux - Networking 6 03-09-2012 10:32 AM
Script for hosts, numbers of hosts and users connected to squid server arunabh_biswas Programming 5 08-28-2010 04:11 AM
can't restrict sshd access through hosts.allow and hosts.deny but was working earlier farhan Linux - Security 4 04-18-2008 07:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration