How to optimize WordPress with Ubuntu VPS

Ubuntu Virtual Private Server optimized for WordPress

Author: .

  • How to add Google Tag Manager code to the Thesis 2.1 WordPress framework and theme

    Tidy up your code and gather all your stats and conversions tags in one place. Manage tags for all your websites in one place.

    • Google Analytics
    • Google AdWords remarketing
    • Google Adwords conversion
    • Facebook ads tracking
    • Twitter ads tracking
    • Microsoft Bing Ad Center ads tracking
    • Linked In ads tracking
    • – and much more

    Adding tags without efficient management would potentially cause trouble. All that code bogs down your site. Redundant or incorrectly applied tags can distort your measurement and result in duplicate costs or missing data. And it can be time-consuming for the IT department or webmaster team to add new tags, which means important marketing and measurement programs could suffer from delay. With Google Tag Manager, you eliminate these problems—and run your campaigns when you need them.

     

     

     

    Google Tag Manager
    http://www.Google.com/tagmanager/

    WordPress plugin to add extra functionality to Tag Manager, Google Analytics, AdWords and more:
    https://WordPress.org/plugins/duracelltomi-google-tag-manager/

    Tips on how to use the plugin
    http://DuracellTomi.com/

    Thesis is the ultimate design and template manager for WordPress
    http://DIYthemes.com

     

     

     

    You need to add the PHP code below in the file named

    custom.php

    This PHP-file is available in the folder:

    /wp-content/thesis/skins/YOUR-THEME-NAME/custom.php

    I use a theme from  http://Themedy.com called Junction 2

    The path to my custom.php is:

    /wp-content/thesis/skins/junction-t2/custom.php

     

    This is the PHP code to add to your custom.php file in Thesis:

     

     

     

    // Google TagManager START
    function injectTagManager() {
    ?>
    
    <?php if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) { gtm4wp_the_gtm_tag(); } ?>
    
    
    <?php
    }
    
    add_action('hook_before_html','injectTagManager');
    
    
    function injectDataLayer() {
    ?>
    <script>
    var dataLayer = [];
    </script>
    <?php
    }
    
    
    add_action('wp_head','injectDataLayer');
    
    // Google TagManager STOPP
    

     

     

     

    If you don’t want to use the WordPress plugin, and instead place the full Google Tag Manager code, please use this code:

     

     

     

    // Google TagManager START
    function injectTagManager() {
    ?>
    
    <!-- Google Tag Manager -->
    <noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-XXXXX"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','dataLayer','GTM-XXXXX');</script>
    <!-- End Google Tag Manager -->
    
    
    
    
    <?php
    }
    
    add_action('hook_before_html','injectTagManager');
    
    
    function injectDataLayer() {
    ?>
    <script>
    var dataLayer = [];
    </script>
    <?php
    }
    
    
    
    add_action('wp_head','injectDataLayer');
    
    
    // Google TagManager STOPP
    
    
  • Keyword research tools for copywriting

    When writing a post on a matter that you are an expert on. Then the only external resource you would need is tools to help you generate a list of long tail keywords and ordinary keywords. Finding the right set of keywords is critical to obtain favorable SEO visibility.

    Toast is one of the main authorities on SEO with his software, e-books, courses other products.

    Infographics about choosing keyword

    Double click the image to magnify to a readable size.

    Infograpic
    Push the picture to use the  infographic

    Keyword research tools recommend by Yoast.com

    https://www.google.com/trends/

    https://yoast.com/suggest/

    https://adwords.google.com/KeywordPlanner

    http://tools.seobook.com/keyword-tools/seobook/  – Powered by WordTracker

    Other keyword research tools

    https://ubersuggest.io/

    http://www.wordstream.com/keywords

    https://www.wordtracker.com

    http://KeywordTool.io

    https://www.semrush.com

    https://moz.com/products/pro/keyword-explorer

    https://kwfinder.com

    http://www.spyfu.com/?v=14

    http://www.keywordspy.com

    http://www.keyworddiscovery.com/search.html

    https://serps.com/tools/keyword-research/

    Blog post analysis tools

    http://buzzsumo.com

     

     

    Disavow backlinks

    https://support.google.com/webmasters/answer/2648487?hl=en

    https://moz.com/researchtools/ose/

    https://majestic.com

     

    Other tools

    https://www.QuickSprout.com

    https://ahrefs.com/content-explorer

    https://twitter.com/search-advanced

    https://www.quora.com

    https://www.semrush.com

     

     

    Paid tools

    http://www.longtailpro.com/

    Software

    http://www.marketsamurai.com/full-version/wdcu5b/

     

     

  • The process of copywriting for affiliate marketing

    Copywriting for affiliate marketing requires quality and volum. Quality is much more important than volume, but you still need volume. This is outlines the process of creating high ranking, high quality content.

     

    A. Decide what content you will produce

     

    B. Research keywords. Research other post related to the same content.

     

    C. Decide about and select both longtails- and common keywords

     

    D. Research the content if required

     

    C. Write the content

     

    D. Add illustrations

     

    E. Verify that the post is SEO friendly

    Making the post SEO friendly is a process that permeates everything you do. Traffic is what generates a sale. SEO is one of the things that generates traffic. Traffic has many other sources than SEO. SEO is a long tail traffic generator.

    F. Schedule publishing

     

    G. After publishing you should promote the post

     

    H. After some months or years re-promote the post. Update the post if needed or if it will make the post better.

     

  • WooCommerce and W3C Total Cache settings

    WooCommerce extra configuration steps

    InstallingDOMDocument

    WooCommerce needs DOMDocument to create HTML emails

    sudo apt-get install php-xml

    Install Multibyte String

    To display none-English characters you should install:

    sudo apt-get install php7.0-mbstring

    W3C Total Cache additional configuration steps

    Enable 2 Apache modules

    sudo a2enmod expires
    sudo a2enmod headers
    sudo service apache2 restart

    Enable compression in php.ini

    Do not zlib.output_compression if you are using W3C Total Cache.

    sudo nano /etc/php/7.0/apache2/php.ini

    Use “Ctrl”+”W” and search for zlib.output_compression and change the value from Off to On

    zlib.output_compression = On

    The directive zlib.output_compression_level is used to adjust the compression level. Set the value between 1 and 9. Choose 1 to get the least compression or 9 to get most. The default value is six which balances compression without degrading the servers performance.

    zlib.output_compression_level = 6

    Finally, restart Apache, so the changes take effect.

    sudo service apache2 restart
  • Install GD and ImageMagick on Ubuntu 16 LTS and PHP7

    PHP GD is required on WordPress and plugins like Imsanity to resize images.

    Install GD with this command

    sudo apt-get install php7.0-gd

    Then restart Apache

    To crop images with the built-in image editor in WordPress image magick is required

    sudo apt-get install imagemagick

     

    sudo service apache2 restart
  • TrustPilot vs Google Reviews. How to make the move.

    We simply don’t need all the nice features that Trustpilot provides. We will keep our current Trustpilot account and use Google Review as the primary for future reviews. Here is how we made the change and got a few bonuses along the road.

    Step one, get the link where the customer writes the review

    Use one of the numerous Google Review Link Generator to generate the link where customers leave their review.

    Step two, install the plugin that displays the reviews in WordPress.

    Next step is to install a WordPress plugin that enables you to view the reviews in WordPress as a separate page, a widget in the sidebar or wherever you like. The plugin comes in two versions. A basic free limited version and a Pro version. At the time of writing, this is the only Google Review plugin.

    [themedy_button url=”https://www.wpjeos.no/out/021-wordimpress-com” icon=”wordpress” font_awesome_att=”” label=”Get the WordPress Review Plugin” colour=”blue” colour_custom=”” size=”large” edge=”rounded” target=”_self”]

     

     

  • Set permissions Apache and user ubuntu

    Many of the things we have accomplished when configuring our VPS server is done as the user “root”. This is a obstacle to Apache webserver, WordPress and the tools we use to manage the server. We need to give Apache the required permissions to work correctly.

    We want to be able to control the server with tools like an SSH client, SFTP client, WP-CLI, and WordShell. We will need to give the VPS user “ubuntu” the required access to the files and folders that constitute WordPress.

    Short version:

    Change the permission on /var/www/ and all subfolder with the following command:

    sudo chown -R ubuntu /var/www/ && sudo chown -R www-data /var/www/ && sudo chgrp -R www-data /var/www/ && sudo find /var/www/ -type f -exec chmod 644 {} \; && sudo find /var/www/ -type d -exec chmod 755 {} \; && sudo chown www-data:www-data -R /var/www/ && sudo usermod -aG www-data ubuntu && sudo chmod -R g+w /var/www/

    Change ownership and delegate access

    To verify that the permissions are correct:

    cd /var/www/MyDomain1.com

    Then issue the command:

    sudo ls -l /var/www/MyDomain1.com

    Both the user and group should be “www-data“. If this is not the case, then here is how to correct this:

    Set the right permissions on files and folders

    The Apache web server needs permission to run WordPress.
    Change the owner of the files with this command:

    sudo chown -R www-data /var/www/MyDomain1.com

    moreover, alter the group with this command:

    sudo chgrp -R www-data /var/www/MyDomain1.com

    Set all files to 644 with this command

    sudo find /var/www/MyDomain1.com/ -type f -exec chmod 644 {} \;

    Set all folders to 755 with this:

    sudo find /var/www/MyDomain1.com/ -type d -exec chmod 755 {} \;

    The WordPress configuration file wp-config.php needs extra protection with the 660 rights

    sudo chmod 660 /var/www/MyDomain1.com/wp-config.php

    Apache needs access both as a group and a user.

    sudo chown www-data:www-data -R /var/www/MyDomain1.com/

    Get access with SFTP, WP-CLI, and WordShell

    The user ubuntu needs to access the websites directory tree and home folder with the admin tools SFTP, SSH, WP-CLI, and WordShell.
    This command adds the user ubuntu to the group www-data:

    sudo usermod -aG www-data ubuntu

    and

    sudo chmod -R g+w /var/www/MyDomain1.com

    If needed restart SSHD or the VPS server to make sure that the permission has taken effect.
    To reset the SSHD server

    sudo systemctl restart sshd.service

    To reset the Apache server

    sudo service apache2 restart

    Or restart the VPS server:

    sudo restart now

    Chaining the commands together

    When you are setting up many sites try chaining together the commands using

    &&

    This will run all the commands one-by-one. If something goes wrong. The process will stop with an error message.

    sudo chown -R www-data /var/www/html/ && sudo chgrp -R www-data /var/www/html/ && sudo find /var/www/html/ -type f -exec chmod 644 {} \; && sudo find /var/www/html/ -type d -exec chmod 755 {} \; && sudo chown www-data:www-data -R /var/www/html/ && sudo usermod -aG www-data ubuntu && sudo chmod -R g+w /var/www/html/ && sudo chmod 660 /var/www/html/wp-config.php

    To make sure that the changes take effect. Restart apache and the SSHD server:

    sudo systemctl restart sshd.service
    
    sudo service apache2 restart

    Chaining commands are faster than running all these commands once at a time:

    sudo chown -R www-data /var/www/html
    
    sudo chgrp -R www-data /var/www/html
    
    sudo find /var/www/html -type f -exec chmod 644 {} \;
    
    sudo find /var/www/html -type d -exec chmod 755 {} \;
    
    sudo chown www-data:www-data -R /var/www/html/
    
    sudo usermod -aG www-data ubuntu
    
    sudo chmod -R g+w /var/www/html

    When you have many VPS servers

    WordPress JeOS servers are budget friendly. Instead of running the heavy load on a single server, it could be wise to distribute your WordPress sites to several EC2 VPS servers.
    Use your SSH client and log in to MyServer1.com, MyServer3.com, and MyServer2.com and verify that the user “ubuntu” has the rights to perform actions on all your websites on all of your VPS servers.

    When you want to WordShell to administer many VPS servers you need to configure SSH as described here:
    [themedy_button url=”https://www.wpjeos.no/prepare-ssh-file-folders-wordshell/” icon=”” font_awesome_att=”” label=”Setting up SSH to work with WordShell” colour=”blue” colour_custom=”” size=”large” edge=”rounded” target=”_self”]

    After this, you would be ready to administer all your WordPress sites on all of your VPS servers with WordShell, WP-CLI, SFTP and SSH from your mobile, tablet, Windows, Mac or whatever you choose as your favorite tools.