Title: Cannot connect to localhost
Last modified: August 24, 2016

---

# Cannot connect to localhost

 *  Resolved [sol9001](https://wordpress.org/support/users/sol9001/)
 * (@sol9001)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/)
 * Running CentOS 6.6 with SE Linux enforced, Apache 2.2, Mysql 5.1.73 localhost
   via UNIX socket /var/lib/mysql/mysql.sock, php 5.3.3
    Having installed WordPress
   to the working website and created the wp user and database and set wp-config.
   php I am unable to run the install from wp-admin/install.php. I can connect to
   mysql with the wp user account if I connect via 127.0.0.1 but not when using 
   localhost. I have tried turning off iptables and allowing port 3306 in iptables.
   But I cannot get the install.php to work. Setting the DB_HOST to 127.0.0.1 does
   not help. Any help much appreciated.

Viewing 15 replies - 1 through 15 (of 15 total)

 *  [Clayton James](https://wordpress.org/support/users/claytonjames/)
 * (@claytonjames)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6111960)
 * dbhost should work fine with ‘localhost’ in wp-config.php, right out of the box.
   Nothing special needs to be done with the firewall, or port 3306 by default. 
   SELinux by default will not prevent WordPress from installing. (the default contexts
   can cause automatic update issues, but that’s a different topic).
 * >  I am unable to run the install from wp-admin/install.php.
 * Not enough info.
 * What actually happens? What are you seeing in the browser, do you get any error
   message?
 *  Thread Starter [sol9001](https://wordpress.org/support/users/sol9001/)
 * (@sol9001)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6111994)
 * Thanks for replying I get the following generated
    Error establishing a database
   connection
 * This either means that the username and password information in your wp-config.
   php file is incorrect or we can’t contact the database server at localhost. This
   could mean your host’s database server is down.
 *  Are you sure you have the correct username and password?
    Are you sure that 
   you have typed the correct hostname? Are you sure that the database server is
   running?
 * I can login as the dbuser on the cmd line using mysql -u wp-user -p and can see
   the empty database. I can connect via simple php webform using mysql_connect(‘
   127.0.90.1’, ‘wp-user’, ‘password’) but not if I change host to ‘localhost’ The
   wp-user has permissions to connect from ‘localhost’
 * /etc/hosts has 127.0.0.1 localhost entry
 * Really appreciate your help as very confused – regards Pete
 *  [Clayton James](https://wordpress.org/support/users/claytonjames/)
 * (@claytonjames)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6112006)
 * Did you grant your wp-user (the username that’s defined in wp-config.php) permissions
   on the database that you created just for use with WordPress?
 *  Thread Starter [sol9001](https://wordpress.org/support/users/sol9001/)
 * (@sol9001)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6112014)
 * Yes –
    mysql> select user, host from mysql.user where user=’wordpressuser’; +—————
   +————————-+ | user | host | +—————+————————-+ | wordpressuser | localhost |
 * Also did GRANT ALL PRIVILEGES ON *.* TO ‘wordpressuser’@’localhost’; and flush
   privileges; but when I do show grants; I only see the grants for root@localhost
   
   Also [root@hostname wordpress]# mysql -u wordpressuser -p Enter password: Welcome
   to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 
   26 Server version: 5.1.73 Source distribution
 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
 * Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates.
   Other names may be trademarks of their respective owners.
 * Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
 * mysql>
 * Thanks again Pete
 *  [Clayton James](https://wordpress.org/support/users/claytonjames/)
 * (@claytonjames)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6112021)
 * > Also did GRANT ALL PRIVILEGES ON *.* TO ‘wordpressuser’@’localhost’;
 * Just to be sure we’re on the same page:
 *     ```
       mysql -u root -p
   
       CREATE DATABASE database_name;
   
       CREATE USER wordpressuser@localhost;
   
       SET PASSWORD FOR wordpressuser@localhost= PASSWORD("password");
   
       GRANT ALL PRIVILEGES ON database_name.* TO wordpressuser@localhost IDENTIFIED BY 'password';
   
       FLUSH PRIVILEGES;
       ```
   
 * That all looks familiar in detail to what you’ve done?
 *  Thread Starter [sol9001](https://wordpress.org/support/users/sol9001/)
 * (@sol9001)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6112050)
 * Yes – I just created a new database and user and edited the wp-config.php file
   to reflect the changes but still get the same error message. I checked I could
   login as the user on the mysql command line with no problem. Now I think it is
   a mysql problem but not sure where or how to debug. I do not have any anonymous
   users in mysql user tables – any thoughts?
    Many thanks
 *  [Clayton James](https://wordpress.org/support/users/claytonjames/)
 * (@claytonjames)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6112058)
 * _“Having installed WordPress to the working website”_
 * Did you manually install it at /var/www/html, or did you install WordPress through
   yum, which (I think) leaves it at /usr/share/wordpress?
 *  Thread Starter [sol9001](https://wordpress.org/support/users/sol9001/)
 * (@sol9001)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6112060)
 * I manually installed it at /var/www/html/wordpress and configured /etc/wordpress/
   wp-config.php. I chown -R apache.apache on the wordpress folder I edited the 
   wordpress.conf in /etc/httpd/conf.d with the alias /wordpress /var/www/html/wordpress
 * and I added localhost to the allowed hosts but it has made no difference – I 
   still get the same error.
 * <Directory /var/www/html/wordpress>
    AllowOverride Options <IfModule mod_authz_core.
   c> # Apache 2.4 Require local </IfModule> <IfModule !mod_authz_core.c> # Apache
   2.2 Order Deny,Allow Deny from All Allow from localhost 127.0.0.1 Allow from ::
   1 </IfModule> </Directory>
 * <Directory /var/www/html/wordpress/wp-content/plugins/akismet>
    <FilesMatch “\.(
   php|txt)$”> Order Deny,Allow Deny from all </FilesMatch> </Directory>
 *  Thread Starter [sol9001](https://wordpress.org/support/users/sol9001/)
 * (@sol9001)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6112063)
 * Just found this in /var/log/messages
    kernel: type=1400 audit(1431263595.217:
   2050): avc: denied { read } for pid=12026 comm=”httpd” name=”mysql” dev=dm-0 
   ino=2359429 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=system_u:object_r:
   mysqld_db_t:s0 tclass=lnk_file
 * but I do not what it means but it happens every time I try to comnect to the 
   install.php
 *  [Clayton James](https://wordpress.org/support/users/claytonjames/)
 * (@claytonjames)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6112064)
 * > I manually installed it at /var/www/html/wordpress and configured /etc/wordpress/
   > wp-config.php
 * The config file that WordPress will be using is the one located in /var/www/html/
   wordpress
 * The one located at /etc/wordpress/wp-config.php would only be there and is only
   used when WordPress is installed via yum. (lots of extra hoops to jump through,
   and generally a much less satisfying experience IMO)
 * If you tried installing WordPress using yum at some point, you should make sure
   it’s been completely uninstalled. Otherwise, edit the wp-config.php file that’s
   in the /var/www/html/wordpress directory and try running the install routine 
   again from `http://localhost/wordpress/wp-admin/install.php` and see if that 
   does the trick.
 *  Thread Starter [sol9001](https://wordpress.org/support/users/sol9001/)
 * (@sol9001)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6112066)
 * Previously I had installed wordpress via yum but then manually installed but 
   I had changed the wp-config.php in all locations. I have just yum remove wordpress
   and re-edited the config files but I am still getting the same error which is
   getting to be very annoying.
    Thanks
 *  [Clayton James](https://wordpress.org/support/users/claytonjames/)
 * (@claytonjames)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6112069)
 * >  I edited the wordpress.conf in /etc/httpd/conf.d
 * That file is also part of the yum installed package and would not be present 
   or used in a manual installation at /var/www/html
 * You remembered to rename wp-config-sample.php to wp-config.php in the /html/wordpress
   directory?
 * Be absolutely sure of the edits you made in the file. A missing single quote (‘),
   or case error will cause a failure.
 * Nuclear option:
 * Manually remove/delete the entire contents of the /html/wordpress directory.
 * re-run `yum remove wordpress`, then `yum clean all`
 * Restore the contents of /etc/httpd/conf.d/ to it’s original un-edited/default
   state.
 * Reboot.
 * On reboot, confirm that httpd is working as expected at `http://localhost` it
   will probably show you the apache welcome page if you didn’t turn it off.
 * Confirm mysqld is running.
 * Drop a test index.php – phpinfo() works great for this test – file into /html/
   wordpress and confirm it works by visiting `http://localhost/wordpress/filename.
   php` in your browser.
 * [ How to Create a phpinfo.php File](http://support.hostgator.com/articles/specialized-help/technical/phpinfo)
 * Download a fresh WordPress package: [https://wordpress.org/download/](https://wordpress.org/download/)
   and extract the contents to /html/wordpress/
 * The rest is all covered in this guide: [https://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Install](https://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Install)
 * Beyond that – meaning if it still fails – I would guess you might be dealing 
   with some specific server misconfiguration issue rather than a WordPress issue.
 *  Thread Starter [sol9001](https://wordpress.org/support/users/sol9001/)
 * (@sol9001)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6112081)
 * Many thanks – I think there must be something specific to the server as I switched
   tack and installed a fresh install manually of WordPress on a different server
   and voila once I had sorted out the webserver I was able to connect to localhost
   and run the wp-admin/install.php so finally I have a Dashboard to work with!
 * Have not been able to find out what was wrong with the original server but if
   I do will update in case it is of use to anyone else.
 * Much kudos for helping me out – kind regards Pete
 *  [Clayton James](https://wordpress.org/support/users/claytonjames/)
 * (@claytonjames)
 * [11 years ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6112084)
 * You’re welcome!
 *  [neha12gupta34](https://wordpress.org/support/users/neha12gupta34/)
 * (@neha12gupta34)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6112304)
 * Hi, I am not able to run local host as i am getting the error of login failed
 *  Login failed for user ‘ngupta’. Reason: The password of the account has expired.
   
   Description: An unhandled exception occurred during the execution of the current
   web request. Please review the stack trace for more information about the error
   and where it originated in the code.
 * Exception Details: System.Data.SqlClient.SqlException: Login failed for user ‘
   ngupta’. Reason: The password of the account has expired.

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘Cannot connect to localhost’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 15 replies
 * 3 participants
 * Last reply from: [neha12gupta34](https://wordpress.org/support/users/neha12gupta34/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/cannot-connect-to-localhost-1/#post-6112304)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
