PhpMyadmin is a fantastic tool that gives you an easy to use web interface that lets you manage a MySQL database. You can install PhpMyAdmin by downloading the source files from the official website and placing them onto your web server following the config. Better news is that there is actually a package on Centos and Red Had operating systems that will let you install it through the command line.

In order to get access to phpmyadmin via yum you will need to enable the epel repository. Execute the following commands to install epel and phpmyadmin.

Once this has completed you will now have phpmyadmin installed on your server. You will need to restart apache in order for it to pick up the new conf files that were created when apache was installed.

If you now visit “/phpmyadmin” for your website e.g. http://website.com/phpmyadmin. You will be able to gain access to the UI. Chances are you will encounter permission issues trying to access this. I constantly get this error when i first install phpmyadmin. In order to be able to use PhpMyAdmin without getting permission errors go to /etc/httpd/conf.d/phpmyadmin.conf. Replace the contents of the file with the following and restart apache after.

Save this file and restart apache

Try visit the URL again and you should now have access to phpmyadmin.

 

Setting up an email server can be a very daunting task when you aren’t too sure about how an email server works. Thankfully there are tools and configurations you can use that will make the job of managing an email server incredibly easy to understand and perform.

For a long time I was creating new linux OS users to create a new mailbox. The problem here is it meant that only one server could handle a domain, this is when I discovered virtual mailboxes which allows one single server to handle emails for a large number of different domains. A lot of the tutorials out there will show you how to do this using the default database system that postfix uses. This is perfectly fine, but it becomes a major chore to manage when you start to get a large number of domains and emails. After some searching I discovered a web application called postfix admin. This magic piece of software lets you manage all your domains and mailboxes from your web browser without ever needing to ssh into the server. To make things even better, this will also replace the default postfix DB with a much more familiar MySQL database. So lets get to it, this guide will explain everything that you need to know about setting up an email server that uses Postfix and Dovecot with Postfix Admin to manager your sever.

Create Mail User

First thing we want to do is create the mail user. This will be a user that has access to manage all of the files and folders that your mail server will need to manage. The following commands will create a user and configure it with the correct permission and UID. This step is very important as all of the config code below is assuming that you are going to be using the same user created below. If you know what you are doing then of course you can change this to whatever you wish.

We now have a user and a group called vmail with the uid and gid of 2222. This is the ID that needs to be used when configuring Postfix and Dovecot.

Install And Configure Postfix

First and most important, install your SMTP server. There are various ways in which you can do this depending on your operating system. To install this on a Centos/ Red Hat OS run the following command.

Once postfix is installed, navigate to /etc/postfix/main.cf. Open this file and edit the contents to make it look like the following.

/etc/postfix/main.cf

