Website on a LAMP or LEMP stack
LAMP (Linux, the Apache HTTP Server, MySQL, and PHP) and LEMP (its variation where Apache is replaced with Nginx) are popular sets of components for deploying web applications and dynamic websites.
In this tutorial, you'll learn how to deploy LAMP in the Yandex.Cloud infrastructure: as a result, you'll launch a VM running your site's web server.
To set up a LAMP or LEMP-based website:
- Before you start.
- Create a VM with a pre-installed web server.
- Upload the website files.
- Configure DNS.
- Check that the website is running.
If you no longer need the website, delete all its resources.
Before you start
Before deploying the server, you need to sign up for Yandex.Cloud and create a billing account:
- Go to the management console. Then log in to Yandex.Cloud or sign up if don't already have an account.
- On the billing page, make sure you linked a billing account, and it has the
TRIAL_ACTIVEstatus. If you don't have a billing account, create one.
If you have an active billing account, you can create or select a folder to run your VM in from the Yandex.Cloud page.
Required paid resources
The cost for maintaining a LAMP server includes:
- A fee for a continuously running VM (see Yandex Compute Cloud pricing).
- A fee for using a dynamic or static external IP address (see Yandex Virtual Private Cloud pricing).
Create a VM with a pre-installed web server
To create a VM:
On the folder page in the management console, click Create resource, and select Virtual machine.
In the Name field, enter a name for the VM:
- 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.
Select the availability zone to host the VM in. If you don't know which availability zone you need, leave the default.
Under Images from Cloud Marketplace, click Select and choose a VM image with the desired set of components:
- LAMP for Linux, Apache, MySQL, and PHP.
- LEMP for Linux, Nginx, MySQL, and PHP.
For static websites, we recommend using LEMP.
Under Computing resources:
- Choose a platform for the VM.
- Specify the necessary number of vCPUs and amount of RAM.
The minimum configuration is enough for functional website testing:
- Platform: Intel Cascade Lake.
- Guaranteed vCPU share: 5%.
- vCPU: 2.
- RAM: 1 GB.
In the Network settings section, select the network and subnet to connect the VM to. If you don't have a network or subnet, create them right on the VM creation page.
In the Public address field, leave the Auto value to assign 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 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 the SSH connection yourself. Learn how to connect to VMs via SSH.
The IP address and host name (FQDN) to connect to the VM are assigned on VM creation. If you selected No address in the Public address field, you won't be able to access the VM from the internet.
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.
Upload the website files
To test the web server, upload the
index.html file to the VM. You can use a test file. Make sure you unzip the archive.
You can learn the IP address of the VM under Network on the VM page in the management console.
Connect to the VM over SSH.
Grant your user write access to the directory
$ sudo chown -R "$USER":www-data /var/www/html
$ sudo chown -R "$USER":apache /var/www/html
Upload the website files to the VM over SCP:Linux/macOSWindows
$ 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/htmldirectory on the VM.
Configure DNS (if you have a domain name)
If you want to link a domain name to the deployed server, edit the DNS records for your domain.
The instructions below describe how to configure an external DNS service using reg.ru for the
example.com domain names:
- An A record allows you to map the
example.comdomain name to its IP address.
- A CNAME (Canonical Name) record for
wwwallows you to access your website via
To configure the external DNS service, do the following:
- You can learn the IP address of the VM under Network on the VM page in the management console.
- 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.
- Follow the Zone management link in the Domain management section.
- Create or edit an A record:
- IP Address: your VM's public IP address.
@(points to the main domain).
- Create a CNAME record with the following field values:
- Canonical name:
example.com.domain with a dot at the end.
- Wait 15-20 minutes for DNS record changes to take effect. The waiting time may differ for your DNS service.
Check that the website is running
To test the website, open it in the browser at:
http://<VM public IP address>.
You can check the domain name the same way only 15-20 minutes after editing the DNS records.
How to delete created resources
To stop paying for your deployed server, just delete the
lemp-vm virtual machine.
If you reserved a static public IP address specifically for this VM:
- Open the Virtual Private Cloud in your folder.
- Go to the IP addresses tab.
- Find the address you need, click , and select Delete.