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:
- Get your cloud ready.
- Create a cloud network and subnets.
- Create a security group.
- Create a VM with a pre-installed web server.
- Upload the website files.
- Configure 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.
Get your cloud ready
Sign up for Yandex Cloud and create a billing account:
- Navigate to the management console
and log in to Yandex Cloud or create a new account. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVEorTRIAL_ACTIVEstatus. If you do not have a billing account, create one and link a cloud to it.
If you have an active billing account, you can navigate to the cloud page
Learn more about clouds and folders here.
Required paid resources
The infrastructure support costs for a website include:
- 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 resources created in this tutorial 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-networkfor 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 the group Name:
sg-web. -
Select
web-networkfor Network. -
Under Rules, create the following rules using the instructions below the table:
Traffic
directionDescription Port range Protocol Source /
destinationCIDR blocks OutgoinganyAllAnyCIDR0.0.0.0/0Inboundext-http80TCPCIDR0.0.0.0/0Inboundext-https443TCPCIDR0.0.0.0/0- Select the Egress or Ingress tab.
- Click Add rule.
- In the Port range field of the window that opens, specify a port or range of ports open for inbound or outbound traffic.
- In the Protocol field, specify the protocol or leave Any to allow traffic over any protocol.
- In the Source or Destination field, select the scope of the rule:
- CIDR: Rule will apply to a 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 more CIDRs, click Add CIDR.
- Security group: Rule will apply to the current or the selected security group VMs.
- Click Save. Repeat these steps to create all rules from the table.
-
Click Save.
-
Create a VM with a pre-installed web server
-
On the folder dashboard of the management console
, click Create resource and selectVirtual machine instance. -
Under Boot disk image, enter
LAMPorLEMPin the Product search field and select the VM image with the components you need: -
Under Location, select the availability zone to create your VM in. If you are not sure which one to choose, leave the default.
-
Under Computing resources, navigate to the
Customtab 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-networkand the subnet to create your VM in. - Under Public IP address, leave
Autoto assign a random external IP address from the Yandex Cloud pool to your VM. Alternatively, select a static address from the list if you reserved one.
- In the Subnet field, select
-
Under Access, select SSH key and specify the VM access credentials:
-
Under Login, enter the username. Do not use
rootor other names reserved for the OS purposes. For operations requiring root privileges, use thesudocommand. -
In the SSH key field, select the SSH key saved in your organization user profile.
If there are no 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 system will add the SSH key to your organization user profile. If the organization has disabled the ability for users to add SSH keys to their profiles, the added public SSH key will only be saved in the user profile inside the newly created resource.
-
-
Under General information, specify the VM name:
lamp-vmorlemp-vm. The naming requirements are as follows:- It must be from 2 to 63 characters long.
- It can only contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with 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 addressin the Public IP 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 your VM. When the VM status changes to
RUNNING, you can upload the website files to it.
Upload the website files
To test the web server, upload the index.html file to the VM. You can use a test file
-
Find the VM public IP address under Network on the VM page in the management console
. -
Connect to the VM via SSH.
-
Grant your user write permissions for the
/var/www/htmldirectory:sudo chown -R "$USER":www-data /var/www/html -
Upload the website files to the VM via SCP
.Linux/macOSWindowsUse the
scpcommand line utility:scp -r <path_to_directory_with_files> <VM_user_name>@<VM_IP_address>:/var/www/htmlUse WinSCP
to copy the local file directory to/var/www/htmlon the VM.
Configure 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 website of your DNS hosting provider, navigate to the DNS settings.
-
Create or edit the A record for
example.comso that it points to the copied IP address:example.com. A <VM_IP_address> -
Create a CNAME record named
wwwwithexample.comas its value.If you use Yandex Cloud DNS, follow this tutorial 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 domain name with a trailing dot:
example.com.. - Select the zone Type:
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.comdomain 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.comDNS zone from the list. - Click Create record.
- Specify the record settings:
- 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. Internet provider servers normally update records within 24 hours (86,400 seconds). 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.
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: