Here are the instructions for setting up a LEMP stack on a Kamatera server for the purposes of web development. LEMP represents a known web server configuration that is used to host dynamic websites and applications. Here’s a brief overview of each component:
Prerequisites
There are three prominent ways to get LEMP Stack working.
Before you begin, ensure you have one of the following sets of software installed on your system:
On the homepage, find the “Login” button located at the top right corner.
Enter your registered email address and password in the provided fields.
Click on the “Create New Service” button to start the process.
After choosing the zone, you will continue with the setup by selecting the specifications for your virtual machine.
Select the Type, CPU, RAM, and SSD DISK#1, according to your needs.
Advanced Configuration:
Finalize Settings:
Create a unique password for your server and confirm it by entering it again.
Select a name for your server.
LEMP can be installed on Windows, but it requires a Windows Subsystem for Linux to be installed.
Post successful installation, refer to the following section for using LEMP on Ubuntu.
Step 1: Installing Linux
If you haven’t already, install a Linux distribution like Ubuntu, CentOS, or Debian. For this guide, we’ll use Ubuntu as an example.
Step 2: Update Your Package Manager
A LEMP stack is a development framework that comprises four key components: Linux, Nginx, MySQL, and PHP. Below are step-by-step instructions for setting up a LEMP stack on Ubuntu:
*Note: These instructions are tailored for a fresh installation of Ubuntu. Ensure your system is up-to-date by executing the following commands in a terminal:
Step 1: Installing Nginx
Nginx is required for the site visitors to see web pages. Nginx is a high-performance web server that will be installed on ubuntu using apt package manager.
sudo apt install nginx
3. Once the installation is complete, the Nginx web server will start running on your Ubuntu server.
Note: It is suggested to allow connections to Nginx. For that, the most restrictive application profile allowing the traffic shall be enabled. For example, enable the HTTP traffic on port 80 by running the following:
Sudo ufw allow ‘Nginx HTTP’
4. To verify that Nginx is working properly, open a web browser and enter your server’s IP address or “http://localhost” if you’re setting this up on your local machine. You should see the default Nginx welcome page.
Step 2: Install MySQL
With a web server set up successfully, a database system needs to be installed for storing and managing site data. MySQL is one such popular and effective database management system used alongside the PHP ecosystem.
1. Install MySQL by executing the following command.
sudo apt install mysql-server
Step 3: Install PHP
With Nginx and MySQL installed to host, store and manage the data for your site, PHP is to be installed to serve the code and generate dynamic content for the web server.
sudo apt install php8.1-fpm php-mysql
Step 4: Testing MySQL and PHP
You can create a simple PHP script to test the connection to MySQL by following these steps.
sudo nano /var/www/html/test-mysql.php
“`php <?php $connection = mysqli_connect(“localhost”, “root”, “your_mysql_password”);
if (!$connection) {
die(“Database connection failed: ” . mysqli_connect_error());
}
echo “Connected to MySQL successfully!”;
mysqli_close($connection); ?>
“`
You’ve successfully installed a LEMP stack on your Ubuntu system. You are now ready to start building and hosting web applications on your server.
Have additional questions? Search below: