<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ubuntu - Architect the cloud</title>
	<atom:link href="https://blog.slepcevic.net/tag/ubuntu/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.slepcevic.net</link>
	<description></description>
	<lastBuildDate>Fri, 20 Oct 2023 12:00:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>From zero to WordPress in less than 2 minutes on Linode using cloud-init and/or Terraform</title>
		<link>https://blog.slepcevic.net/from-zero-to-wordpress-in-less-than-2-minutes-using-linode-and-cloud-init-and-or-terraform/</link>
					<comments>https://blog.slepcevic.net/from-zero-to-wordpress-in-less-than-2-minutes-using-linode-and-cloud-init-and-or-terraform/#respond</comments>
		
		<dc:creator><![CDATA[Alesandro Slepčević]]></dc:creator>
		<pubDate>Fri, 20 Oct 2023 11:53:34 +0000</pubDate>
				<category><![CDATA[Akamai Connected Cloud]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[cloud-init]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Linode]]></category>
		<category><![CDATA[Terraform]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[wordpress]]></category>
		<guid isPermaLink="false">http://172.233.40.105/blog.slepcevic.net/?p=185</guid>

					<description><![CDATA[<p>Yeah, it&#8217;s true. You can get a fully running VM with installed MySQL, Apache, PHP and WordPress configured in less than 2 minutes! 1:58 to be exact 🙂 Ok, what is cloud-init in the first place? Cloud-init is a widely...</p>
<p>The post <a href="https://blog.slepcevic.net/from-zero-to-wordpress-in-less-than-2-minutes-using-linode-and-cloud-init-and-or-terraform/">From zero to WordPress in less than 2 minutes on Linode using cloud-init and/or Terraform</a> first appeared on <a href="https://blog.slepcevic.net">Architect the cloud</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Yeah, it&#8217;s true. You can get a fully running VM with installed MySQL, Apache, PHP and WordPress configured in less than 2 minutes! <strong>1:58 to be exact <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></strong></p>



<p><strong>Ok, what is cloud-init in the first place?</strong></p>



<p>Cloud-init is a widely used open-source package for initializing and configuring cloud instances (virtual machines or instances) in cloud computing environments. It is commonly used in infrastructure as a service (IaaS) and cloud platforms such as Akamai Connected Cloud, Amazon Web Services (AWS), Google Cloud Platform (GCP), Microsoft Azure, and various other cloud providers.</p>



<p>Cloud-init allows you to define and execute custom scripts and configuration at instance launch time or when an instance boots. It is typically provided with the cloud <a href="https://blog.slepcevic.net/linode-metadata-service/">instance&#8217;s metadata</a> during its provisioning. This metadata can include user data, which consists of cloud-init configuration in the form of a script or YAML file.</p>



<p>Key features and use cases of cloud-init include:</p>



<p><strong>Operating System Configuration</strong>: You can use cloud-init to perform various tasks like setting the hostname, configuring network interfaces, setting up users, and more.</p>



<p><strong>Package Installation</strong>: Cloud-init can be used to install software packages, libraries, or applications on the newly provisioned instance.</p>



<p><strong>User Data</strong>: You can pass user-specific data to the instance, which can be used to customize the instance&#8217;s behavior at boot time. For example, you can use it to configure software, install additional packages, or run scripts.</p>



<p><strong>Security</strong>: You can use cloud-init to set up SSH keys for secure access, set firewall rules, or perform other security-related tasks.</p>



<p><strong>Customization</strong>: Cloud-init allows you to define instance-specific customizations, making it easier to automate the setup and configuration of instances.</p>



<p><strong>Cloud Provider Agnostic</strong>: While commonly used in various cloud providers, cloud-init is not tied to a specific cloud platform. It&#8217;s available and can be used in many different environments.</p>



<p><strong>Flexibility</strong>: You can provide cloud-init configuration as a script or a YAML file, giving you flexibility in how you define the initialization and configuration process.</p>



<p></p>



<p>Ok, but how do I use it? It&#8217;s quite simple actually. </p>



<p>In this example, we install 5 packages and run a few commands to download WordPress, create a DB user, prepare wp-config file and so on. </p>



<p><strong>Please make sure to use a better password and/or a better way to deliver the credentials to the VM. Password in <em>plain </em>text is just for demo purposes and it&#8217;s just <em>plain</em> wrong (ha ha, get it! :D)!</strong></p>



<p>Log into your Linode Cloud manager interface and click on &#8220;<strong>Create Linode</strong>&#8221; button. </p>



<p><strong><em>Make sure to select a distribution which support cloud-init!</em></strong> <strong>Those are indicated by a &#8220;file&#8221; icon next to the distro name. </strong></p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="727" height="428" src="https://blog.slepcevic.net/wp-content/uploads/2023/10/cloudinit.png" alt="" class="wp-image-186" srcset="https://blog.slepcevic.net/wp-content/uploads/2023/10/cloudinit.png 727w, https://blog.slepcevic.net/wp-content/uploads/2023/10/cloudinit-300x177.png 300w" sizes="(max-width: 727px) 100vw, 727px" /></figure>



<p>Next step (beside selecting the region, instance type, key and password), is to expand the &#8220;User Data&#8221; section and paste in the following code and press &#8220;Deploy&#8221;. </p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="262" src="https://blog.slepcevic.net/wp-content/uploads/2023/10/userdata-2-1024x262.png" alt="" class="wp-image-189" srcset="https://blog.slepcevic.net/wp-content/uploads/2023/10/userdata-2-1024x262.png 1024w, https://blog.slepcevic.net/wp-content/uploads/2023/10/userdata-2-300x77.png 300w, https://blog.slepcevic.net/wp-content/uploads/2023/10/userdata-2-768x196.png 768w, https://blog.slepcevic.net/wp-content/uploads/2023/10/userdata-2-1280x328.png 1280w, https://blog.slepcevic.net/wp-content/uploads/2023/10/userdata-2.png 1283w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<pre class="wp-block-code"><code>#cloud-config
packages:
  - apache2
  - mysql-server
  - php8.1
  - libapache2-mod-php8.1
  - php8.1-mysql
runcmd:
  - mkdir -p /var/www/html  # Create the /var/www/html directory if it doesn't exist
  - rm -f /var/www/html/index.html  # Remove the default index.html file
  - &#091;wget, https://wordpress.org/latest.tar.gz, -O, /tmp/wordpress.tar.gz]
  - &#091;tar, -xvzf, /tmp/wordpress.tar.gz, -C, /var/www/html]
  - mv /var/www/html/wordpress/* /var/www/html/  # Move WordPress files to the root of the web directory
  - &#091;chown, -R, www-data:www-data, /var/www/html]
  - |
    mysql -u root -e "CREATE DATABASE wordpress;"
    mysql -u root -e "CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'ComplexPassword123#';"
    mysql -u root -e "GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';"
    mysql -u root -e "FLUSH PRIVILEGES;"
  - cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
  - sed -i 's/database_name_here/wordpress/g' /var/www/html/wp-config.php
  - sed -i 's/username_here/wordpressuser/g' /var/www/html/wp-config.php
  - sed -i 's/password_here/ComplexPassword123#/g' /var/www/html/wp-config.php
  - a2enmod php8.1  # Enable PHP module
  - systemctl restart apache2  # Restart Apache to apply the changes
</code></pre>



<p>Open your browser and navigate to the IP address of the server and less than 2 minutes after you should be greeted with a WordPress &#8220;Finish setup&#8221; page where you need to specify your email, username and password. </p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="825" src="https://blog.slepcevic.net/wp-content/uploads/2023/10/wordpress-1024x825.png" alt="" class="wp-image-190" srcset="https://blog.slepcevic.net/wp-content/uploads/2023/10/wordpress-1024x825.png 1024w, https://blog.slepcevic.net/wp-content/uploads/2023/10/wordpress-300x242.png 300w, https://blog.slepcevic.net/wp-content/uploads/2023/10/wordpress-768x619.png 768w, https://blog.slepcevic.net/wp-content/uploads/2023/10/wordpress.png 1030w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p>You can accomplish the same thing via Terraform by using the &#8220;<strong>metadata</strong>&#8221; block and <strong>encoding your cloud-init script in base64</strong>.</p>



<pre class="wp-block-code"><code>
resource "linode_instance" "wordpressviacloudinit" {
  label = "Wordpress-via-cloudinit"
  image = "linode/ubuntu22.04"
  region = "us-iad"
  type = "g6-standard-1"
  authorized_keys = &#091;"ssh-rsa AAAA...Gw== user@example.local"]
  root_pass = "terr4form-test"
  <strong>metadata </strong>{<strong>
    user_data </strong>= "I2Nsb3VkLWNvbmZpZwpwYWNrYWdlczoKICAtIGFwYWNoZTIKICAtIG15c3FsLXNlcnZlcgogIC0gcGhwOC4xCiAgLSBsaWJhcGFjaGUyLW1vZC1waHA4LjEKICAtIHBocDguMS1teXNxbApydW5jbWQ6CiAgLSBta2RpciAtcCAvdmFyL3d3dy9odG1sICAjIENyZWF0ZSB0aGUgL3Zhci93d3cvaHRtbCBkaXJlY3RvcnkgaWYgaXQgZG9lc24ndCBleGlzdAogIC0gcm0gLWYgL3Zhci93d3cvaHRtbC9pbmRleC5odG1sICAjIFJlbW92ZSB0aGUgZGVmYXVsdCBpbmRleC5odG1sIGZpbGUKICAtIFt3Z2V0LCBodHRwczovL3dvcmRwcmVzcy5vcmcvbGF0ZXN0LnRhci5neiwgLU8sIC90bXAvd29yZHByZXNzLnRhci5nel0KICAtIFt0YXIsIC14dnpmLCAvdG1wL3dvcmRwcmVzcy50YXIuZ3osIC1DLCAvdmFyL3d3dy9odG1sXQogIC0gbXYgL3Zhci93d3cvaHRtbC93b3JkcHJlc3MvKiAvdmFyL3d3dy9odG1sLyAgIyBNb3ZlIFdvcmRQcmVzcyBmaWxlcyB0byB0aGUgcm9vdCBvZiB0aGUgd2ViIGRpcmVjdG9yeQogIC0gW2Nob3duLCAtUiwgd3d3LWRhdGE6d3d3LWRhdGEsIC92YXIvd3d3L2h0bWxdCiAgLSB8CiAgICBteXNxbCAtdSByb290IC1lICJDUkVBVEUgREFUQUJBU0Ugd29yZHByZXNzOyIKICAgIG15c3FsIC11IHJvb3QgLWUgIkNSRUFURSBVU0VSICd3b3JkcHJlc3N1c2VyJ0AnbG9jYWxob3N0JyBJREVOVElGSUVEIEJZICdDb21wbGV4UGFzc3dvcmQxMjMjJzsiCiAgICBteXNxbCAtdSByb290IC1lICJHUkFOVCBBTEwgUFJJVklMRUdFUyBPTiB3b3JkcHJlc3MuKiBUTyAnd29yZHByZXNzdXNlcidAJ2xvY2FsaG9zdCc7IgogICAgbXlzcWwgLXUgcm9vdCAtZSAiRkxVU0ggUFJJVklMRUdFUzsiCiAgLSBjcCAvdmFyL3d3dy9odG1sL3dwLWNvbmZpZy1zYW1wbGUucGhwIC92YXIvd3d3L2h0bWwvd3AtY29uZmlnLnBocAogIC0gc2VkIC1pICdzL2RhdGFiYXNlX25hbWVfaGVyZS93b3JkcHJlc3MvZycgL3Zhci93d3cvaHRtbC93cC1jb25maWcucGhwCiAgLSBzZWQgLWkgJ3MvdXNlcm5hbWVfaGVyZS93b3JkcHJlc3N1c2VyL2cnIC92YXIvd3d3L2h0bWwvd3AtY29uZmlnLnBocAogIC0gc2VkIC1pICdzL3Bhc3N3b3JkX2hlcmUvQ29tcGxleFBhc3N3b3JkMTIzIy9nJyAvdmFyL3d3dy9odG1sL3dwLWNvbmZpZy5waHAKICAtIGEyZW5tb2QgcGhwOC4xICAjIEVuYWJsZSBQSFAgbW9kdWxlCiAgLSBzeXN0ZW1jdGwgcmVzdGFydCBhcGFjaGUyICAjIFJlc3RhcnQgQXBhY2hlIHRvIGFwcGx5IHRoZSBjaGFuZ2VzCg=="
  }
  group = "foo"
  tags = &#091; "foo" ]
  swap_size = 512
  private_ip = false
}</code></pre>



<p>Of course, you can use cloud-init for pretty much anything you want but the ideal usecase would be bootstrapping your instance so your configuration management tool can take over after Terraform creates it. </p>



<p>Until next time!</p>



<p>Cheers, Alex. </p><p>The post <a href="https://blog.slepcevic.net/from-zero-to-wordpress-in-less-than-2-minutes-using-linode-and-cloud-init-and-or-terraform/">From zero to WordPress in less than 2 minutes on Linode using cloud-init and/or Terraform</a> first appeared on <a href="https://blog.slepcevic.net">Architect the cloud</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.slepcevic.net/from-zero-to-wordpress-in-less-than-2-minutes-using-linode-and-cloud-init-and-or-terraform/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)

Served from: blog.slepcevic.net @ 2025-12-27 00:09:16 by W3 Total Cache
-->