Wordpress Apache



For WordPress websites, try to use NGINX with Apache (NGINX as a reverse proxy, and Apache at the backend). This allows your WordPress site to use.htaccess file AND get the benefits of NGINX’s performance for serving static content. This is a powerful combination with a powerful backend and robust frontend. Configure NGINX with Apache. Get OpenLiteSpeed, the Open Source edition of LiteSpeed Web Server Enterprise. Learn about features, check the knowledgebase, and get support. News From Our Blog Become an Early Adopter With the Gutenberg Plugin. Copy by Anne McCarthy (@annezazu) and Design by Mel Choyce-Dwan (@melchoyce) In WordPress circles (whether it’s your local meetup, a trusted publication, or your networking group), you may have heard terms like Core Editor, Gutenberg, and the Block Editor used interchangeably over the last four years.

If you made the decision to move your WordPress install from shared hosting to a shiny new VPS you should consider optimizing Apache by making some tweaks to your httpd.conf file. Apache is a fast, reliable, and flexible server but is heavy on resources by default. If you are running a small VPS, and using it just for WordPress, you can make some small tweaks to your configuration and get some significant performance gains.

If you’re looking for some tips on SSL performance with your WordPress site be sure to check out our guide on using SPDY and SSL. If you need a WordPress theme, be sure to check out our WordPress templates or read about how to find the best WordPress themes.

Trim Down Those Modules

Wordpress Apache Config Example

Open up the httpd.conf file on your server in your favorite text editor and look for a bunch of lines starting with LoadModule. It should look something like this:

The actual list will be much longer but you get the idea. You can disable these modules by “commenting them out”. Which essentially amounts to adding a # in front of the line like so:

ApacheWordpress Apache

You are going to disable a bunch of these modules that a basic WordPress website does not require. In fact, I want you to comment out every module EXCEPT FOR the following:

One of the lines you probably commented out was this one:

This provides some functions for auto-completing mistyped URL’s that you don’t really need. It also is required if you are serving multilingual pages. If that is the case then DO NOT comment out the above module.

Wordpress Apache

Wordpress Apache Configuration File

If you did in fact comment out the mod_negotiation.so module you will need to make a couple more tweaks. Find these two lines (they are in different locations) and comment them out:

You should see a significant performance boost after disabling those modules. They were eating up a good size chunk of your limited system resources.

Apache MPM Prefork Module

Another handy tweak is to make some adjustments to the Apache MPM prefork module. This is assuming you are using Apache in prefork mode, which is highly recommended and likely if you are on a small VPS.

This module controls the number of processes and spare processes Apache will start and run. This is especially important if you are running a small VPS that is handling MySQL and Apache. Unless you are getting slammed with really heavy traffic on a regular basis (in which case you should be on a dedicated server) there is no need to be running the default configuration. Find these lines in your httpd.conf file:

MinSpareservers and MaxSpareServers control the number of spare processes your webserver is permitted to run and StartServers controls how many are started by default.

ServerLimit controls the maximum configured value for MaxClients. Reducing MaxClients on a webserver that is serving dynamic content (e.g. WordPress) can make a big difference. If you experience a traffic spike on your VPS and your MaxClients is set too high your server will more than likely get stuck in an endless loop of swapping pages from physical memory to virtual memory, commonly referred to as thrashing. The accepted way of calculating an appropriate MaxClients value is dividing your total available system memory by the size per Apache process. For example, if you had a 500MB left for Apache to use and each Apache process was using around 10MB you would set your MaxClients to (512-12) / 10 = 50. To check real time memory usage on your VPS use top.

MaxRequestsPerChild limits the number of requests a child server will handle during it’s life. We can safely reduce this value and realize a small gain.

So let’s go ahead and pare down those values:

Remember these are not concrete “best” values, they depend on the size of your VPS and how small or large you Apache process is.

Optimize Your KeepAlive

KeepAlive allows your visitors to issue multiple requests over the same TCP connection, in theory this helps improve latency because your visitors can request your webpage, images, and javascripts all over one connection. Unfortunately, Apache must use a worker process to service each and every request. The worker process stays busy servicing each request for a full 15 seconds by default, even if your visitor is no longer using it! This means you have less worker processes available on your system at any given time. With the limited system resources you have on your small VPS we always want open worker processes to be actually working. One way of accomplishing this is turning off KeepAlive. Find this line in your httpd.conf file:

and change it to:

If you have a site with lots of images and javascripts it is usually better leave KeepAliveturned on and make some additional tweaks.

If you decide to leave KeepAliveturned on it is important you change the default KeepAliveTimeout value. This prevents unused connections from staying open for excessive amounts of time. Find this line in your httpd.conf file:

You want to leave this connection open for 2 seconds, just long enough for the client to request most if not all of the necessary files. So change that line to:

If you are going to leave KeepAlive on you will want to increase MaxKeepAliveRequests. Setting this higher allows more requests per connection and increases efficiency. Find this line:

and change it to:

Adjust Timeout

Another minor tweak that will give you a small performance boost as well as help reduce the effects of a DOS attack is changing the TimeOut Directive. This directive tells Apache how many seconds to wait while receiving an incoming request, processing it, and sending back a response. Find this line:

and change it to:

Restart Apache and Enjoy!

Wordpress

Now restart Apache and enjoy your performance boost! Always remember to backup your httpd.conf file in case something goes wrong. Keep in mind this is just a sample configuration and we aren’t responsible if it breaks something on your server.

Additional Resources

Enjoy this post? Read more like it in Tutorials.

A couple of weeks ago I moved my WordPress blogs from a trivial shared hosting to a more sophisticated VPS running CentOS 7 since I was in search of more flexibility from my server.

During these days, I learned a lot about managing a web server on my own and I’m still currently learning a ton of interesting things about this topic.

One of the most annoying problems I faced a couple of days ago concerned, in particular, my WordPress installation. Everytime I was trying to update its core and plugins, the dashboard showed me a message similar to this:

Downloading update from http://downloads.wordpress.org/plugin/plugin.x.x.x.x.zip…
Unpacking the update…
Could not create directory

This problem looked quite strange to me since I carefully set all correct users, groups and permissions to my WordPress directory tree.

Fortunately, I soon discovered this problem was not about wrong permissions but was related to SELinux.

SELinux infact, for security reasons, prevented WordPress from automatically create and modify directories and files.

Since deactivating SELinux could not be the best idea possible, we have to allow Apache to read and write some directories in order to make the updating process work smoothly.

Setting up the correct permissions

First of all, we have to set the correct permissions to the WordPress directory tree.

Firstly, we have to set apache as a user:

# chown -Rv apache:apache /var/www/wordpress/

Wordpress Apache Config

The second thing to do is giving the correct permissions to files and directories with the following two commands:

# find /var/www/wordpress/ -type d -exec chmod 755 {} ;
# find /var/www/wordpress/ -type f -exec chmod 644 {} ;

Setting up Selinux

Now, we have to allow httpd to read/write the correct directories:

# chcon -t httpd_sys_rw_content_t /var/www/wordpress/wp-content -R

Extras

WordPress Connection Informations

If WordPress is showing you a strange page about Connection Informations asking you for some informations about FTP user and password credentials when you try to update/install new plugins, add the following line at the end of your wp-config.php file:

define(‘FS_METHOD’,’direct’);

Enable Wordpress Apache

That’s all. From now on, you should be able to update your WordPress installation and to update or install new plugins without problems!