Tag Archives: Apache

How To Enable mod_expires With WordPress Plugins For A Better Site Performance?

If you’re using WordPress, you can enable mod_expires and set up caching rules easily using plugins. This method doesn’t require manual server configuration and can help you boost your website’s speed.

Several WordPress plugins can enable mod_expires and set up caching rules. Popular options include: WP Super Cache, W3 Total Cache, WP Rocket, and Hummingbird. For this lesson, let’s focus on W3 Total Cache and WP Super Cache, as they are free and commonly used.

To enable mod_expires through WordPress plugins, you can set up caching rules without manually configuring the server. This helps to improve your website’s loading speed and overall performance. Here’s how to do it using popular caching plugins for WordPress.

Step 1 Installing W3 Total Cache Plugin

Start by installing and activating the W3 Total Cache plugin. Navigate to the WordPress Dashboard, go to Plugins, then Add New, and search for W3 Total Cache.

Step 2 Enabling mod_expires With W3 Total Cache

After activation, go to Performance > Browser Cache in the WordPress dashboard. There, you will find an option to enable the “HTTP (Expires) Header” for different content types, such as CSS, JavaScript, and HTML.

Make sure to check the box for each relevant type and configure the expiration settings.

For example, you could set the “Expires header lifetime” to one week for CSS and JavaScript, while setting it to one month for images. Don’t forget to save your settings and purge the cache afterward.

Step 1 Installing WP Super Cache Plugin

Start by installing and activating the WP Super Cache plugin. Navigate to the WordPress Dashboard, go to Plugins, then Add New, and search for WP Super Cache.

Step 2 Enabling mod_expires Using WP Super Cache

Activate the WP Super Cache plugin. Next, go to the WordPress Dashboard, select Plugins, and then Add New. Search for WP Super Cache, install it, and activate the plugin.

Now, head over to Settings > WP Super Cache > Advanced. In this section, you will find an “Expiry Time & Garbage Collection” area.

Enable the “Cache HTTP headers with expires” option, and set an appropriate expiration time for your content.

For instance, 3600 seconds (1 hour) may work for dynamic content, whereas static files like images could have a longer expiration period. Once you’ve made these adjustments, update the status.

Step 3 Verify That Cache Is Working (Common Step)

Clear your site cache through the plugin’s settings to apply all changes. You can then check the HTTP headers using the developer tools in your browser or online services like GTmetrix. This will help confirm that the “Expires” or “Cache-Control” headers are correctly set.

By following these steps, you can easily enable mod_expires through plugins like W3 Total Cache and WP Super Cache, optimizing caching rules for better website performance without directly modifying server configurations.

How To Enable mod_expires To Cache Your Website Files For Speed?

Mod_Expires is a built-in module for the Apache web server, available on all Sangkrit.net hosting plans. This module leverages the functionality of mod_expires to manage how long a client’s web browser caches website resources.

Here’s how it works: Mod_Expires manipulates the “Expires” headers sent by the hosting server. This gives you control over how long a browser stores cached copies of website resources. By adjusting these cache durations, you can optimize your site’s performance while considering your website’s update frequency.

Important Note: If the server response already includes an “Expires” header (e.g., generated by a CGI script or a proxied origin server), Mod_Expires won’t modify or add an “Expires” or “Cache-Control” header in those cases.

How To Enable mod_expires Via .htaccess?

If Mod_Expires is not enabled you will need to enable it in your .htaccess file which is present in your website’s root directory, sometimes hidden and can be viewed by changing the view option from the top right corner of cPanel’s file manager. You can enable it on a per-directory basis and it applies recursively.

Sangkrit.net uses the vendor-provided code from Apache mod_expires. Apache HTTPD documentation is accurate for using .htaccess files on your hosting account.

Locate your .htaccess file: This file is usually located in your website’s root directory (e.g., /var/www/html/). The following given example enables mod_expires for a set of common image types and CSS files:

# Activate mod_expires for this directory
ExpiresActive on
# locally cache common image types for 7 days
ExpiresByType image/jpg "access plus 7 days"
ExpiresByType image/jpeg "access plus 7 days"
ExpiresByType image/gif "access plus 7 days"
ExpiresByType image/png "access plus 7 days"
# cache CSS files for 24 hours
ExpiresByType text/css "access plus 24 hours"

Similarly, you can configure mod_expires in your .htaccess file with more options by adding extra caching rules.

Open the .htaccess file and add the following code to specify the caching duration for different file types:

<IfModule mod_expires.c>
    ExpiresActive On
    # Set expiration for images
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    # Set expiration for CSS and JavaScript
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType text/javascript "access plus 1 week"
    # Set expiration for other file types
    ExpiresByType text/html "access plus 1 day"
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresDefault "access plus 1 week"
</IfModule>

How To Enable mod_expires Via Apache Server?

Alternatively, if you have root or administrative access to your server you can enable mod_expires directly in Apache by using the command line. Simply, access your server and do as directed.

Step-1 Enable the module by running the following command:

bash
sudo a2enmod expires

Step-2 After enabling the module, restart Apache to apply the changes. Simply use the following command for restarting apache :

bash
sudo service apache2 restart

Now clear your browser cache to ensure you see the latest changes.

You may also check HTTP headers by using browser developer tools (Network tab) to confirm that the “Expires” or “Cache-Control” headers are set correctly for the specified file types.

By enabling mod_expires, you can significantly reduce page load times, as browsers will cache static files and serve them locally on subsequent visits.

How To Enable Mod_Expires Via WordPress Plugins?

WordPress users may also use some cache plugins such as WP Super Cache or W3 Total Cache to get this thing done from their admin area dashboard. Read this lesson to know the complete process.

Installing & Configuring Apache On Your Dedicated Server

Before installing PHP or MySQL, the first thing you need to do is install Apache on your dedicated server. In order to do that you simply need to access the command line of your server and log in as the root user:

  1. Connect your server via SSH
  2. Run this command: sudo su –
  3. Enter your server password

You now have root access.

Once you have that, you can install Apache using the ‘Yum‘ command:

[root@admin]# yum install httpd
Loaded plugins: fastestmirror, langpacks
base
| 3.6 kB 00:00:00
extras
| 3.4 kB 00:00:00
updates
| 3.4 kB 00:00:00
extras/7/x86_64/primary_d
| 121 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirror.sigmanet.com
* extras: linux.mirrors.es.net
* updates: mirror.eboundhost.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-45.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-45.el7.centos for package:
httpd-2.4.6-45.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.645.el7.centos.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-45.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
Installed:
httpd.x86_64 0:2.4.6-45.el7.centos

Dependency Installed:
httpd-tools.x86_64 0:2.4.6-45.el7.centos
mailcap.noarch 0:2.1.41-2.el7

Complete!
[root@admin]#

Once Apache is installed, the next thing you need to do is configure it and then make sure it works on your server, use the following command:

[root@admin]# systemctl start httpd && systemctl enable httpd

To make sure the Apache services are running on your server:

[root@admin] sudo systemctl status httpd

This will show you an active status if the service is running on your dedicated server.

Managing Apache & PHP Modules On Your Server

You can install necessary PHP modules for Apache on your VPS and Dedicated Server and then enable them manually.

You can enable, disable, or customize such modules using a tool called EasyApache. By using this tool, the PHP and Apache options are rebuilt on the basis of the options you select.

  1. Login to your SANGKRIT.net account
  2. Visit your My Products page
  3. Click the Servers option
  4. Click Manage
  5. Open WHM

The easiest way to upgrade PHP is through EasyApace which you can find in the software section of WHM:

  1. Lookup for EasyApache using the search box on the left section of WHM
  2. Click to open it then click EasyApache (ApacheUpdate) option
  3. This will open the present time Apache Configuration Profile
  4. Click the gear icon for a customized profile option
  5. You will see Apache wizard guiding you through various steps
  6. Here, select the Apache version
  7. Then, select your PHP versions
  8. Next, from the Short Options List, select the features you like to include in your Apache
  9. You can enable the modules you like to add and you can also disable the modules which you don’t want
  10. For more configuration options you may click the Exhaustive Options List
  11. Finally, select the Save and Build option

In the Exhaustive Options List, you can select or deselect various other modules. There is also an option called Save Only that only saves your profile and doesn’t starts the building process.

To start building you will need to click Save and Build option as explained above. Once you click this option, do not close your browser window and wait for the process to complete.

This may take some time depending on the options you have selected and the power of your server. If you are using a small server with limited resources then you should not enable many options at once and instead enable a few options first and then repeat the process for enabling more modules.

How To Configure PHP Directives On Your Server?

PHP allows you to control different aspects of your websites by using directives in php.ini files. These files contain the default configuration for the operation of PHP applications.

By using PHP directives you can control different variables such as upload size, file timeout, and resource limit, etc of websites running on your hosting, VPS, or dedicated server.

To add or edit a PHP directive – Log in to your SANGKRIT.net account and follow these steps:

  1. Open cPanel of your server or hosting option
  2. Navigate to the File Manager interface via cPanel -> Home -> Files -> File Manager
  3. Make sure that hidden files are visible to you or you can enable them via Settings, by ticking the Show hidden files checkbox option
  4. Navigate to the target directory.
  5. Create a new file – click New File / + File button
  6. Enter .user.ini filename
  7. Click Create New File button
  8. Select the new file from the list of files and click Edit
  9. Now enter the PHP directives you wish to adjust for the present directory
  10. Click the Save button

INI files can be configured on per-directory basis and are processed only by the CGI/FASTCGI SAPI. This functionality obsoletes the PECL htscanner extension. If you are running PHP as an Apache module then the .htaccess file will do your thing.

In addition to the main INI file, PHP scans each directory for its INI file. In a case where the PHP file has been kept outside the document root, only its directory is scanned.

Easily Add/Remove WWW From WordPress Admin Area

Now you can configure WordPress to always or never use www. in all internal links on your website. By default this setting is configured from domain management page. But in this lesson we will show you how you can change this setting from your admin area dashboard.  Continue reading Easily Add/Remove WWW From WordPress Admin Area

How To Install & Configure phpMyAdmin On Ubuntu 12.04 & Greater Versions?

phpMyAdmin is a free software that provides you a user friendly interface to work with MySQL on the web. It simply provides you a convenient visual frontend to access MySQL capabilities. This tutorial shows you the steps for installing phpMyAdmin on Ubunu Linux so before installing it make sure you must have root privileges on your virtual private server.

Continue reading How To Install & Configure phpMyAdmin On Ubuntu 12.04 & Greater Versions?

Different Ways Of Increasing PHP Memory Limit When Using WordPress

Increasing PHP limit is easy. The most popular method of increasing PHP limit is by editing the PHP.ini file which is present on your site’s root directory. But here are few more menthods you can use for increasing PHP memory limit in your WordPress site.

Continue reading Different Ways Of Increasing PHP Memory Limit When Using WordPress

How To Restrict Other Servers From Accessing Your Files ?

If your site stores popular image files then for reducing bandwidth usage you can use this Apache hack for denying servers to access your files. Open your sites .htaccess file for editing and add the following code:

<FilesMatch “.(gif|jpe?g)$”>
SetEnvIf Referer “^http://([^/]*.)?mydomain.com/” request_ok = 1
Order Allow, Deny
Allow from env=request_ok
</FilesMatch>

This restricts other domains form accessing all GIF or JPG files in  your website.

How To Configure Apache WebSite To Use Multiple Ports ?

  1. Open httpd.conf file in your host.
  2. Find Listen 80 and on the next line add Listen 8080
  3. Find VirtualHost section for your Site config.
  4. Add *:8080. It should look like this: <VirtualHost *:80 *:8080>
  5. Restart Apache
  6. Test your work by hitting your site to the new port number. Example: http://www.yoursite.com:8080

This would be helpful for you if your ISP is blocking any port. You can add an alternate port in your website. Here we have used port 8080 but you are free to use any other.

Creating Temporary And Permanent Redirects Using Apache

301 is a permanent redirect and 302 is a temporary redirect. 301 redirect is used when you want to redirect pages without penalizing them in search engines. And 302 redirect is used when you want to set up temporary redirect for keeping your page rank better in search engines. Learn more.

How To Set Up Permanent Redirect Using Apache ?

Open your site’s .htaccess file.

If there is no .htaccess redirect then create a new text file in your site’s root.

Add this line at the very end of your .htaccess file:

Redirect 301 /REDIRECT_PATH NEW_URL

Where:

REDIRECT_PATH = Directory path on your web server. And

NEW_URL = Is the path you want the pages redirected to.

Save the file and test your URL.

Example: 

Redirect 301 /tags/lamp/ https://www.sangkrit.net/tags/lamp/

How To Set Up Temporary Redirect Using Apache ?

Open your site’s .htaccess file.

If there is no .htaccess redirect then create a new text file in your site’s root.

Add this line at the very end of your .htaccess file:

Redirect 302 /REDIRECT_PATH NEW_URL

Where:

REDIRECT_PATH = Directory path on your web server. And

NEW_URL = Is the path you want the pages redirected to.

Save the file and test your URL.

Example:

Redirect 302 /tags/lamp/ https://www.sangkrit.net/tags/lamp/

Difference Between Permanent And Temporary Redirects

301 redirect is a permanent redirect whereas 302 is a temporary redirect. Permanent redirects tell search engines that old URL is out so that they can pull this new URL in it’s place. 301 is used when you want to preserve the page index and keep the page rank.