{"id":1750,"date":"2018-10-26T09:53:59","date_gmt":"2018-10-26T09:53:59","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=1750"},"modified":"2018-10-27T03:48:13","modified_gmt":"2018-10-27T03:48:13","slug":"howtospeedupawebsiteonubuntu1604","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/26\/howtospeedupawebsiteonubuntu1604\/","title":{"rendered":"How To Speed Up a Website on Ubuntu 16.04 &#8211; LinuxCloudVPS Blog"},"content":{"rendered":"<p>26th October 2018<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2018\/10\/How-to-Speed-Up-Your-Website-on-Ubuntu-16.04.jpg\" alt=\"How to Speed Up Your Website on Ubuntu 16.04\" width=\"750\" height=\"360\" \/><\/p>\n<p>Everyone loves speedy websites and search engines love them as well. If your speedy website is an e-commerce site, you will likely have a better conversion rate. In this article, we will show you how to speed up a website on <a href=\"https:\/\/www.linuxcloudvps.com\/ubuntu-cloud-vps.html\">Ubuntu 16.04<\/a>. Let\u2019s get started with the guide.<\/p>\n<h2>Optimize Images<\/h2>\n<p>Eye-catching images on your website will grab the visitors\u2019 attention. But, at the same time, your images might be too large, both in size or scale. There are many online tools to optimize your images, they can reduce the size but also maintain the quality.<\/p>\n<h2>Use HTTP\/2<\/h2>\n<p>Why do we need to implement this? Because with http\/2 all requests are downloaded in parallel, not in a queue as in http\/1.1. The server can also push data without being requested, which eventually can improve the speed for visitors with high latency.<\/p>\n<p>Support of the HTTP\/2 protocol was introduced in Apache 2.4.26. Unfortunately, the default repository in Ubuntu 16.04 contains a version lower than this, so we need to add a third-party repository.<\/p>\n<h4>Apache<\/h4>\n<p>To make sure what Apache version you have, you can invoke this command:<\/p>\n<p>apache2 -v<\/p>\n<p>If it\u2019s lower than 2.4.26, then we need to install the latest available version.<\/p>\n<p>apt install software-properties-common<\/p>\n<p>add-apt-repository ppa:ondrej\/apache2<\/p>\n<p>apt update<\/p>\n<p>apt-key adv &#8211;keyserver keyserver.ubuntu.com &#8211;recv-keys 4F4EA0AAE5267A6C<\/p>\n<p>apt install apache2<\/p>\n<p>Add this line to your SSL enabled website virtual host, right after &lt;VirtualHost *:443&gt; tag.<\/p>\n<p>Protocols h2 http\/1.1<\/p>\n<p>Now, you need to know that http2 is not compatible with mpm_prefork, so you need to disable it and use another mpm, like mpm_event<\/p>\n<p>a2dismod mpm_prefork<\/p>\n<p>a2enmod mpm_event setenvif proxy_fcgi<\/p>\n<h4>Install PHP-FPM and disable Mod PHP<\/h4>\n<p>apt install php-fpm7.0<\/p>\n<p>a2dismod php7.0<\/p>\n<p>systemctl restart apache2<\/p>\n<p>At this point, your website is running on http\/2, your static assets will be delivered much faster.<\/p>\n<h4>Nginx:<\/h4>\n<p>If you are using nginx, enabling http\/2 is much easier. You can simply add \u201chttp2\u201d in your SSL enabled website\u2019s server block.<br \/>\nIt should be like this:<\/p>\n<p>listen 443 ssl http2;<\/p>\n<p>Support for http\/2 was introduced in Nginx version 1.9.5, and with the default Nginx installation on Ubuntu 16.04, we have nginx version higher than that, so we don\u2019t need to add a third party repository as we do when using Apache.<\/p>\n<h2>Use CDN<\/h2>\n<p>A Content Delivery Network can accelerate your websites, CDN works by caching your static assets in many servers around the globe. If you enabled CDN, and when a visitor from Europe is accessing your website which is hosted on a server located in the USA, the static assets delivered to him\/her will be from a nearer location, not from your server. This will speed up your website loading time. There are many CDN providers nowadays, you can choose one of them.<\/p>\n<h2>Enable Compression<\/h2>\n<p>When you visit a website, your browser will check the website configuration whether it has gzip enabled and request the pages. If it\u2019s enabled, your browser will receive the gzip files which are much smaller than the original one and if it isn\u2019t, your browser will receive the files which usually are much larger. So, enabling compression is another option to take in order to speed up your website, visitors will receive the files faster because files are delivered in a smaller size.<\/p>\n<p>To enable compression, you can add the following to your .htaccess file:<\/p>\n<p>&lt;IfModule mod_deflate.c&gt;<br \/>\n# Compress HTML, CSS, JavaScript, Text, XML and fonts<br \/>\nAddOutputFilterByType DEFLATE application\/javascript<br \/>\nAddOutputFilterByType DEFLATE application\/rss+xml<br \/>\nAddOutputFilterByType DEFLATE application\/vnd.ms-fontobject<br \/>\nAddOutputFilterByType DEFLATE application\/x-font<br \/>\nAddOutputFilterByType DEFLATE application\/x-font-opentype<br \/>\nAddOutputFilterByType DEFLATE application\/x-font-otf<br \/>\nAddOutputFilterByType DEFLATE application\/x-font-truetype<br \/>\nAddOutputFilterByType DEFLATE application\/x-font-ttf<br \/>\nAddOutputFilterByType DEFLATE application\/x-javascript<br \/>\nAddOutputFilterByType DEFLATE application\/xhtml+xml<br \/>\nAddOutputFilterByType DEFLATE application\/xml<br \/>\nAddOutputFilterByType DEFLATE font\/opentype<br \/>\nAddOutputFilterByType DEFLATE font\/otf<br \/>\nAddOutputFilterByType DEFLATE font\/ttf<br \/>\nAddOutputFilterByType DEFLATE image\/svg+xml<br \/>\nAddOutputFilterByType DEFLATE image\/x-icon<br \/>\nAddOutputFilterByType DEFLATE text\/css<br \/>\nAddOutputFilterByType DEFLATE text\/html<br \/>\nAddOutputFilterByType DEFLATE text\/javascript<br \/>\nAddOutputFilterByType DEFLATE text\/plain<br \/>\nAddOutputFilterByType DEFLATE text\/xml<\/p>\n<p># Remove browser bugs (only needed for really old browsers)<br \/>\nBrowserMatch ^Mozilla\/4 gzip-only-text\/html<br \/>\nBrowserMatch ^Mozilla\/4.0[678] no-gzip<br \/>\nBrowserMatch bMSIE !no-gzip !gzip-only-text\/html<br \/>\nHeader append Vary User-Agent<br \/>\n&lt;\/IfModule&gt;<\/p>\n<p>If you are using nginx, the gzip compression is enabled by default, you can check it in \/etc\/nginx\/nginx.conf file.<\/p>\n<h2>Configure Expire Headers<\/h2>\n<p>With expire headers, your browser can check whether it should request the website assets from the server or fetch them from the browser cache. For example, we set an expire headers value for our logo.png file to one month, so the browser will cache the logo.png file and it doesn\u2019t need to request the file as the browser already have it in the cache. Expire headers can reduce the HTTP connection and improve the site loading speed at the same time.<\/p>\n<p>If you use apache, you can add the following lines to your .htaccess file:<\/p>\n<p>&lt;IfModule mod_expires.c&gt;<br \/>\nExpiresActive On<\/p>\n<p># Images<br \/>\nExpiresByType image\/jpeg &#8220;access plus 1 year&#8221;<br \/>\nExpiresByType image\/gif &#8220;access plus 1 year&#8221;<br \/>\nExpiresByType image\/png &#8220;access plus 1 year&#8221;<br \/>\nExpiresByType image\/webp &#8220;access plus 1 year&#8221;<br \/>\nExpiresByType image\/svg+xml &#8220;access plus 1 year&#8221;<br \/>\nExpiresByType image\/x-icon &#8220;access plus 1 year&#8221;<\/p>\n<p># Video<br \/>\nExpiresByType video\/mp4 &#8220;access plus 1 year&#8221;<br \/>\nExpiresByType video\/mpeg &#8220;access plus 1 year&#8221;<\/p>\n<p># CSS, JavaScript<br \/>\nExpiresByType text\/css &#8220;access plus 1 month&#8221;<br \/>\nExpiresByType text\/javascript &#8220;access plus 1 month&#8221;<br \/>\nExpiresByType application\/javascript &#8220;access plus 1 month&#8221;<\/p>\n<p># Others<br \/>\nExpiresByType application\/pdf &#8220;access plus 1 month&#8221;<br \/>\nExpiresByType application\/x-shockwave-flash &#8220;access plus 1 month&#8221;<br \/>\n&lt;\/IfModule&gt;<\/p>\n<p>If you are using nginx, you can add this line to your location block:<\/p>\n<p>if ($request_uri ~* &#8220;.(ico|css|js|gif|jpe?g|png)$&#8221;) {<br \/>\nexpires 30d;<br \/>\naccess_log off;<br \/>\nadd_header Pragma public;<br \/>\nadd_header Cache-Control &#8220;public&#8221;;<br \/>\n}<\/p>\n<h2>Enable Keep-Alive<\/h2>\n<p>HTTP keep-alive means that the browser is using a single TCP connection to send and receive multiple requests. This will speed up the website because your visitors\u2019 browser only needs to open one persistent HTTP connection to the web server. The keep-alive option is enabled by default, but you will want to double check it. To enable keep-alive, you can do the following:<\/p>\n<h4>Apache:<\/h4>\n<p>nano \/etc\/apache2\/apache2.conf<br \/>\nKeepAlive On<\/p>\n<h4>Nginx:<\/h4>\n<p>nano \/etc\/nginx\/nginx.conf<\/p>\n<p>keepalive_timeout 65;<br \/>\nThe value higher than 0 will enable keepalive<\/p>\n<h2>Minify JS and CSS<\/h2>\n<p>Minification is a process to minimize our codes in order to reduce or remove all unnecessary characters from the code without changing its functionality. The unnecessary characters usually include comments, white spaces, new lines, and block delimiters. The characters are actually used to add readability, but we can remove them as they are not required. The code file size can be reduced if it\u2019s minified. But, we have to be careful when minifying our codes because not all spaces can be removed.<\/p>\n<p>Example of CSS minification:<\/p>\n<h4>Before:<\/h4>\n<p>.item_names p a {<br \/>\ncolor: #000;<br \/>\npadding: 10px 0px 0px 0;<br \/>\nmargin-bottom: 5px;<br \/>\nborder-bottom: none;<br \/>\n}<\/p>\n<h4>After:<\/h4>\n<p>.item_names p a<\/p>\n<p>As you can see, the minified version is hard to read. You can also see that not all spaces can be removed, so manually minifying the codes is not recommended.<br \/>\nYou can use any online tools to minify your JS and CSS files.<\/p>\n<p>That\u2019s it, your website should be faster now. If your website is running on WordPress, you can use plugins to do some of the steps above.<\/p>\n<p>Of course, you don\u2019t have speed up your website on Ubuntu 16.04 yourself if you use one of our <a href=\"https:\/\/www.linuxcloudvps.com\/ubuntu-cloud-vps.html\">Ubuntu Cloud Hosting<\/a> services, in which case you can simply ask our expert Linux admins to speed up your website on Ubuntu 16.04 for you. They are available 24\u00d77 and will take care of your request immediately.<\/p>\n<p>PS. If you liked this post on how to speed up your website on Ubuntu 16.04, please share it with your friends on the social networks using the buttons below or simply leave a reply in the comments sections. Thanks.<\/p>\n<p>Be the first to write a comment.<\/p>\n<p><a href=\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-speed-up-a-website-on-ubuntu-16-04\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>26th October 2018 Everyone loves speedy websites and search engines love them as well. If your speedy website is an e-commerce site, you will likely have a better conversion rate. In this article, we will show you how to speed up a website on Ubuntu 16.04. Let\u2019s get started with the guide. Optimize Images Eye-catching &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/26\/howtospeedupawebsiteonubuntu1604\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How To Speed Up a Website on Ubuntu 16.04 &#8211; LinuxCloudVPS Blog&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1750","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1750","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=1750"}],"version-history":[{"count":2,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1750\/revisions"}],"predecessor-version":[{"id":1787,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1750\/revisions\/1787"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=1750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=1750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=1750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}