Website on LAMP or LEMP stack

To configure a static website or dynamic website in PHP:

  1. Create a VM with a pre-installed web server
  2. Upload the website files
  3. Configure DNS

Before you start

Before creating a VM:

  1. Go to the Yandex.Cloud management console and select the folder where you want to perform the operations.
  2. Make sure the selected folder has a network with a subnet that the VM can be connected to. To do this, click the Virtual Private Cloud tile on the folder page. If the list contains a network, click on its name to see the list of subnets. If there aren't any networks or subnets, create them.

1. Create a VM with a pre-installed web server

To create a VM:

  1. On the folder page of the management console, click Create resource and select Virtual machine.

  2. In the Name field, enter the VM name.

    • The name must be unique within the folder.
    • The name may contain lowercase Latin letters, numbers, and hyphens.
    • The first character must be a letter. The last character can't be a hyphen.
    • The maximum length of the name is 63 characters.
  3. Select the availability zone to locate the VM in.

  4. Select a public image:

    • LEMP for Linux, nginx, MySQL, and PHP
    • LAMP for Linux, Apache, MySQL, and PHP

    For static websites, we recommend using LEMP.

  5. In the Computing resources section:

    • Choose the platform.
    • Specify the required amount of vCPUs and RAM.

    The minimum configuration is enough for functional testing:

    • Platform: Intel Cascade Lake.
    • Guaranteed vCPU share: 5%.
    • vCPU: 2.
    • RAM: 1 GB.
  6. In the Network settings section, select the subnet to connect the VM to when creating it.

  7. Specify data required for accessing the VM.

    • Enter the username in the Login field.
    • In the SSH key field, paste the contents of the public key file. You need to create a key pair for SSH connection yourself. To generate keys, use third-party tools, such as ssh-keygen utilities on Linux and macOS or PuTTYgen on Windows.
  8. Click Create VM.

Creating the VM may take several minutes. When the VM status changes to RUNNING, you can upload the website files to it.

When a VM is created, it is assigned an IP address and hostname (FQDN). This data can be used for SSH access.

See also

2. Upload the website files

  1. You can learn the IP address of the VM under Network on the VM page in the management console.

  2. Connect to the VM over SSH.

  3. Grant your user write access to the directory /var/www/html:

    $ sudo chown -R "$USER":www-data /var/www/html
    $ sudo chown -R "$USER":apache /var/www/html
  4. Upload the website files to the VM over SCP.

    Use the scp command-line utility:

    $ scp -r <path to the file directory> <VM user name>@<VM IP address>:/var/www/html

    Use the WinSCP program to copy the local file directory to the /var/www/html directory on the VM.

3. Configure DNS

The domain name that you want to use for your website must be associated with the created VM.

The instructions below describe how to configure an external DNS service using for the and domain names:

  • An A record allows you to map the domain name to its IP address.
  • A CNAME (Canonical Name) record for www allows you to access your website via

To configure the external DNS service, do the following:

  1. You can learn the IP address of the VM under Network on the VM page in the management console.
  2. Log in to the control panel of the external DNS service. Go to the list of your domains and click on the required domain name.
  3. Follow the Zone management link in the Domain management section.
  4. Create or edit an A record:
    • IP Address: your VM's public IP address.
    • Subdomain: @ (points to the main domain).
  5. Create a CNAME record with the following field values:
    • Subdomain: www.
    • Canonical name: @ or the domain with a dot at the end.
  6. Wait 15-20 minutes for DNS record changes to take effect. The waiting time may differ for your DNS service.