Website on a LAMP or LEMP stack using the management console
To create an infrastructure for a website on a LAMP or LEMP stack using the Yandex Cloud management console:
- Prepare your cloud.
- Create a cloud network and subnets.
- Create a security group.
- Create a VM with a pre-installed web server.
- Upload the website files.
- Configure the DNS.
- Check that the website is running.
We will use the example.com
domain name as an example.
If you no longer need the resources you created, delete them.
Prepare your cloud
Sign up for Yandex Cloud and create a billing account:
- Go to the management console
and log in to Yandex Cloud or create an account if you do not have one yet. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVE
orTRIAL_ACTIVE
status. If you do not have a billing account, create one.
If you have an active billing account, you can go to the cloud page
Learn more about clouds and folders.
Required paid resources
The cost of supporting the website infrastructure includes:
- Fee for a continuously running VM (see Yandex Compute Cloud pricing).
- Fee for using a public IP address (see Yandex Virtual Private Cloud pricing).
- Fee for public DNS queries and DNS zones if using Yandex Cloud DNS (see Cloud DNS pricing).
Create a cloud network and subnets
All the resources created in the use case will belong to the same cloud network.
To create a network and subnets:
- In the management console
, select Virtual Private Cloud. - Click Create network.
- Specify the Name of the network:
web-network
. - In the Advanced field, select Create subnets.
- Click Create network.
Create a security group
Security groups contain rules that allow accessing your VMs from the internet. You need to create a security group named sg-web
.
To create a security group:
- In the management console
, select Virtual Private Cloud. - Open the Security groups tab.
- Create a security group for your VM:
-
Click Create group.
-
Enter the Name of the group:
sg-web
. -
Select the Network:
web-network
. -
Under Rules, create the following rules using the instructions below the table:
Traffic
directionDescription Port range Protocol Source /
destinationCIDR blocks Outgoing
any
All
Any
CIDR
0.0.0.0/0
Incoming
ext-http
80
TCP
CIDR
0.0.0.0/0
Incoming
ext-https
443
TCP
CIDR
0.0.0.0/0
- Select the Outgoing traffic or Incoming traffic tab.
- Click Add rule.
- In the Port range field of the window that opens, specify a single port or a range of ports that traffic will come to or from.
- In the Protocol field, specify the appropriate protocol or leave Any to allow traffic transmission over any protocol.
- In the Purpose or Source field, select the purpose of the rule:
- CIDR: Rule will apply to the range of IP addresses. In the CIDR blocks field, specify the CIDR and masks of subnets that traffic will come to or from. To add multiple CIDRs, click Add CIDR.
- Security group: Rule will apply to the VMs from the current group or the selected security group.
- Click Save. Repeat the steps to create all the rules from the table.
-
Click Save.
-
Create a VM with a pre-installed web server
-
On the management console
folder page, click Create resource and select Virtual machine. -
In the Name field, enter
lamp-vm
orlemp-vm
as the VM name. The naming requirements are as follows:- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
-
Select an availability zone to place the VM in. If you do not know which availability zone you need, leave the default one.
-
Under Image/boot disk selection, go to the Cloud Marketplace tab and select the VM image with the components you need:
-
Under Computing resources:
- Choose a VM platform.
- Specify the required number of vCPUs and the amount of RAM.
This minimum configuration is enough for functional website testing:
- Platform: Intel Ice Lake
- Guaranteed vCPU share: 20%
- vCPU: 2
- RAM: 1 GB
-
In the Network settings section, select the
web-network
network and the subnet to connect the VM to. -
Under Public address, keep Auto to assign your VM a random external IP address from the Yandex Cloud pool, or select a static address from the list if you reserved one in advance.
-
Specify the VM access data:
-
Enter the username in the Login field.
-
In the SSH key field, paste the contents of the public key file.
You will need to create a key pair for the SSH connection yourself; see Connecting to a Linux VM via SSH for details.
Alert
Once created, the VM gets an IP address and a host name (FQDN) for connections. If you selected No address in the Public address field, you will not be able to access the VM from the internet.
-
-
Click Create VM.
It may take a few minutes to create the VM. When the VM status changes to
RUNNING
, you can upload the website files.
Upload the website files
To test the web server, upload the index.html
file to the VM. You can use a test file
-
Under Network on the VM page in the management console
, find the VM's public IP address. -
Connect to the VM via SSH.
-
Grant your user write access to the
/var/www/html
directory:sudo chown -R "$USER":www-data /var/www/html
-
Upload the website files to the VM via SCP
.Linux/macOSWindowsUse the
scp
command-line utility:scp -r <path_to_file_directory> <VM_username>@<VM_IP_address>:/var/www/html
Use WinSCP
to copy the local file directory to/var/www/html
on the VM.
Configure the DNS
If you have a registered domain name, use the Cloud DNS service to manage the domain.
Read below to learn how to configure the DNS for the example.com
domain name. The example.com
domain name must be mapped to the VM IP address using DNS records. To do this:
-
In the management console
, select Compute Cloud. -
Copy the IP address of the VM you created.
-
On the site of your DNS hosting provider, go to the DNS settings.
-
Create or edit the A record for
example.com
so that it points to the copied IP address:example.com. A <VM_IP_address>
-
Create a CNAME record named
www
withexample.com
for value.If you use Yandex Cloud DNS, follow this guide to configure the record:
Configuring DNS records for Cloud DNS
- In the management console
, select Cloud DNS. - If you do not have a public DNS zone, create one:
- Click Create zone.
- Specify
example-zone-1
for zone Name. - In the Zone field, enter the website's domain name with a trailing dot:
example.com.
- Select a Type of the zone:
Public
. - Click Create.
- Create an A record:
- In the list of zones, click
example-zone-1
. - Click Create record.
- Leave the Name field empty for the record to match the
example.com
domain name (rather than a name with a subdomain, e.g.,www.example.com
). - Select the record Type:
A
. - In the Data field, paste the copied IP address of the VM.
- Click Create.
- In the list of zones, click
- Create a CNAME record:
- Select the
example.com
DNS zone from the list. - Click Create record.
- Set the record parameters:
- Name:
www
. - Record type: Select
CNAME
as the value. - TTL (record time to live): Keep the default value.
- Value: Enter
example.com
.
- Name:
- Click Create.
- Select the
- In the management console
Delegate the domain name
Delegation is the transfer of authority from the registrar's servers to yours. For a domain, NS resource records are created (ns1.yandexcloud.net
and ns2.yandexcloud.net
).
To delegate a domain, specify its DNS servers in the registrar's account.
Delegation does not take effect immediately. It usually takes up to 24 hours (86,400 seconds) for internet service providers to update records. This depends on the TTL value which specifies how long domain records are cached.
You can check domain delegation using Whoisdig
utility:
dig +short NS example.com
Result:
ns2.yandexcloud.net.
ns1.yandexcloud.net.
Check that the website is running
To test the site, enter its IP or domain name in your browser:
http://<public_IP_of_VM>
http://www.example.com
How to delete the resources you created
To stop paying for the resources you created: