Apache Performance Tuning: Configuring MPM Directives

 

Our previous article in this series focused on defining and fitting MPM to match your environment.  Building off of our last tutorial we will be discussing specific details on how to adjust the previously mentioned Apache configuration directives on the various types of Liquid Web servers.  

 

 

Core-managed CentOS 6/7 Servers

On CentOS servers, Apache configuration files are located in /etc/httpd/.

  1. Log in to the server over SSH or FTP.
  2. First, create an optimization file. It’s necessary for the optimization file to be loaded last so that it will override all other previous settings. We suggest naming the file z-optimize.conf.touch /etc/httpd/conf.d/z-optimize.conf
  3. Open file for editing with your favorite editor:vim /etc/httpd/conf.d/z-optimize.conf
  4. Input necessary directive change, using IfModule statements for compatibility.Configuration example for Centos 6/7 servers.
  5. Save the file.
  6. Reload Apache.service httpd restart

Core-managed Ubuntu 14.04/16.04 LTS Servers

On Ubuntu servers, Apache configuration files are located in /etc/apache2/.

  1. Backup existing apache2.conf file:cp -p /etc/apache2/apache2.conf{,.bak.$(date +%F_%H%M%S)}
    ls -lah /etc/apache2/apache2.conf*
  2. Open file for editing with your favorite editor:vim /etc/apache2/apache2.conf
  3. Append the necessary directive changes to the very bottom of the config file. Configuration examples for Centos 6/7, Ubuntu 14.04/16.04 servers.
  4. Save the file.
  5. Reload Apache.apache2ctl reload

Fully-managed CentOS 6/7 cPanel Servers

Out of the box, our Fully-Managed cPanel servers come with general optimization suitable for most small and mid-range sites. cPanel servers use a sophisticated template system for managing Apache configurations. cPanel typically handles all configurations seamlessly by using the WHM and cPanel interfaces. However, it is still quite simple to set up an optimization configuration file. You have the choice to compose an optimized configuration file via command line over SSH/FTP or within the WHM interface.

Command Line Method (SSH/FTP)

The Apache configuration files on cPanel servers are stored in: /usr/local/apache/conf/includes/

You can use several included files for optimization. It’s necessary for the optimization file to be loaded last so that it will override all other previous settings. For this reason, the post_ include files work best, specifically the post_virtualhost_global.conf file.

 

  1. Log in to the server with SSH or FTP.
  2. Open the post_virtualhost_global.conf file in your favorite editor. (This file is typically empty and maybe missing entirely. This is okay and not unexpected.)vim /usr/local/apache/conf/includes/post_virtualhost_global.conf
  3. Input necessary directive change, using IfModule statements for compatibility. Configuration examples for Centos 6/7, Ubuntu 14.04/16.04 servers.
  4. Save the file.
  5. Reload Apache./scripts/restartsrv_apache
  6. Reload Apache PHP FPM servers./scripts/restartsrv_apache_php_fpm


WMH Method

  1. Log in to Webhost Manager (WHM) on the necessary server.
  2. Type apache in the quick find box.
  3. Click on Apache Configuration in the Service Configuration section.
  4. Click on Include Editor.
  5. Scroll down to Post VirtualHost Include.
  6. Select All Versions from the drop down.
  7. In the box input the necessary directives for optimization. Configuration examples for Centos 6/7, Ubuntu 14.04/16.04 servers.
  8. Click the Update button when finished to save the change.
  9. On the left-hand navigation pane in the Restart Services section at the bottom click on HTTP Server(Apache).
  10. Click on the Yes button.
  11. Back to the left-hand navigation pane in the Restart Services section at the bottom click on PHP-FPM services for Apache.
  12. Click on the Yes button to complete the configuration.

Fully-managed CentOS 7 Plesk Onyx 17 Linux Servers

Out of the box, our Fully-Managed Linux Plesk servers come with general optimization suitable for most small and mid-range sites. Plesk uses mostly a standard CentOS based Apache2 installation so that it can be modified in the same manner as our Core-managed CentOS 6/7 servers:

 

On CentOS servers, Apache configuration files are located in /etc/httpd/.

 

  1. Log in to the server over SSH or FTP.
  2. First, create an optimization file. It’s necessary for the optimization file to be loaded last so that it will override all other previous settings. Suggested name: z-optimize.conf.touch /etc/httpd/conf.d/z-optimize.conf
  3. Open file for editing with your favorite editor:vim /etc/httpd/conf.d/z-optimize.conf
  4. Input necessary directive change, using IfModule statements for compatibility.Configuration examples for Centos 6/7, Ubuntu 14.04/16.04 servers.
  5. Save the file.
  6. Reload Apache.service httpd restart


Our Heroic Support™ team is equipped with talented and knowledgeable techs who can discuss ways to enhance your environment.  After reading through our series if you still have questions our techs can walk you through the outlined steps. For our customer with Fully Managed servers, we are happy to pick up the torch and take the lead by directly implementing the changes in this article.  We are just a phone call, chat or ticket away from aiding you through the process.

Editing DNS Zone Files in WHM/cPanel

When using custom name servers, it is essential to update the DNS in cPanel/WHM, doing so, is a component of hosting your own DNS. To use custom name servers, you must update the nameservers at your domain’s registrar to match your Liquid Web server’s hostname. If you are unsure how to do this, you can see how in our article Setting Up Private Name servers in WHM/cPanel. It is critical to have created a cPanel account and to add the domain to your WHM panel, if you haven’t already,  follow our article, How To: Create a cPanel Account in WHM.  Additionally, access to your registrar’s control panel is necessary to update the name servers. If you are questioning who your registrar is, learn how to locate where your domain’s DNS is by following the instructions in our article, Where Is My DNS Hosted?

Knowing your DNS provider is imperative in guaranteeing that you’re pointing your name servers to your Liquid Web server. There is not much use in updating the records you see in WHM if your name servers are not looking to the Liquid Web server. Any updates that you want to take place have to be done so on the authoritative server for DNS (which in this case is Liquid Web), as this is the actual server responding to DNS requests.

Once you’ve set up your custom nameservers and created a cPanel account, the final step is to edit the DNS in your WHM/cPanel account.
If you’re setting your records through WHM/ cPanel and your WHOIS information reflects the correct name servers, then you are ready to make changes to your DNS. There are several different kinds of DNS records that you can set up, but the most essential of the records, and the one I am going to focus on for this article is the A and CNAME records.

After logging into WHM navigate to “Edit DNS Zone” under “DNS Functions,” and select the domain you want to edit DNS. Once highlighted, select “Edit” to update records on a particular domain.

Edit DNS in WHM

Once you enter the zone file, none of the changes you make will take effect until you save them, so you can back out at any time and start over, a good tactic if you think you have messed up the syntax. Many parts of the zone file will never get changed, so we will focus on the three fields you are most likely to edit:

  • Domain
  • TTL (Time to Live)
  • Record Type

These are significant fields for the function of the DNS, and within each area, specific nuances tend to raise questions from people, but the fundamentals remain very simple. The Domain field should be the domain name followed by a trailing period (.). Anywhere that a Fully Qualified Domain Name (FQDN) is used, never forget the trailing period. If you are not using a FQDN in the domain field, you can use the sub-domain, which does not require the trailing period.

This image shows several different sub-domain names and how their syntax differs from FQDNs:

DNS Zone in WHM

The TTL column controls how long the record remains cached before it requires the general public to re-request the DNS record from the source. Caching is convenient during times of migration because it can effectively minimize downtime by using a lower TTL! The IN field always needs to be set to IN, so it is best not to make changes to this field.

Lastly, we have the record type, which is twofold: it’s necessary to select the record type and fill in the data field. For example, if you choose to add an A record, an IP address must follow that in the adjacent field. If using a CNAME then you’ll use a FQDN in its adjoining field, again, don’t forget the trailing period!

WHM is broken up into two sections, one section allows for modifying the existing data OR adding a record. In this example, we are going to add an A record a new sub-domain “files.domain.com,” if propagation is a factor we can edit the TTL:

TTL field in WHM

In this example, we’ve added a new record to my zone file using a TTL of 300 seconds and pointed to the IP of the sub-domain. It will take at least 300 seconds, and up to 24 hours in some cases, for you to be able to see that domain from your browser or through a DNS lookup. Once you have added this info, you can save your changes! For the sake of brevity, we will skip the mail exchanger settings.

So far, we have only discussed editing DNS in WHM. Editing in cPanel is much more straightforward only offering two record options: add an A record, or add a CNAME. CPanel has fewer options and does not give full permission to the Panel user to edit their file, though they can make additional A and CNAME records, necessary for adding such elements as CDNs (Content Delivery Networks) or sub-domains.

If you need to add an A record through the cPanel you will want to search for and click on “Zone Editor” through the cPanel interface:

cPanel Zone Editor

Once in the Zone Editor, you will have the option of adding either an A, CNAME, or an MX record. You will see the options next to a plus sign:

Add A Record in Zone Editor

This becomes useful when setting up services like CDN or the like. CDN services typically require a CNAME record to be added. In the following example, we are adding a CNAME to dnsexample.com for the sub-domain cdn.dnsexample.com:

CNAME Record for a Sub Domain Record in cPanel

Once complete, select “add” and the record will be saved. One advantage of the cPanel view versus the WHM view of the DNS record is the ability to filter your search by record type:

Filtering Records in cPanel

 

In closing, when the hosting DNS on your server enables editing through WHM >> Edit DNS Zone. Altering any records will not be reflected changes if the name servers are not pointed to the appropriate server. In general, you won’t touch or need to change most fields in the zone file, except for Domain, TTL and Record Type. Through WHM you can make edits to the existing record or opt to add records. To get started with editing your DNS records and locate your DNS provider our easy to follow DNS article can assist you.

 

VPS Server Space/Disk Quota

The term “server space” refers to the amount of disk space that is available on your server’s hard disk drive. This space varies according to server type, hosting plan and possibly by additional services that are set up and available on your Liquid Web account.

Some of the largest hard disk drives on the market now can hold up to 100TB of data. To better visualize this, 100 terabytes of data is approximately equivalent to:

  • 42,000,000,000 trillion single-spaced typewritten pages
  • 8,000,000 phone books
  • 160,000 regular compact discs
  • 20,000 DVDs
  • 200 average-sized hard disks (500GB)
  • 80 human brains (the capacity of a human being’s functional memory is estimated to be 1.25 terabytes by futurist Raymond Kurzweil in The Singularity Is Near)

Your disk space can hold many types of data including file types like HTML, TXT, CSS, PHP, PDF, JPG, MP3, MP4, compressed (tar.gz) backups, SQL databases and more. These files are in specific folders which are defined by the applications configuration files or locations you determine.

How do I locate the folders containing a particular set of data?

The location of a file depends primarily on the type of file. On a Linux server, your typical cPanel account is set up under the /home/username folder, and your cPanel account username specifies the username folder. This folder is sometimes called the top-level or root folder of your cPanel account. This root folder is not publicly accessible on the web but, contains folders which are accessible via a web browser. The root folder holds other cPanel specific system folders that use a variety of functions.

As you can see, when uploading files to your account, you’ll likely want them to be in public_html to be accessible on the web. Uploading an image.jpg file to the public_html folder makes it available at domain.com/image.jpg. Additionally, if you create a folder inside of the public_html directory and add the same image there, it would be accessible at yourdomain.com/foldername/image.jpg.

To see the location of a file, you have several options;

  1. Log into your cPanel and open the File Manager under the Files section
    cPanel >> Home >> Files >> File Manager’ here you can view all of the files and folders in your account’s root directory.cPanel File Manager
  2. When a cPanel account is initially set up, it also creates the main FTP user. You can use the servers FTP functionality to access folders from a remote location to view the file listings. Several software titles like Filezilla, Cyberduck, and WinSCP are available for this type of connection.
  3. Lastly, you can connect to the server via SSH and get access to folders/files on the server.

How do I see how much space I’m using?

Disk Usage Graph

Let’s start by reviewing a few command line examples; mainly the “du” and “df” commands.

Note
The ‘du’ command sums up the total space of files that exist on the filesystem, while the ‘df’ command shows blocks available in the file system.

The ‘df’ command (abbreviation for disk free) simply lists the space used per partition:

df Command Output

The ‘du’ command (abbreviation for disk usage) reports the sizes of directories including all of their contents and the sizes of individual files:

du Command Output

Note
There are times when the ‘du’ and ‘df’ commands show different usage amounts. Previously removed files can cause this discrepancy from a running process holding open that file. Open processes cause the ‘df’ command to report that space as still being used. The solution to this is to restart the service to close any open process.

You can also use cPanel to determine the amount of space used and where its located. If you log in to cPanel, you would need to go to cPanel >> Home >> Files >> Disk Usage to get graphical of your disk usage.

cPanel Disk Usage

Lastly, to view your server’s disk usage in your Manage account server resource graph

  1. Log into your Manage portal.
  2. Navigate to the Servers section and then click on the Plus sign (+) next to the server of focus.
  3. Click on the Dashboard button and click the link next to the Disk Usage text as seen below

graphical statistics

This view provides a graphical representation of your disk space and the used amount.

How do I prevent disk space overages?

Disk space overages can result in lost emails, backups or even websites or the server going down! Just like your car, your server requires regular server maintenance. Attention to server maintenance reduces lost data. One way to prevent disk space overages is to use cPanel’s built-in tools.

cPanel possess the ability to send “Disk Quota Warning”  emails that denote when your server is using too much space. They contain specific locations to check, and the space used. The settings for these emails notifications are in WHM (Web Hosting Manager) under the Home »Server Configuration »Tweak Settings .

Email Notifications AreaOther areas of server maintenance to check on regularly include:

  • Pruning backups
  • Logs are rotating correctly (including Domlogs, Apache2, MySql, and Chkservd)
  • Regularly archiving email
  • Using the /home directory for large user accounts

What are the dangers of being too close to Disk Quota?

When a server gets close to or is at its max disk space capacity, strange errors and problems can manifest themselves in many ways including:

  • Services (like MySQL or Apache) can error out or stop
  • Websites can become very sluggish
  • The servers overall responsiveness can become slower
  • The server may exhibit a high load
  • You may see degraded disk performance
  • The server may display an increase in I/O wait
  • The server may demonstrate an increase in CPU usage
  • The file system can go into “read-only” mode
  • The server can run out of inodes
  • Files can become corrupted
  • Decreased swap space may occur causing issues

So what do I do if I’m running out of space?

As Benjamin Franklin stated, “By failing to prepare, you are preparing to fail.” In light of this knowledge, taking steps in advance to prevent these issues is always the best course of action. Directly monitoring your server disk space on a weekly or monthly basis prevents most space issues from turning into actual problems.

If you have already reached the point where immediate action needs to be taken to bring a server back in line with normal space expectations, you have several options. Using the “du” and “df” commands are your primary weapons in tracking down used server space.

The primary steps needed are:

    1. Log into your server
    2. Run a df -h command to locate which partitions are using the most spacedf Command Output
    3. Change directories into the affected folders using the most space.
    4. Run the following command:

du-sk Command Output(This is an advanced du command that sorts the contents of a directory by size. Use this to drill down into a folder to see used space.)

  1. Move files (to a backup drive or folder) or, remove the files that are no longer needed using the ‘rm’ command.
  2. Repeat steps 2 through 6 as needed until reaching desired space level.

Final Thoughts

Over time, any operating system can become overcrowded with addition and removal of programs or accounts. Actively monitoring your servers disk space is the most effective method to prevent server space issues. If you do run into issues, using the du, df command line tools or, using the graphical interface in your account allows you to view files as needed. As always, if you have further thoughts or questions about this topic, please contact our Linux Support department for more information.

 

Setting up packages in WHM to use in WHMCS

Using Packages in WHM

Any new reseller’s first move when integrating WHMCS is to ensure that the products they are provisioning have the correct resources and limitations for their cPanel packages.

This article will walk you through the steps of setting up packages in WHM so you can use WHMCS.

Creating a package in WHM

  1. Log in to your server’s WHM as the root user (be sure this is the connected server to WHMCS that you intend to sell shared hosting on)
  2. Navigate to Add a Package
  3. Select Package Name – This will be used to identify within WHMCS
  4. Create Resource Limitations
    • Disk Quota (MB)
    • Monthly Bandwidth (MB)
    • Max FTP Accounts
    • Max Email Accounts
    • Max Email Lists
    • Max Databases
    • Max Sub Domains
    • Max Parked Domains
    • Max Addon Domains
    • Maximum Hourly Email by Domain Relayed
    • Maximum percentage of failed or deferred messaged a domain may send per hour

  5. Settings

    This is where you can specify if you want the package to have a dedicated IP, offer shell access (SSH), cPanel access (CGI), or Digest Authentication.
    Typically you can leave the Settings as default, but if you need to make changes, this is where you can do it.

WHMCS

Once you create a package in WHM, you will need to create a product in WHMCS and tie the two together in order to resell cPanel accounts with automated provisioning.

1.  Log in to your WHMCS as an Admin User

2. Navigate to Setup -> Products/Services -> Products/Services

3. As a new installation, you will first need to click “Create a New Group”

  • Set your Product Group Name (for example, Shared Hosting)
  • Set the Product Group Headline (this is customer facing, so something specific to the group of products)
  • Set the Product Group Tagline
  • Select your available Payment Gateways
  • Select the Order Form Template, if you don’t want the System Default
  • You have the option of making a product group hidden, the functionality of hidden products/groups will be covered in another article.
  • Save Changes

4. Now select “Create a New Product”

  • Select the product type, for this example we will be selecting “Hosting Account” as it will be for the shared product you created the package for
  • Choose your newly created Product Group
  • Set the Product Name and hit continue (note: the product name does NOT have to match the package name, but it can make tracking easier in the long run)
  • Details Tab

    • Enter the Product Description – Here you can enter the description that the customer will see, for example, if it is a shared hosting package with 5GB of disk, 100GB of bandwidth, etc. you can list the features of this product)
    • Welcome Email – This will give you a drop down of pre-existing email templates, for more on customizing WHMCS email templates, please see that article.
    • Require Domain – This means the client must have a domain for the package (You can offer domain registration for new clients, but this box just ensures that they enter a fully qualified domain name to proceed).
    • Stock Control – Set this if you only want to sell X number of this product
    • Apply Tax – If taxes apply, select this box
    • Featured – This will show the product more prominently in certain order form templates.
    • Hidden – See the benefits of hidden groups/products.
    • Retired – Often used in editing old products).
    • Pricing Tab –
    • Payment Type – Is this a free product (trial), one time bill, or recurring billing.
    • Allow Multiple Quantities – This allows the customer to order more than 1 of this package.
    • Recurring Cycles Limit – 0 is unlimited which will be the case for most hosting, change this if you want to limit how many cycles they can keep the product.
    • Auto Terminate/Fixed Term – 0 is disabled, this can be used to auto terminate accounts after a certain date, I’d suggest avoiding this as it could potentially delete/destroy user data, better to have a fixed limit and contact the customer prior to termination as it could potentially save a client.
    • Termination Email – This would need to be configured only if you use the previous option.
    • The next three options are around billing date modifications
      • Prorata Billing: Select this if you want to have universal billing dates.
      • Prorata Date: This would be the day of the month that all billing would exist for this product.
      • Charge Next Month: This will be the “cutoff” date for when the following month will be included in the original invoice.
  • Module Settings – This assumes you have a server already created, if you do not see the documentation on connecting your first server.

    • Module Name: Select cPanel from the drop down
    • Server Group: If you have a specific group for this product, select it here.
    • WHM Package Name: Select the correct package name to match the product.

  • Custom Fields

    • These fields allow for you to collect additional information from your client, such as “How did you hear about us?” or “Are you interested in our newsletter?”
    • You can add any number of additional custom fields and you can make them public facing, or internal.
    • Some modules and addons will require a custom field to be set up and filled out to successfully run.
  • Configurable Options

    • This will remain blank unless you have something that will generate the configurable options. For example, the Liquid Web Plugin. (https://github.com/liquidweb/LiquidWeb-WHMCS-Plugin) can generate configurable options based around what is available via our API.
  • Upgrades

    • Package Upgrades: This box will show other products within WHMCS and you can select which you would like the customer to be able to upgrade to/from. For example, if you have a Bronze Shared Plan at 5GB of disk space and you would like to offer an upgrade path to the Silver Shared Plan at 10GB of disk space, you’d select it here.
    • Configurable Options: Selectable if you have configurable options generated and set up for the product list.
    • Upgrade Email: You can set an email in Email Templates if you would like them to receive something during the process.
  • Free Domain

    • Free Domain: You can select if you would like it to only be free for registration/transfer (one time), or if you would like it to remain free as long as they maintain the product.
    • Free Domain Payment Terms: You can select if you only want to offer free domain registrations for specific payment terms. For example, Annual payment terms for hosting are a fairly common requirement to receive the free domain in this case since the domain registration is annual.
  • Other

    • Custom Affiliate Payout:
      • Default – Uses the default set up in the system.
      • Percentage – Pays a percentage of their referral.
      • Fixed Amount – you set the amount they would earn for each product
      • No Commission – they can track referrals but no commission is paid, this is helpful for if you have a program with incentives for referrals aside from money.
    • Affiliate Pay Amount: Enter the amount you would like the affiliate to get paid for referring this product.
    • Subdomain Options: Allowing specific subdomains to be used if you want to specify.
    • Associated Downloads: You can set download files that are only available to clients who have this specific product.
    • Overages Billing: If you want to allow for a client to use more than the allocated amount and charge them for it you set it here. Just to clarify though, the package we set up in WHM previously will determine the true “hard limits” if you set up overage billing with soft limits, the client will still see the full “hard limit” in cPanel, there is no way to “hide” that.
  • Links

    • Direct Shopping Cart Link: This is a direct link you can provide customers (or code into your site) that will link directly to the “checkout” page with the product in the cart.
    • Direct Shopping Cart Link Specifying Template: If you’re running a specific promotion in which you want to utilize a specific shopping cart template, you can use that here
    • Direct Shopping Cart Link Including Domain: If you were to send a direct “quote link” and you want to pre-fill the domain for the client you’re sending it to, you can use this:
      • Replace the “sld=whmcs” with “sld=clientdomain”
      • Replace the “tld=.com” with “tld=clientstld”
      • If the client is using .com, you can leave this the same. If they are using .net you would enter “tld=.net”
    • Product Group Cart Link: This can link to the full group, if you had multiple products in the same group type.
  • Hit Save Changes and your product setup is now complete! You can begin selling that shared product right away.

You can repeat this process by setting up a different package in WHM and then in the “Module Settings” section, you would select that package instead. Just be sure that you adjust the pricing and any options that you need for each product.

If you need to purchase a WHMCS or have further questions, please contact our support team via chat! Happy to help.

Featured Freeware: htop

Featured Freeware highlights some of the Liquid Web staff’s favorite free software. This can range from useful command line tools, open-source packges useful in web-development, or even multi-platform applications. This week we are covering a treasured favorite, htop.

Note: This post assumes you have a working knowledge of top. You can read our article on using top, if you are not familiar with the tool.

htop, or Hisham’s top, is an interactive process viewer for Unix systems. With htop you are provided the same functionality as top, however it provides some needed improvements. Most are in areas where top shows some of it’s age; for example, in htop you can scroll the list of processes vertically and horizontally to see all the process info.

Another benefit is that htop seems to start significantly faster, generally when using top there is a bit of a delay while the program loads up some initial data. So now that you know the basics of how htop differs from top, lets get to using it. First you’ll need to ensure it’s installed on the server and if not we’ll try to get it installed.
Continue reading “Featured Freeware: htop”