Wordpress Apache



Custom wordpress Docker image, from bitnami base image. Helm install example. WordPress is the most popular open source blogging system and CMS on the Web.

Learn how to install and configure Apache for WordPress. WordPress is one of the world's most popular CMS and blogging software packages, and its famous 'five minute install' makes it one of the easiest to use.

Wordpress apache2

Most WordPress users will find that it works on their server without having to make any updates or changes to Apache. However, in some cases Apache may need to be updated or configured in order to run WordPress.

  1. Updating Apache

Requirements

vServer (VPS) from IONOS

Low-cost, powerful VPS hosting for running your custom applications, with a personal assistant and 24/7 support.

Ready in 55 sec.

For any Cloud Server with Plesk, applications like WordPress should always be installed and managed through the Plesk interface. See our article Use WordPress on a Cloud Server With Plesk for step-by-step instructions.

Checking Your Apache Version

You can find your version of Apache with the following commands:

  • CentOS and Red Hat: sudo httpd -v
  • Ubuntu and Debian: sudo apache2 -v

This will return information about your Apache server.

In the example above, the server is running Apache version 2.4.6.

Updating Apache

The current version of WordPress requires Apache version 2.4 or later, in order to run the required version of PHP.

Updating to the newest version of Apache can cause issues with older web software packages. Consult this list of changes to ensure that your website(s) will not be affected before you update Apache.

Ubuntu 14.04

On newer Ubuntu and Debian systems including Ubuntu 14.04, update Apache with the command:

CentOS 6

On older CentOS and Red Hat systems including CentOS 6, update Apache with the commands:

You can then check the version of the new installation with the command:

CentOS 7

On newer CentOS and Red Hat systems including CentOS 7, update Apache with the command:

Installing mod_rewrite

WordPress uses Apache's mod_rewrite in order to format (and change the format of) its links.

To see if mod_rewrite is installed on your system:

  • Red Hat and CentOS: sudo httpd -M | grep rewrite_module
  • Ubuntu and Debian: sudo apache2ctl -M | grep rewrite_module

mod_rewrite is installed by default on CentOS and Red Hat systems. To install this module on Ubuntu and Debian use the command:

After installing it, you will need to restart Apache services with the command:

Managed WordPress Hosting with IONOS!

Start your website quickly and benefit from the most secure and up-to-date version of WordPress!

SSL

Configuring Apache to Allow mod_rewrite

In some cases, Apache may need to be configured in order to allow mod_rewrite to run. To do this, you will first need to locate and edit the relevant Apache configuration file.

Wordpress Apache

The specific file will depend on your server's web hosting setup. By default, the main Apache configuration file for your server's primary domain is:

  • Red Hat and CentOS: /etc/httpd/conf/httpd.conf
  • Ubuntu and Debian: /etc/apache2/apache2.conf

There may also be separate Apache configuration files for each individual domain. By common convention, these are usually found at:

  • Red Hat and CentOS: /etc/httpd/conf.d/[your domain name].conf
  • Ubuntu and Debian: /etc/apache2/sites-available/[your domain name].conf

You will need to edit the file and find the directive:

Save and exit the file, then restart Apache with the command:

  • Red Hat and CentOS: sudo systemctl restart apache
  • Ubuntu and Debian: sudo service apache2 restart
Related articles

Previously we’ve shown how to use apache server for hosting Wordpress sites anduse the right MPM to get a better performance, now we will explore another popular webserver called Nginx and compare its performance with apache and event MPM.

Nginx is a popular web server software written in C, it can be used as a reverseproxy, caching server and load balancer, it offers very high performance withoutchanging the configuration, Nginx does not have any modules to execute PHPscripts in its own process, it relies on other servers to execute them and returnthe results.

To follow along make sure you have read the previous tutorial and you have the results ready to compare themwith the results you will get here.

In this tutorial we will:

  • Install Nginx server and use it to serve Wordpress site.
  • Run locust performance tests on the server and compare them with previous results.

Login to the wordpress droplet created previously and execute these commandsto install Nginx

First we stopped apache2 server so when we install Nginx it starts immediately,because Nginx and Apache use port 80 for listening to HTTP connections andwe cannot start them both at the same time.

If you try to access your wordpress site now you will get “403 Forbidden”as shown bellow

This is because Nginx needs additional configuration to execute PHPscripts, we will explore this in the next section.

By default Nginx will just return the contents of PHP files when we requestthem, but we need to execute these files and return the results.

In order to do this we will change the default Nginx site located in/etc/nginx/sites-enabled/default and add these lines.

Wordpress Apache Install

Here we tell nginx to use the configuration for all files that end with .phpextension, first we include the configuration options located in snippets/fastcgi-php.conf then we tell nginx where to find the PHP-FPM socket using fastcgi_pass option.

After we make these changes we restart Nginx using this command for changesto take effect.

If we try to access Wordpress site again we will see that we still have thesame error “403 Forbidden”, now nginx is configured to execute PHP scriptsif we try to call them directly in the URL, try to create a simple PHP scriptinside the Wordpress directory called info.php with this content and requestit from the browser using this URL http://<wordpress_ip>/wordpress/info.phpand it will work as shown bellow

In the next section we will explore the source of this error and configureNginx properly to serve Wordpress site.

When we used Apache, it was able to serve Wordpress sites without any configurationthanks to the .htaccess file that comes with Wordpress code, this file includesdirectives to properly rewrite URLs to include the PHP script name in the URLso the server can properly execute the file, however Nginx does not use or read.htaccess files for performance reasons as this file is read every time a newrequest is received and this will slow down the server.

So the configuration to rewrite the URLs in Nginx must be added to Nginx sitemanually and this configuration is read once when Nginx starts and never changeduntill nginx is restarted, so the configuration is not read from the disk for everynew request and this will improve performance and reduce disk reads when serving requests.

Open your default nginx site configuration file and add these lines of code.

This block is applied only when we open a Wordpress URL (it startswith /wordpress) remember we put wordpress code in a sub-directory, wehave two rewrite rules here, the first one for all URLs that end withwp- prefix such as /wordpress/wp-admin and /wordpress/wp-login and the second oneis for URLs that start with wordpress prefix, they are rewroteto include index.php file.

Now restart Nginx and try to open wordpress site again.

if you get any errors, here is the complete Nginx configuration file,make sure it matches your file and do not forget ; at the end of lines.

Now after nginx is configured and ready to serve our Wordpress site, we needto run load tests against it as we did with Apache, to do this login to thelocust droplet and execute this command

The following image shows the results

Apache

From the image we can see the average response time is 2.2 seconds,this is very close to the one we got from apache event MPM, howeverfor the errors we can see a lot of them 521 errors and the requestsper second is 50.28 very close to the value we got with apache event MPM.

In this tutorial we learned how to use nginx to serve Wordpress sites, we alsomade load tests on Nginx and compared them with apache tests.

From the previous results in this tutorial and the previous onewe can find these conclusions:

  • Apache prefork and worker MPMs are not suitable at all for Wordpress sites,DO NOT USE THEM.
  • Apache event MPM offers a great performance for Wordpress sites.
  • Nginx out of the box can offer very good performance for Wordpress sites,however with high load we got a bigger number of errors than with apache.

You could try for your self and test apache vs nginx using different numberof users and different hatch rates (number of users added per second) and shareresults in the comments bellow.

Wordpress Apache Config

In future tutorials we will focus on using multiple droplets for our Wordpresssites to provide better performance and highly available infrastructure.

Ubuntu Wordpress

I hope you find the content useful for any comments or questions you can contact meon my email address mohsen47@hotmail.co.uk

Wordpress Apache Ssl

Stay tuned for more articles. :) :)