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.
- Test the website.
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.
- Enter
web-network
for the network Name. - 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 a Name for the group:
sg-web
. -
Select
web-network
for Network. -
Under Rules, create the following rules using the instructions below the table:
Traffic
directionDescription Port range Protocol Source /
targetCIDR 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 folder page in the management console
, click Create resource and selectVirtual machine instance
. -
Under Boot disk image, enter
LAMP
orLEMP
in the Product search field and select the VM image with the components you need: -
Under Location, select an availability zone to create your VM in. If you do not know which availability zone you need, leave the default one.
-
Under Computing resources, navigate to the
Custom
tab and specify the required platform, number of vCPUs, and amount of RAM. This minimum configuration is enough for functional website testing:- Platform:
Intel Ice Lake
. - vCPU:
2
. - Guaranteed vCPU performance:
20%
- RAM:
1 GB
- Platform:
-
Under Network settings:
- In the Subnet field, select
web-network
and the subnet to create your VM in. - Under Public IP, 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.
- In the Subnet field, select
-
Under Access, select SSH key and specify the VM access data:
-
Under Login, enter the username. Do not use
root
or other names reserved by the OS. To perform operations requiring superuser permissions, use thesudo
command. -
In the SSH key field, select the SSH key saved in your organization user profile.
If there are no saved SSH keys in your profile, or you want to add a new key:
- Click Add key.
- Enter a name for the SSH key.
- Upload or paste the contents of the public key file. You need to create a key pair for the SSH connection to a VM yourself.
- Click Add.
The SSH key will be added to your organization user profile.
If users cannot add SSH keys to their profiles in the organization, the added public SSH key will only be saved to the user profile of the VM being created.
-
-
Under General information, specify the VM name:
lamp-vm
orlemp-vm
. 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.
-
Click Create VM.
Alert
Once created, the VM gets an IP address and a host name (FQDN) for connections. If you selected
No address
in the Public IP field, you will not be able to access the VM from the internet.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.
Below we describe 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
as its 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 the zone Name:
example-zone-1
. - 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
. - 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 (ns1.yandexcloud.net
and ns2.yandexcloud.net
) are created.
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 the domain delegation using Whoisdig
utility:
dig +short NS example.com
Result:
ns2.yandexcloud.net.
ns1.yandexcloud.net.
Test the website
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: