Server Performance Improvements for WordPress – Turning off Services

My site is proudly hosted with Inmotion Hosting, I use their VPS3000 plan which means I have almost full control over my server. It's a virtual server, but I have full root access, and technically I can do anything I want on it. This also means that I could easily break something.

As I've been working on optimizing WordPress, I decided to take a look at the server side of things. If you're looking to improve the performance of your website, this may be useful for you. Please keep in mind the things in here are exclusive for VPS or Dedicated type of servers, they will not work with shared hosting or managed hosting, but may work for other hosts besides Inmotion Hosting.

If you haven't done so yet, you may need to configure SSH first so you can access your server from the command line and do the stuff I talk about here. Check if your host allows you to do that, and how to set it up. If you have a VPS with InmotionHosting, you can setup SSH as explained here.

Most web hosts allow you to ssh into your VPS.

As a quick disclaimer, I run all the commands listed here as root. This can be risky so be careful when you're running this on your server; you should always run commands with your own username and use sudo to run commands as root when needed. But I'm awesome, and I live dangerously, so I run as root, deal with it.

Turning off unnecessary services.

The first thing you should do with any server if you're going to optimize it for performance is to turn off unnecessary services. There are usually a half dozen or more services that run on every server but aren't needed, they're there for your convenience and just in case.

Conversely, you should know and remember that if you turn these services off and you need them later, you'll need to turn them back on.

How to find out what services are running.

Depending on the operating system your server is running, you'll need to run some commands to see what services are running. In my case, my server is running CentOS which is a spinoff from RedHat. To find out what's running on a RedHat server, you can  run these commands:

service --status-all

To narrow down to a much smaller and useful list of stuff you can run this command:

chkconfig

And to eliminate even more noise, we can filter the output of the chkconfig command to just the stuff that is running right now at our runlevel, like this:

root@servername [~]# chkconfig |grep 3\:on

That command shows only what's running right now under runlevel 3. Let's take a look:

root@servername [~]# chkconfig |grep 3\:on
apf            	0:off	1:off	2:off	3:on	4:on	5:on	6:off
atd            	0:off	1:off	2:off	3:on	4:on	5:on	6:off
cpanel         	0:off	1:off	2:off	3:on	4:on	5:on	6:off
crond          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
exim           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
fastmail       	0:off	1:off	2:off	3:on	4:on	5:on	6:off
filelimits     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
ip6tables      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
ipaliases      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
iptables       	0:off	1:off	2:on	3:on	4:on	5:on	6:off
mailman        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
messagebus     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
modules_dep    	0:off	1:off	2:on	3:on	4:on	5:on	6:off
mysql          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
named          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
netfs          	0:off	1:off	2:off	3:on	4:on	5:on	6:off
network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
nscd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
psacct         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
pure-ftpd      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
ror            	0:off	1:off	2:on	3:on	4:on	5:on	6:off
rpcbind        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
rsyslog        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
saslauthd      	0:off	1:off	2:off	3:on	4:off	5:off	6:off
sshd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
sysstat        	0:off	1:on	2:on	3:on	4:on	5:on	6:off
udev-post      	0:off	1:on	2:on	3:on	4:on	5:on	6:off
vzquota        	0:on	1:on	2:on	3:on	4:on	5:on	6:on

From the services listed (notice the 3:0n column) that are running, most of them are necessary for the proper operation of the server. The ones I am questioning are exim, fastmail, mailman and ror.

My server doesn't work as an email server and I don't want it to be a relay, the first 3 services I listed are related to mailserver stuff. If I know my stuff, then I'm willing to bet that those services aren't needed for my WordPress site to operate properly.

But what about email sending from WordPress? WordPress sends email out sometimes, like when there are updates, or sometimes certain plugins send updates and alerts. I believe that the sendmail script is all that's needed for that, but I decided to test this theory.

Then the 4th service I found suspect is ror which is the Ruby on Rails service. I don't have any ROR apps running so I don't know why that would even be active.

Turning services on and off

You can turn a service off and on with a simple command:

root@servername [~]# chkconfig servicename off

That turns off a service named servicename. Changing "off" to "on" turns it back on. Note that this command is temporary until the server restarts, so if you make a mistake or shut down a service that you shouldn't have turned off, you may need to reboot the server and the service will restart automatically.

This is how I test to see if I need a service. I first turn it off and then check the site, then if all works fine, I make the service permanently turned off, so it stays that way even after the server restarts. You can see more information on how to use the chkconfig utility here.

To make a service stay turned off permanently, I use this command:

root@servername [~]# chkconfig --level 3 servicename off

Testing services before making permanent changes

To verify that the services I want to disable will not affect my WordPress site and prevent it from sending email, I'll turn off each one at a time and then test my site's ability to send an email. In this case, I'm using a basic contact form from WP Forms to make sure sending email still works.

So I run this command to turn off exim:

root@servername [~]# chkconfig exim off

I then use the test contact form to confirm the site can still send email, I also check the inbox to make sure I received the message. If you're going to follow my steps, I also recommend you test all this before you make any changes to the services running to make sure it's all working fine to begin with.

After I turned off exim, I could send messages just fine. Next up fastmail.

root@servername [~]# chkconfig fastmail off

This also resulted in being able to send emails fine. Next is mailman.

root@servername [~]# mailman mailman off

I turned off all four services, fastmail, mailman, exim, and ror without any adverse side effects. So the next step is to permanently turn off each of those services, like this:

root@servername [~]# chkconfig --level 3 fastmail off
root@servername [~]# chkconfig --level 3 exim off
root@servername [~]# chkconfig --level 3 mailman off
root@servername [~]# chkconfig --level 3 ror off

To confirm that all the changes are permanent, I rebooted my VPS using the restart server button from my Inmotion account dashboard. I don't use the built in reboot or shutdown command from the command line because the server never seems to come back up if I do that. There must be a routine that happens when the server is rebooted from the dashboard instead of the command line so keep that in mind if you feel like restarting your server from the command line.

I confirm one more time with the chkconfig command to list what is running on runlevel 3:

root@servername [~]# chkconfig |grep 3\:on
apf            	0:off	1:off	2:off	3:on	4:on	5:on	6:off
atd            	0:off	1:off	2:off	3:on	4:on	5:on	6:off
cpanel         	0:off	1:off	2:off	3:on	4:on	5:on	6:off
crond          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
filelimits     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
ip6tables      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
ipaliases      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
iptables       	0:off	1:off	2:on	3:on	4:on	5:on	6:off
messagebus     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
modules_dep    	0:off	1:off	2:on	3:on	4:on	5:on	6:off
mysql          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
named          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
netfs          	0:off	1:off	2:off	3:on	4:on	5:on	6:off
network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
nscd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
psacct         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
pure-ftpd      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
rpcbind        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
rsyslog        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
saslauthd      	0:off	1:off	2:off	3:on	4:off	5:off	6:off
sshd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
sysstat        	0:off	1:on	2:on	3:on	4:on	5:on	6:off
udev-post      	0:off	1:on	2:on	3:on	4:on	5:on	6:off
vzquota        	0:on	1:on	2:on	3:on	4:on	5:on	6:on

Notice the services are not listed as being "on" for runlevel 3, success! There are a few other services that other sysadmins would question, like named. In my case, I'm pretty sure that I need everything else listed here for now.

While the active resources that these services may not be very significant, I don't need any mail services running. I also noticed in my mail logs that spammers have been trying to use my server as an email relay, turning off all mail related services should help minimize this activity. To be sure that gets shut down as well, I should turn off all ports that aren't needed. I will tackle that in another post soon.

Conclusion

If you want to start squeezing every bit of performance out of your VPS server, this is an example of some of the things you can do. In this case, I showed you how I turned off 4 services that were running but not being utilized. They may not impact your server significantly, but every bit counts and this is easy to do so why not start with this. You may have other unused services running, but this should be a good guide to show you how to find said services, test them and then turn it off if they're not needed.