Fix Error Establishing a Database Connection in WordPress

Recently i was trying to install WordPress on my friend’s localhost but an error occurred which said – “Error establishing a database connection in WordPress“.

I’ll not go in detail, lets just solve the error right away. In order to fix – Error establishing a database connection, you’ll need to follow two steps.

  1. Creating a new Database
  2. Creating Database User
  3. Editing wp-config file of your WordPress package.

Where to Find wp-config file?

If you plan to install WordPress on Local Host using WAMP server then wp-config file has to be inside www folder (C:wampwww). If you plan to install WordPress on Web Host then you can access wp-config file using FTP Client like FileZilla.

You need to know the right location of wp-config file in order to proceed. If at all you have any difficulty to find wp-config, just leave a comment below and i’ll surely help you out.

Step 1 – Creating Database

Step 2 – Creating Database User

  • If you are installing WordPress on Local Host then just go to step 3
  • If you are installing WordPress on Web Host then read THIS article.

Step 3 – Editing wp-config file

When you open wp-config file, you’ll see something as shown below.

WP Local Host Installation

If you have created database named XYZ then make the following changes in your wp-config file –

WP Web Host Installation

If you have created database named ABC and created a user with username: admin and password: hello then just make the following changes in your wp-config file (which is on the server).

Long Story Short

You need to create database and database user. The database user will have username and password. This error usually occurs because of mismatch in configuration. So to fix it, open wp-config file and enter the right database name, database username and database user password. Save the file where it is supposed to be. And problem of “Error establishing a database connection in WordPress” will be solved.

Thanks for reading and do subscribe to blog feed for more amazing posts. You can find the subscription box below.

Custom Tag Buttons Widget For WordPress Using CSS

I’ll be sharing the code for custom tag buttons which you can use as a widget in your WordPress Blog. I have designed these buttons using CSS.

So in order to implement these, you’ll need to add two part of codes. One is CSS and other is HTML. You’ll need to put the CSS code at the bottom of style.css file of your WordPress theme. And you’ll have to add the HTML code inside a text widget.

Below is the screenshot of how the custom tag buttons look like. These are very simple buttons with round border. Also when you move your cursor over the button, the color of the button changes into a darker shade.

Custom Tags

CSS Code

You can use the CSS code as it is. But if you want to make any changes, feel free to experiment with it. If you are not sure about how to use it, then follow these steps –

  1. Open WordPress Administrators Dashboard
  2. Go to Appearance > Editor
  3. This should open the Stylesheet (style.css)
  4. Go to the bottom of this file and paste the CSS code given above.
  5. Save the file.

HTML Code

The HTML code which i use to display the buttons in the screenshot is given below. Note that, these buttons link to my blog categories.

You cannot use this code as it is. You’ll need to change it according to your need. For example, if you need a custom tag button to link to google.com then the format for that is given below –

In this way you can write a html code for a button with desired link. And then just copy the html code and use it inside a text widget. If you are unsure about how to use the code then follow these steps –

  1. Open WordPress Administrators Dashboard
  2. Go to Appearance > Widgets
  3. Drag the text widget into your desired Widget Area
  4. Paste the html code inside the content area of Widget. (leave the title empty)
  5. Save the widget.
  6. Go to your blog’s home page and you’ll find the custom tag button in the widget area of your choice.

Thanks for reading and do subscribe to blog feed for more amazing posts. You can find the subscription box below.

Installing WordPress On Subdomain Using cPanel

In this post, I’ll show how to install WordPress on a subdomain using the softaculous installer in cPanel of Linux Web Hosting. This is very simple, you just have to follow the steps given below.

I assume you already have a hosting account with a domain associated to it. So just log into your web hosting account and open the Control Panel (cPanel) of Linux hosting. Some hosts hide cPanel under the name ‘Manage Web Hosting‘.

Creating Sub-Domain

Once you open cPanel, navigate or scroll down to the ‘Domains‘ section. Here select the subdomains option and a new page will open up.

You can straightaway figure out how to create a subdomain, but if you can’t then keep reading. On the subdomains page, you can find ‘Create a subdomain‘ section. Check the screenshot given below –

All you need to do is just enter the subdomain name and select the domain. In this case, I have chosen the domain as codefap.com and the subdomain as lab. And do not mess with the document root, it will be automatically created once you enter the subdomain.

After entering subdomain and domain in the form, just hit Create button. In this case, a subdomain with link lab.codefap.com will be created for me.

Installing WordPress On Sub-Domain

Installation of WordPress package on a sub-domain is very similar to that of installing it on root itself. All you need to do is just select the newly created subdomain from the drop down menu.

Install WordPress On SubDomain

Fill the rest of the details as described in my previous post – Installing WordPress On The Web Host. I hope this post helps you. Subscribe for more amazing posts, Thanks.

Installing WordPress Using An FTP Client

I have previously written about how to install WordPress directly using a online installer like Softaculous. But some hosts do not provide installers, so in that case you can just upload the WordPress package using FTP Client.

First of all, you will need the WordPress package. Go to wordpress.org and download the package. Click on ‘Download WordPress’ which will take you to the download page. Here choose the .zip version and download it. Its basically a big blue button with some version number. (eg. Download WordPress 3.6 .zip – 4.3mb).

#1. Extract the downloaded zip using Winrar or any suitable program. Open the extracted folder where you can find folders like wp-admin, wp-content, wp-includes and files like wp-activate, wp-settings, etc.

#2. Open FileZilla and establish a connection to your server. Once you are connected. Open the www folder in FileZilla remote directory.

#3. Select all the extracted files as shown below –

WordPress Installation Files

#4. Now drag-n-drop these files into the www folder of the Filezilla remote directory. This will initiate file upload. It will take a while to upload all these files. Once file upload is done, move to the next step.

#5. Go to yourdomain.com/wp-admin/install.php and follow the installation procedure. Its almost the same as installing WordPress on WAMP Server.

#6. You’ll be asked to enter database information. Here you need to enter MySQL database name, username and password. Keep the rest as it is.

#7. Once database information is set, you’ll be asked to enter site name, description, admin username and password, etc. Just finish the installation process.

#8. After completing installation, you can login to WordPress administrators dashboard by visiting yourdomain.com/wp-admin

Installing WordPress On The Web Host

In the previous post, I have written about purchasing domain and web hosting from BigRock. Now lets see how to install WordPress on the server which you have purchased. And note that, I am using BigRock’s hosting as an example. But you can follow this for almost every other host.

Once you purchase linux hosting with a new domain, your account will be setup in 24 hours. Once its done, just login to your hosting account.

List Of Orders - Big Rock

After logging in, click on the domain name of the product named Web Services. Now scroll down to the Web Hosting part and click on Manage Web Hosting. This will open up the Control Panel (cPanel).

BigRock Web Hosting cPanel

In Softaculous app installer, click on WordPress. You’ll be taken to the installation page. Click on install button and now you’ll be asked to enter the details of the installation.

Installing WordPress Using Softaculous Installer

  1. Choose the Protocol as HTTP.
  2. Choose domain as your Domain Name. (I have chosen codefap.com)
  3. Leave the ‘In Directory‘ empty, so the installation will be in the root folder (domain.com) instead of sub folder (domain.com/wordpress).
  4. Leave the Database name and table prefix as it is.
  5. Just go ahead and enter the site name and description.
  6. Enter the admin username, password and email address. This will be the user account which you can use to administrate the blog. Basically this is blog owner’s account.
  7. Once WordPress is installed you can simply goto yourdomain.com/wp-admin and login using the username and password which you have set previously.
  8. That’s it. You are now ready to go.

Softaculous WordPress Installation Linux Bigrock

Note that, If your host does not support an online installer then you will need to upload the WordPress package using an FTP Client. I’ll talk about that in the next post.

Getting the Domain and Web Hosting For WordPress

I am writing this post as a base for the upcoming series of WordPress Tutorial. Many people have been asking me about how to create a WordPress blog. So i have decided to write a complete tutorial for beginners.

Note that, WordPress.com and WordPress.org are very different from each other. The .com version is wordpress hosted blog whereas .org is a package which you can use to create a self hosted blog.

To create a self hosted blog, you basically need two things – the domain and the web hosting. And there are many companies which provide cheap and reliable web hosting. But its not that easy, there are cheaters and oversellers. So the question is, how to choose a good web host?

After having an year of experience, I would recommend BigRock. Its good, reliable and cheap as compared to other biggies out there.

Purchasing Hosting and Domain

I’ll show you how to purchase hosting package and domain from BigRock India. Note that, the procedure is 99% same on every other hosting site. So you can follow this post, even if you decide to purchase hosting and domain from other host.

#1. Go to Bigrock.in and Click on Get Hosting > Linux Hosting. Note that, by selecting Linux or Windows hosting, you are not interacting with the OS directly. Instead you will get a control panel and trust me, CP in Linux is easier.

#2. Choose the suitable hosting plan. I would recommend Linux Advanced Plan for beginners who plan to grow fast. But if you are planning for a small static website or blog, then go with Starter Plan.

BigRock India Plans

#3. After selecting the desired plan, select the duration and click on Add this plan button. Where you’ll be asked to select a domain name or enter an existing domain.

#4. I assume you are creating a whole new site, so enter a new domain name and click on Search button. If the domain is available, click on add or else select other domain.

#5. And click on checkout button. Here you can enter a coupon code to get discount. You can use my domain name (codefap.com) as a coupon code to get 25% discount.

#6. Now just complete the purchase and place the order by registering your account. You will then get e-mails about your registration details. Just keep these e-mails safe. You’ll need them to setup your site.

In the next post we will see – How to install WordPress on the hosting server which you just purchased.