diff --git a/docs/deploy/digital-ocean.md b/docs/deploy/digital-ocean.md index 81ab8c1d..b3489cb4 100644 --- a/docs/deploy/digital-ocean.md +++ b/docs/deploy/digital-ocean.md @@ -1,6 +1,6 @@ # Deploying to DigitalOcean -This guide will walk you through deploying a simple Hello, world Vapor application to a [Droplet](https://www.digitalocean.com/products/droplets/). To follow this guide, you will need to have a [DigitalOcean](https://www.digitalocean.com) account with billing configured. +This guide will walk you through deploying a simple Hello, world Vapor application to a [Droplet](https://www.digitalocean.com/products/droplets/). To follow this guide, you must have a [DigitalOcean](https://www.digitalocean.com) account with billing configured. ## Create Server @@ -8,12 +8,12 @@ Let's start by installing Swift on a Linux server. Use the create menu to create ![Create Droplet](../images/digital-ocean-create-droplet.png) -Under distributions, select Ubuntu 18.04 LTS. The following guide will use this version as an example. +Under distributions, select Ubuntu 22.04 LTS. The following guide will use this version as an example. -![Ubuntu Distro](../images/digital-ocean-distributions-ubuntu-18.png) +![Ubuntu Distro](../images/digital-ocean-distributions-ubuntu.png) !!! note - You may select any Linux distribution with a version that Swift supports. At the time of writing, Swift 5.2.4 supports Ubuntu 16.04, 18.04, 20.04, CentOS 8, and Amazon Linux 2. You can check which operating systems are officially supported on the [Swift Releases](https://swift.org/download/#releases) page. + You may select any Linux distribution with a version that Swift supports. At the time of writing, Swift 5.7.3 supports Ubuntu 18.04, 20.04, 22.04, CentOS 7, and Amazon Linux 2. You can check which operating systems are officially supported on the [Swift Releases](https://swift.org/download/#releases) page. After selecting the distribution, choose any plan and datacenter region you prefer. Then setup an SSH key to access the server after it is created. Finally, click create Droplet and wait for the new server to spin up. @@ -29,7 +29,7 @@ Open your terminal and connect to the server as root using SSH. ssh root@your_server_ip ``` -DigitalOcean has an in-depth guide for [initial server setup on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04). This guide will quickly cover the basics. +DigitalOcean has an in-depth guide for [initial server setup on Ubuntu 22.04](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-22-04). This guide will quickly cover the basics. ### Configure Firewall @@ -77,38 +77,40 @@ Install Swift's required dependencies. ```sh sudo apt-get update -sudo apt-get install clang libicu-dev libatomic1 build-essential pkg-config +sudo apt-get install binutils git gnupg2 libc6-dev libcurl4-openssl-dev + \ libedit2 libgcc-9-dev libpython3.8 libsqlite3-0 libstdc++-9-dev + \ libxml2-dev libz3-dev pkg-config tzdata unzip zlib1g-dev ``` -### Download Toolchain +### Download Swift Toolchain -This guide will install Swift 5.2.4. Visit the [Swift Releases](https://swift.org/download/#releases) page for a link to latest release. Copy the download link for Ubuntu 18.04. +This guide will install Swift 5.7.3. Visit the [Swift Releases](https://swift.org/download/#releases) page for a link to latest release. Copy the download link for Ubuntu 22.04. -![Download Swift](../images/swift-download-ubuntu-18-copy-link.png) +![Download Swift](../images/swift-download-ubuntu-copy-link.png) Download and decompress the Swift toolchain. ```sh -wget https://swift.org/builds/swift-5.2.4-release/ubuntu1804/swift-5.2.4-RELEASE/swift-5.2.4-RELEASE-ubuntu18.04.tar.gz -tar xzf swift-5.2.4-RELEASE-ubuntu18.04.tar.gz +wget https://download.swift.org/swift-5.7.3-release/ubuntu2204/swift-5.7.3-RELEASE/swift-5.7.3-RELEASE-ubuntu22.04.tar.gz +tar xzf swift-5.7.3-RELEASE-ubuntu22.04.tar.gz ``` !!! note Swift's [Using Downloads](https://swift.org/download/#using-downloads) guide includes information on how to verify downloads using PGP signatures. -### Install Toolchain +### Install Swift Toolchain Move Swift somewhere easy to acess. This guide will use `/swift` with each compiler version in a subfolder. ```sh sudo mkdir /swift -sudo mv swift-5.2.4-RELEASE-ubuntu18.04 /swift/5.2.4 +sudo mv swift-5.7.3-RELEASE-ubuntu22.04 /swift/5.7.3 ``` Add Swift to `/usr/bin` so it can be executed by `vapor` and `root`. ```sh -sudo ln -s /swift/5.2.4/usr/bin/swift /usr/bin/swift +sudo ln -s /swift/5.7.3/usr/bin/swift /usr/bin/swift ``` Verify that Swift was installed correctly. @@ -117,59 +119,79 @@ Verify that Swift was installed correctly. swift --version ``` -## Setup Project +## Install Vapor Using the Vapor Toolbox -Now that Swift is installed, let's clone and compile your project. For this example, we'll be using Vapor's [API template](https://github.com/vapor/api-template/). +Now that Swift is installed, let's install Vapor using the Vapor Toolbox. You will need to build the toolbox from source. View the toolbox's [releases](https://github.com/vapor/toolbox/releases) on GitHub to find the latest version. In this example, we are using 18.6.0. -First let's install Vapor's system dependencies. +### Clone and Build Vapor + +Clone the Vapor Toolbox repository. ```sh -sudo apt-get install openssl libssl-dev zlib1g-dev libsqlite3-dev +git clone https://github.com/vapor/toolbox.git ``` -Allow HTTP through the firewall. +Checkout the latest release. ```sh -sudo ufw allow http +cd toolbox +git checkout 18.6.0 ``` -### Clone & Build - -Now clone the project and build it. +Build Vapor and move the binary into your path. ```sh -git clone https://github.com/vapor/api-template.git -cd api-template -swift build +swift build -c release --disable-sandbox --enable-test-discovery +sudo mv .build/release/vapor /usr/local/bin +``` + +### Create a Vapor Project + +Use the Toolbox's new project command to initiate a project. + +```sh +vapor new HelloWorld -n ``` !!! tip - If you are building this project for production, use `swift build -c release` + The `-n` flag gives you a bare bones template by automatically answering no to all questions. + + +![Vapor Splash](../images/vapor-splash.png) + +Once the command finishes, change into the newly created folder: + +```sh +cd HelloWorld +``` + +### Open HTTP Port + +In order to access Vapor on your server, open an HTTP port. + +```sh +sudo ufw allow 8080 +``` ### Run -Once the project has finished compiling, run it on your server's IP at port 80. The IP address is `157.245.244.228` in this example. +Now that Vapor is setup and we have an open port, let's run it. ```sh -sudo .build/debug/Run serve -b 157.245.244.228:80 +vapor run serve --hostname 0.0.0.0 --port 8080 ``` -If you used `swift build -c release`, then you need to run: -```sh -sudo .build/release/Run serve -b 157.245.244.228:80 -``` - -Visit your server's IP via browser or local terminal and you should see "It works!". +Visit your server's IP via browser or local terminal and you should see "It works!". The IP address is `134.122.126.139` in this example. ``` -$ curl http://157.245.244.228 +$ curl http://134.122.126.139:8080 It works! ``` Back on your server, you should see logs for the test request. ``` -[ NOTICE ] Server starting on http://157.245.244.228:80 +[ NOTICE ] Server starting on http://0.0.0.0:8080 [ INFO ] GET / ``` diff --git a/docs/images/digital-ocean-create-droplet.png b/docs/images/digital-ocean-create-droplet.png index 73412ce3..98928c87 100644 Binary files a/docs/images/digital-ocean-create-droplet.png and b/docs/images/digital-ocean-create-droplet.png differ diff --git a/docs/images/digital-ocean-distributions-ubuntu-18.png b/docs/images/digital-ocean-distributions-ubuntu-18.png deleted file mode 100644 index b0d347fb..00000000 Binary files a/docs/images/digital-ocean-distributions-ubuntu-18.png and /dev/null differ diff --git a/docs/images/digital-ocean-distributions-ubuntu.png b/docs/images/digital-ocean-distributions-ubuntu.png new file mode 100644 index 00000000..cbf1aa91 Binary files /dev/null and b/docs/images/digital-ocean-distributions-ubuntu.png differ diff --git a/docs/images/digital-ocean-droplet-list.png b/docs/images/digital-ocean-droplet-list.png index ad5d3cd7..bcd17804 100644 Binary files a/docs/images/digital-ocean-droplet-list.png and b/docs/images/digital-ocean-droplet-list.png differ diff --git a/docs/images/swift-download-ubuntu-18-copy-link.png b/docs/images/swift-download-ubuntu-18-copy-link.png deleted file mode 100644 index 75dc4e8e..00000000 Binary files a/docs/images/swift-download-ubuntu-18-copy-link.png and /dev/null differ diff --git a/docs/images/swift-download-ubuntu-copy-link.png b/docs/images/swift-download-ubuntu-copy-link.png new file mode 100644 index 00000000..8c2d32f9 Binary files /dev/null and b/docs/images/swift-download-ubuntu-copy-link.png differ diff --git a/docs/images/vapor-splash.png b/docs/images/vapor-splash.png new file mode 100644 index 00000000..f6502083 Binary files /dev/null and b/docs/images/vapor-splash.png differ