<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nino Mihovilić</title>
    <description>The latest articles on DEV Community by Nino Mihovilić (@ninodevo).</description>
    <link>https://dev.to/ninodevo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F488576%2Fe7111770-6b86-4ebf-8db1-cc2ac2840626.jpeg</url>
      <title>DEV Community: Nino Mihovilić</title>
      <link>https://dev.to/ninodevo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ninodevo"/>
    <language>en</language>
    <item>
      <title>Easy WordPress theme deployment using Deployer</title>
      <dc:creator>Nino Mihovilić</dc:creator>
      <pubDate>Mon, 19 Apr 2021 10:29:21 +0000</pubDate>
      <link>https://dev.to/bornfightcompany/easy-wordpress-theme-deployment-using-deployer-2ie7</link>
      <guid>https://dev.to/bornfightcompany/easy-wordpress-theme-deployment-using-deployer-2ie7</guid>
      <description>&lt;p&gt;In this article, I’ll show you an easy and fast way how to set up WordPress theme deployment without downtime using Deployer in 5 steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table Of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Setting up Deployer&lt;/li&gt;
&lt;li&gt;Setting up the Server&lt;/li&gt;
&lt;li&gt;Setting up SSH Agent Forwarding&lt;/li&gt;
&lt;li&gt;Setting up deploy.php&lt;/li&gt;
&lt;li&gt;Testing our Script&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 1 &lt;a&gt; - Setting up Deployer
&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://deployer.org/docs/getting-started.html" rel="noopener noreferrer"&gt;Deployer&lt;/a&gt; is a simple &lt;strong&gt;open-source&lt;/strong&gt; PHP-based &lt;strong&gt;deployment&lt;/strong&gt; tool. It’s easy to use and set up.&lt;/p&gt;

&lt;p&gt;There are multiple ways to &lt;strong&gt;install&lt;/strong&gt; the tool on their website but the easiest way is to run these 3 commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -LO https://deployer.org/deployer.phar
mv deployer.phar /usr/local/bin/dep
chmod +x /usr/local/bin/dep
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check if everything is installed ok run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dep
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2 &lt;a&gt; - Setting up the Server
&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;In this tutorial, we will be using AWS Lighstail, but you can use any other server.&lt;br&gt;
The only requirement is that you have &lt;strong&gt;SSH Access&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Creating an instance - you can skip this part if you have a server and SSH access
&lt;/h4&gt;

&lt;p&gt;Log in to your AWS account and search for Lightsail in the search bar. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr7g6c2bzs1xv8xyo0hmq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr7g6c2bzs1xv8xyo0hmq.png" alt="Lightsail"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create an instance using the WordPress blueprint and Linux platform. When the server is up and running, open the server terminal and add your public SSH key to the &lt;strong&gt;~/.ssh/authorized_keys&lt;/strong&gt; file.&lt;/p&gt;
&lt;h4&gt;
  
  
  Setting up GIT
&lt;/h4&gt;

&lt;p&gt;We need &lt;strong&gt;Git&lt;/strong&gt; on the server because &lt;strong&gt;Deployer&lt;/strong&gt; will pull the theme from the repository. &lt;/p&gt;

&lt;p&gt;As we are on a Linux-based server, the command to install git is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To verify the installation run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3 - Setting up SSH Agent Forwarding
&lt;/h3&gt;

&lt;p&gt;To be able to pull the repository, the server needs access to it. We can use &lt;strong&gt;deploy keys&lt;/strong&gt; or &lt;strong&gt;SSH Agent Forwarding&lt;/strong&gt;. Both ways are pretty straightforward when it comes to the set up, but we will go with Agent Forwarding in this tutorial.&lt;/p&gt;

&lt;p&gt;On your local machine position yourself in the &lt;strong&gt;~/.ssh&lt;/strong&gt; folder. If it doesn't exist, create a file named "config".&lt;br&gt;
Enter the following text into the file, replacing example.com with your server's domain name or IP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host example.com
  ForwardAgent yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key must be available to &lt;strong&gt;ssh-agent&lt;/strong&gt;. You can check that by running the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-add -L
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the command says that no identity is available, you'll need to add your key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-add yourkey
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*For your server SSH Agent Forwarding troubleshooting refer to this tutorial -&amp;gt; &lt;a href="https://docs.github.com/en/developers/overview/using-ssh-agent-forwarding" rel="noopener noreferrer"&gt;Using SSH Agent Forwarding&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4 &lt;a&gt; - Setting up deploy.php
&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Deploy.php&lt;/strong&gt; is the main &lt;strong&gt;config file&lt;/strong&gt; for Deployer. As we want to only deploy the WordPress theme, we will put the deploy.php in the &lt;strong&gt;theme root&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Position yourself in the theme root and enter the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dep init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will need to provide some basic info. Choose the &lt;strong&gt;0 - Common script&lt;/strong&gt; as it has the basic stuff that we need. &lt;br&gt;
Next, enter your theme repository. In the repository, only the theme files should be present. &lt;br&gt;
In the last step, you can choose to submit anonymous usage information to the PHP-Deployer community.&lt;br&gt;
Now we have the basic deploy.php file. We will do some &lt;strong&gt;changes&lt;/strong&gt; to make our script work.&lt;/p&gt;

&lt;p&gt;First, let's name our application/theme:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set('application', 'my_project');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can enter anything but let's put our theme name: "super-theme".&lt;/p&gt;

&lt;p&gt;We will set a new variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set('theme_dir', 'path_to_themes_folder');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we need to enter the &lt;strong&gt;server path to the themes folder&lt;/strong&gt;. In our example, we used AWS Lightsail with preinstalled WordPress so the path is: "/home/bitnami/apps/wordpress/htdocs/wp-content/themes".&lt;/p&gt;

&lt;p&gt;Next, we set the host and modify it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;host( 'project.com_or_IP' )
    -&amp;gt;set( 'branch', 'master' )
    -&amp;gt;user( 'bitnami' )
    -&amp;gt;set( 'deploy_path', '~/{{application}}' )
    -&amp;gt;forwardAgent();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can use the &lt;strong&gt;domain name or IP&lt;/strong&gt; for the host. We set up the &lt;strong&gt;branch&lt;/strong&gt; that we want to deploy, the &lt;strong&gt;SSH user&lt;/strong&gt; in our case "bitnami". &lt;br&gt;
The &lt;strong&gt;deploy_path&lt;/strong&gt; contains the deployment path on the server that can be left as is, and we enable &lt;strong&gt;Agent Forwarding&lt;/strong&gt; so that our local SSH key is used for pulling the repository on the server.&lt;/p&gt;

&lt;p&gt;For our script, we need to add an &lt;strong&gt;additional task&lt;/strong&gt; that symlinks the current folder to the themes folder so that we can have the latest theme active after the deployment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;task( 'deploy:theme', function () {
    run( 'ln -sfn {{deploy_path}}/current {{theme_dir}}/{{application}}' );
} );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last part is to &lt;strong&gt;add&lt;/strong&gt; the created task to the main task &lt;strong&gt;"deploy"&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;task( 'deploy', [
    'deploy:info',
    'deploy:prepare',
    'deploy:lock',
    'deploy:release',
    'deploy:update_code',
    'deploy:shared',
    'deploy:writable',
    'deploy:vendors',
    'deploy:clear_paths',
    'deploy:symlink',
    'deploy:theme',
    'deploy:unlock',
    'cleanup',
    'success'
] )-&amp;gt;desc( 'Deploy your theme' );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We added the "deploy:theme" task after the current symlink is created.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;whole file&lt;/strong&gt; should look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

namespace Deployer;

require 'recipe/common.php';

// Theme name
set( 'application', 'super-theme' );

// Theme repository
set( 'repository', 'git_repository' );

// Theme directory
set( 'theme_dir', '/home/bitnami/apps/wordpress/htdocs/wp-content/themes' );


// [Optional] Allocate tty for git clone. Default value is false.
set( 'git_tty', TRUE );

// Shared files/dirs between deploys
add( 'shared_files', [] );
add( 'shared_dirs', [] );

// Writable dirs by web server
add( 'writable_dirs', [] );
set( 'allow_anonymous_stats', FALSE );


// Hosts
host( 'project.com_or_IP' )
    -&amp;gt;set( 'branch', 'master' )
    -&amp;gt;user( 'bitnami' )
    -&amp;gt;set( 'deploy_path', '~/{{application}}' )
    -&amp;gt;forwardAgent();


task( 'deploy:theme', function () {
    run( 'ln -sfn {{deploy_path}}/current {{theme_dir}}/{{application}}' );
} );

/**
 * Main task
 */
task( 'deploy', [
    'deploy:info',
    'deploy:prepare',
    'deploy:lock',
    'deploy:release',
    'deploy:update_code',
    'deploy:shared',
    'deploy:writable',
    'deploy:vendors',
    'deploy:clear_paths',
    'deploy:symlink',
    'deploy:theme',
    'deploy:unlock',
    'cleanup',
    'success'
] )-&amp;gt;desc( 'Deploy your theme' );

// [Optional] If deploy fails automatically unlock.
after( 'deploy:failed', 'deploy:unlock' );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5 &lt;a&gt; - Testing our Script
&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;To run our script we enter the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dep deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything is &lt;strong&gt;successful&lt;/strong&gt; it should look like this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9midvc9gsw3457vz8i09.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9midvc9gsw3457vz8i09.png" alt="Successful deploy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If something is wrong you can use the verbose mode to debug:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dep deploy -v, provides default installation view with the least information 
dep deploy -vv, provides some more details as compared with the default mode 
dep deploy -vvv, provides a detailed view of the installation output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Those are the 5 steps for a fast deployment setup for a WordPress theme.&lt;br&gt;
 If you use the same server for all of your projects you can set up this only once and only modify the variables in the deploy.php file.&lt;/p&gt;

&lt;p&gt;There are many ways to manage a WordPress theme and set up deployments. I find this an easy way to quickly set up the workflow, what do you think?&lt;/p&gt;

</description>
      <category>engineeringmonday</category>
      <category>wordpress</category>
      <category>deployment</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