One last change to the config files is to the master.cf file. Add or uncomment the following line. There is a good chance the line exists already and its commented (has a # at the start). Removing the hash will do.

/etc/postfix/master.cf

you have now setup the cf files, but we still have to setup the database. We are going to use MySQL as this allows us to link it in with a web interface and makes life so much easier. If you look at the contents added to the main.cf file you will see references to a bunch of files in an sql folder. All of these files need to be created. If you have downloaded postfix admin there will be an sh script that you can run and it will generate all of the files for you. This saves you a lot of trouble as these are annoying to write, but to make sure that this guide covers everything I will show you everything that needs to be added for these files. Before we can do this we need to setup PostfixAdmin as this will generate the database that you need to use. So lets setup PostfixAdmin.

Install PostfixAdmin

PostfixAdmin is a free, web interface that allows you to manage the database that postfix uses for virtual users. First things first, download and unzip the latest version of the code, which can be found here http://postfixadmin.sourceforge.net/. You will need to configure apache with an alias or virtualhost depending on what you want to do.

PostfixAdmin comes with its own extensive install guide that comes zipped in the folder. The setup is very straightforward. Run the setup php script through the browser and this will generate the database and add some admin information so you can begin working on it. Once you have it installed and setup, you will now have a database that can be used by postfix. Now we need to tell postfix to actually use this database. We have already instructed postfix that it will be using these files, so all you will need to do is create the following files and add the content to them.

Note: PostfixAdmin comes with a script to generate these files automatically for you. If you run the script (all documented in the setup notes) it will create the files in /tmp. If you decide to do this, take these files and copy them into /etc/postfix/sql and you will be done. If you dont know how to do this you can create them yourself.

Here are the database files that you need to create and add the content to.

/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf

/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf

/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf

/etc/postfix/sql/mysql_virtual_alias_maps.cf

/etc/postfix/sql/mysql_virtual_domains_maps.cf

/etc/postfix/sql/mysql_virtual_mailbox_limit_maps.cf

/etc/postfix/sql/mysql_virtual_mailbox_maps.cf

Finally you will need to restart postfix to apply all of the changes that you have made today. Make sure to check the log when restarting to ensure there weren’t any lines that were entered wrong etc.

Install And Configure Dovecot

Setting up Dovecot is a little less tricky than Postfix and there are less things that can go wrong, so consider the worst out of the way. First things first, let’s install Dovecot.

Once installed, navigate to the install directory and modify the following files.

/etc/dovecot/dovecot.conf

/etc/dovecot/dovecot-sql.conf

/etc/dovecot/dovecot-dict-quota.conf

This is everything you need to get dovecot working. Note the UID and GID values are using 2222 which is the same value that was setup for the user and group earlier in the tutorial. Of course please change the username/password/db name for all of the SQL queries for everything.

Final Notes

Everything should now be up and running. Restart everything just to make sure that everything is working fresh and clean.

You should be able to navigate to Postfix Admin in your web browser and work away with managing your web server. I understand that this is an incredibly frustrating part of the setup as there are so many things that can go wrong. I have gathered everything that I have encountered from the times when I have set this up. Hopefully everything went well for you, but if not these resources might help you.

Issue Fixes

Hopefully everything went well, but I know all to well that things never go smooth. Chances are you have some issues that you have encountered while setting this up. The following resources might help you solve any issues that you might be getting while setting this up.

Mysql Access Denied

This error is a damn nightmare. It can be one of many things to solve and hopefully its the obvious error that the account you are using has a bad password or does not have the correct permissions to access the database that you are trying to connect to. If you are 100% sure the user has access and can access the database via the command line then it might be an issue with MySQL. The following tutorial may help you get past this issue.

Postfix With Dovecot MySQL Access Denied

 Dovecot – unknown database driver MySQL

This is a common issue with a simple fix. It just means that you have not installed the dovecot mysql driver. The following guide will show you how to do this.

Dovecot Error Unknown database driver mysql

 

This error might pop up as you are trying to setup your email server. Fear not, there is a good chance that this is not a major issue and can be solved by running one single line of code in the command line.

Yep thats it. Dovecot has a mysql driver that it requires in order to be able to communicate with an SQL database. Once you have it installed you should be able to gain access to the database.

Make sure to restart dovecot so the changes take effect.

This error has become the bane of email server management for me. I know the cause and I know how to fix it, yet it always seems to take forever to get it right and it seems to break so very easily. Thankfully after a lot of frustration i have found a very easy way to get past the following error.

You have tried granting the user full permissions for everything, you can log in via the command line and nothing appears to be wrong with the user account. I tried all of this too and the problem appears to be the method that MySQL uses to encrypt the passwords. I’m not sure if its dovecot that needs to catch up with this or if SQL is acting up. Either way you can fix this error with the following command.

This will alter the password hash for the user account using the older hashing method. Im not really sure the big details of this, but all i know for sure is that it fixed the issue for me.

Of course this might not be the cause of your error. It might be a simple fact that the login is incorrect or that the user does not have the correct permissions to view the database. However it goes, hopefully this helps and you can get over this issue as easy as possible.

When running a web server it’s vital that you have you important that you have applications like apache and mysql start when the system does. Who knows what might trigger a reboot and even more, you don’t want to perform a quick restart and have the entire server crumble. Well fear not, it is very easy to set up your system for running applications on system startup.

The following command will work for Centos and Red Hat Linux.

Run the above command in your command line tool and mysql will be set to start when the system does. Replace mysql with another application name such as httpd to make that application start up on boot too.

It is very easy to lock a user to their home directory. Open up your vsftpd.conf file, which is usually located in “/etc/vsftpd/vsftpd.conf”. Either addor un-comment the following lines from your vsftpd.conf file.

Once you have added the above lines, restart vsftp for the changes to take effect.

This will now lock a user to their home directory, preventing them from being able to move outside of their home directory. To correctly use this as an FTP client, you will need to alter the home directory of the linux user to make this work as a full on useful FTP client.

 

This guide is going to work off the assumption that you already have a functional email server running with postfix on your server. This guide will show you how to setup OpenDKIM with postfix on a linux server

 

Now that opendkim is installed, you need to generate the dkim keys that you need to use to sign the emails with. There are multiple ways to do this. You can do it through the command line or you can use this service http://dkimcore.org/tools/keys.html.

Open up this directory and open the file called “default”. Paste your private key into this file. For safe keeping you could also create another file called “public.txt” and pop the public key into this file so you can access it in the future if you need it.

Sometimes default permissions dont get correctly set. In the event that this happens run the following. There is no harm just running this query anyway.

Open up “/etc/opendkim.conf” and replace everything with the following

You now need to add a key to the keytable. This file is located in /etc/opendkim/keytable

You will also need to add a line to the signing table.
If the file doesnt exist, create it. “/etc/opendkim/SigningTable”

Open or create “/etc/opendkim/TrustedHosts” and add the following.

Add the following to your postfix main.cf file. This will instruct postfix to sign the emails with the DKIM key you setup.

Thats all thats needed. Now run opendkim and restart postfix and you should be good to go.

 

Wordpress Logo

Content filters are used to display some data at a specific location in a post. For example, if you wanted to display some data at the end of every single post on your blog, you could use a content filter and it would allow you to do this. You will need to be able to write PHP code in order to do this. If you follow my full WordPress Plugin Tutorial you should be able to build an entire plugin from start to finish without too much trouble.

So to start off, you will need to have your own custom plugin created. If you do not know how to do this, follow my guide on creating a WordPress plugin template. A plugin is very simple to create, so don’t worry if you aren’t particularly strong at programming in PHP.

Step 1 – Register The Content Filter In The Main Plugin File

Open up your plugin and go to the main php file (usually the same name as the plugin itself) and you can add the filter that will use “the_content” as the data that will be filtered. This means that when wordpress is loading the page and it comes to the point where it loads the content of the post, it will check to see if there are any filters that have been added. If it finds a filter for “the_content” it will run the function that is defined in the filter.

The following code will add a filter that is triggered when WordPress is loading the post content and it will then call a function called myinfo_filter().

Step 2 – Create The Filters Function

In order to make this code work we are going to need to create a function called myinfo_filter. The function is just a standard PHP function that will have 2 simple requirements. It must accept a variable that contains the content of the entire post and it must also return the content for the post.

When WordPress reads the code above it will call a function called myinfo_filter and it will give this function all of the content from the post. If you do not return any data the post will show up blank. If you do not add the function you will get a fatal exception. So lets add a simple function that will append some data onto the end of the post.

This function will accept the content from the post and if this is a single page ie. a post. it will add ” CUSTOM CONTENT!” onto the end of the post. This will show up for every single post on your blog. You can add some more advanced logic here to append something more substantial to the end of the post.

You could also append the data to the start of the post by doing the exact same thing except putting the data at the start.

 

Save the file and your filter should now be adding content to the end of your post.

Creating a wordpress plugin is a lot easier than it might first seem. As long as you know how to write PHP code (or any similar language) you should be able to get a plugin together pretty quickly. The aim of this tutorial is to show you how to create a basic template for a plugin that will show up in the WordPress plugin menu.

Start by navigating to the plugins directory for your WordPress install. This directory is located at “wp-content/plugins/”. In this directory create a new folder named after the plugin that you want to create. E.g. “plugin-test”. Inside this directory create a php file with the same name, so “plugin-test.php”. Open up this php file and add the following code.

Save this file and that is it. You now have a plugin template created. You don’t need to do any additional work to register this plugin with your WordPress install. If you open your web browser and log into your WordPress install. Go to the plugins tab and you will see that the test plugin that you just created now shows up on this list. You can activate the plugin, but it will not do anything as you have not added any code to the plugin.

Now that you have an active plugin registered within your WordPress install, you can start adding any custom features that you want.