Setting Up a LAMP Stack on Kamatera for Web Development

LAMP stands for Linux, Apache, MySQL/MariaDB, and PHP/Perl/Python. It is a popular stack of open-source software used to create web servers and deploy web applications. In this guide, you’ll learn the step-by-step process for setting up a LAMP stack on the Kamatera cloud platform for the purposes of web development.   

Here’s a brief overview of each component:

Prerequisites

There are three ways to get your LAMP stack working.

  1. Using Kamatera
  2. Using Windows
  3. Using Ubuntu

Before you begin, ensure you have one of the following sets of software installed on your system:

 

Using Kamatera

On the homepage, find the “Login” button located at the top right corner.

  1. Click on the “Login” button.
  2. Enter your registered email address and password in the provided fields.
  3. After entering your credentials, click the “Log In” button to access your Kamatera account dashboard.
  4. Once logged in, you will be directed to the main dashboard of your Kamatera account.
  5. From the left-hand side navigation menu, click on “My Cloud” to view and manage your cloud services.
  6. Within the “My Cloud” section, go to “Create New Service” button. 
  7. Click on the “Create New Service” button to start the process.
  8. Choose the zone that is closest to your target audience.

 

 

 

 

    1. From the drop-down menu select the version once you have selected the service.

 

 

  1. Choose Server specifications.

Select the Type, CPU, RAM, and SSD DISK#1 according to your needs.


 

  1. Choose Networking as Public Internet Network

 

Advanced Configuration

 

 

Finalize Settings


 
Create a unique password for your server and confirm it by entering it again.

Select a name for your server.

  1. Click the “Create Server” button to finalize and launch your new virtual machine.

 

Using Windows

LAMP can be installed on Windows, but it requires a series of steps.

Installing XAMPP

 

    1. Download the latest version of XAMPP from the official website.
    2. After the download is complete, run the installer.

    3.  

    4. Follow the prompts provided by the installer to install XAMPP on your system.
    5.  

    6. Once the installation process is finished, launch the XAMPP Control Panel.

     

    Configuring Apache

     

      1. In the XAMPP Control Panel, locate the Apache section.
      2.  

         

      3. Click on the “Start” button next to Apache to initiate the Apache service. Status will be seen changing into ‘running’.

      4.  

      5. Open your web browser and type “http://localhost” into the address bar.
      6. Press Enter to navigate to the localhost address.
      7. Ensure that Apache is running correctly by verifying that the XAMPP welcome page appears in your browser.

       

       

      Configuring MySQL

       

      1. In the XAMPP Control Panel, locate the MySQL section.
      2.  

      3. Click on the “Start” button next to MySQL to initiate the MySQL service. Status will be seen changing into ‘running’.
      4.  

      5. To access the MySQL command line, click on the “Shell” button in the XAMPP Control Panel.
      6. To access phpMyAdmin, click on the “Admin” button next to the MySQL service in the XAMPP Control Panel.

       
      Configuring PHP
       

      1. In the XAMPP Control Panel, locate the Apache section.
      2. Click on the “Config” button next to Apache.
      3. From the dropdown menu, select “php.ini” to access the PHP configuration file.
      4.  

         

      5. Inside the php.ini file, locate the line “; extension=MySQL”.
      6. Remove the semicolon “;” at the beginning of the line to uncomment it.
      7. Save the changes made to the php.ini file.
      8. Restart Apache to apply the changes.

       

      Using 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

      • Open a terminal window on your Linux system.
      • To ensure you have the latest software, update your package manager by running the following command:
      • This will update the list of available packages and upgrade the installed packages to their latest versions.

       

      A LAMP stack is a development framework that comprises four key components: Linux, Apache, MySQL, and PHP. Below are step-by-step instructions for setting up a LAMP 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 Apache

       

      Apache is required for the site visitors to see web pages. Apache has been highly accepted web server with a large active user base, that will be installed on ubuntu using apt package manager.

       

      1. Open a terminal window by pressing Ctrl + Alt + T.
      2. Install Apache by running the following command.
      3. sudo apt install apache2


         

      4. Once the installation is complete, enable Apache to start at boot and start the service by executing the following commands.
      5.              sudo systemctl enable apache2

                     sudo systemctl start apache2

         

      6. To verify that Apache 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 Apache 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.
      2. sudo apt install mysql-server

      3. During the installation, you will be prompted to set a root password for MySQL. Choose a strong password and remember it. 
      4. After installation, secure your MySQL installation by executing the following command and following the prompts:

      sudo mysql_secure_installation

       

       


       
      Step 3: Install PHP
       
      With Apache 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.

      1. Install PHP and some common extensions by executing the following command.
      2. sudo apt install php libapache2-mod-php php-mysql

      3. Once PHP is installed, you can also test it by creating a PHP info file. To do this, create a new file in the web server’s root directory.
      4. sudo nano /var/www/html/phpinfo.php

        Note: Add the following content to the file and save it: 

                     <?php    phpinfo();

      5. Restart Apache to apply the changes by executing the following command.
      6. sudo systemctl restart apache2

         

      7. In your web browser, navigate to http://localhost/phpinfo.php (or use your server’s IP address if it’s remote). You should see the PHP information page displayed.

       

      Step 4: Testing MySQL and PHP

       

      You can create a simple PHP script to test the connection to MySQL by following these steps.

       

      1. Create a test PHP file by executing the following command. 
      2. sudo nano /var/www/html/test-mysql.php

         

      3. Add the following PHP code to the file and save it.
      4. “`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);    ?>   

        “`

      5. Replace ”your_mysql_password” with the root password you set during the MySQL installation in the PHP code.
      6. Open your web browser and navigate to http://localhost/test-mysql.php (or your server’s IP address). You should see a message indicating a successful MySQL connection displayed in the browser.
      7.  

        Congratulations! You’ve successfully installed a LAMP stack on your Ubuntu system. You are now ready to start building and hosting web applications on your server.

         

Have additional questions? Search below: