قالب وردپرس درنا توس
Home / How To / How to install the Visual Studio code

How to install the Visual Studio code



Code Server is a Visual Studio (VS) code that can be run remotely on the server and is accessible through a web browser. It lets you create and have a consistent development environment that can be accessed anytime, anywhere.

In this tutorial, we will show you how to install the code server with Nginx as a reverse proxy and SSL Letsencrypt on the latest Ubuntu 18.04 Server.

Prerequisites

For this guide, we will install the code server on the Ubuntu 18.04 server with 3 GB RAM, 25 GB free disk space and 2CPU.

What we will do:

  • Add user and download code server Binary
  • Setup code server as Systemd Service
  • Generate SSL Letsencrypt
  • Setup Nginx as a reverse code server proxy [1
    9659007] Test

Step 1 – Add user and download code server binary

First we add a new user and download the code server binary file from GitHub.

Add a new user code with the command below.

  useradd -m -s / bin / bash code 
passwd code

Log in now as & # 39; code & # 39; users and d download the code server binary file.

  su - code 
wget https://github.com/cdr/code-server/releases/download/2.1692-vsc1.39.2/code-server2.1692-vsc1. 39.2-linux-x86_64.tar.gz

 Download VS Code Server

Extract the code server and rename the directory as & # 39; bin & # 39;

  tar -xf code-server2.1692 -vsc1.39.2-linux-x86_64.tar.gz 
mv code-server2.1692-vsc1.39.2-linux-x86_64 / bin /

Now make the code server as an executable binary file.

  chmod + x ~ / bin / code-server 

And create a new data directory for storing user data.

  mkdir -p ~ / data 

Now you have created a new user code and downloaded the code server binary to the home directory of the user's & # 39; code & # 39 ;.

 Download and install code server

Step 2 – Configure code server as a system service

In this step we will set up the code server to function as a system service.

The code server service runs under user code e & # 39 ;, with default port & # 39; 8080 & # 39; and enabled password authentication.

Go to directory & # 39; / etc / systemd / system & # 39; and create a new service file & # 39; code-server.service & # 39; with the vim editor.

  cd / etc / systemd / system / 
vim code-server.service

Change the "Environment" option for a password with your own and paste the configuration into it.

[Unit]
Description = code server
After = nginx.service [Service]
User = code
WorkingDirectory = / home / code
Environment = PASSWORD = hakasevscodeserv
ExecStart = / home / code / bin / code-server - host 127.0.0.1 - user-data-dir / home / code / data - auth password
Restart = always

[Install]
WantedBy = multi-user.target

Save and close .

Reload the system manager now.

  systemctl daemon-reload 

Then start the code server service and add it to the system startup with the following command.

  systemctl start code server 
systemctl enable code server

[1 9459031] Configure code server system service "width =" 750 "height =" 144 "style =" display: block; margin-left: auto; margin-right: auto; "/>

Now check the code-server service.

  netstat -plntu 
systemctl status code-server

And the code-server service is running standard port & # 39; 8080 & # 39; .

 Run code server

As a result, you have configured the code server to function as a system service.

Step 3 – Generate SSL Letsencrypt

In this step we will generate SSL -let encryption with the certbot utility to secure the code server.

Install the certbot utility with the apt command below. certonly – standalone –agree-tos -m [email protected] -d vscode.hakase-labs.io

When done, your certificates will be found in the & # 39; / etc / letsencrypt / live / vscode directory. hakase-labs.io/'.

  ls -lah /etc/letsencrypt/live/vscode.hakase-labs. io / [19659015] Now you have generated SSL Letsencrypt to secure the code server installation with the certbot tool. 

Step 4 - Setting Nginx as a Reverse Proxy

In this step, we install the Nginx web server and configure it as a reverse proxy for the code server with SSL enabled on top.

Install the Nginx package with the apt command below.

  sudo apt install nginx-y 

Once the installation is complete, go to the & # 39; / etc / nginx / sites-available & # 39; directory and create a new virtual host configuration & # 39; code server & # 39 ;.

  cd / etc / nginx / sites-available / 
vim code-server [19659015] Now change the SSL domain name and path with your own and paste the configuration into it.

  server {
listen 80;
server name vscode.hakase-labs.io;
# maintain https
return 301 https: // $ server name: 443 $ request_uri;
}

server {
listen 443 ssl http2;
server name vscode.hakase-labs.io; [19659063] ssl_certificate /etc/letsencrypt/live/vscode.hakase-labs.io/fullchain.pem; Chapter19459014 Dollssl_certificate_key /etc/letsencrypt/live/vscode.hakase-labs.io/privkey.pem; {
proxy_pass http://127.0.0.1:8080/;vud19459014??proxy_set_header Host $ host;
proxy_set_header Upgrade $ http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-19459; ]}
}

Save and close.

Now enable the virtual host for the "code server", test the nginx configuration and make sure there is no error.

  ln -s / etc / nginx / sites-available / code-server / etc / nginx / sites-enabled / 
nginx -t

 Edit Nginx Configuration

Then starts you nginx service again and add it to the system boot.

  systemctl restart nginx 
systemctl enable nginx

Now the Nginx service is running as a reverse proxy for the code server. Check it with the command below.

  netstat -plntu 
systemctl status nginx

And you will get the result as below.

 Start Nginx

The Nginx service is up and running on the Ubuntu 18.04 server with the HTTP and HTTPS ports enabled on top of it.

Step 5 - Test

Open your web browser and type the URL of your code server installation.

https://vscode.hakase-labs.io/

Log in with your password that you have configured in the code server's service file.

 Logging in to VS Code

When the password is correct, you will get the VS code editor in your browser as below.

 Visual Studio Code

As a result, you have installed the code server on the Ubuntu 18.04 server with Nginx as a reverse proxy and secure the code server installation with SSL Letsencrypt.

Reference


Source link