Introduction: In the world of web development, having a reliable server stack is essential. LAMP, which stands for Linux, Apache, MySQL, and PHP, is a popular choice for hosting websites and web applications. In this guide, we’ll walk you through the process of setting up a LAMP server on an Ubuntu-based system.

Prerequisites:

Before we dive into the installation process, make sure you have the following:

  1. An Ubuntu-based system (Ubuntu 20.04 LTS is used in this guide).
  2. A user account with sudo privileges.
  3. Access to the terminal.

Step 1: Update and Upgrade Your System:

First, open the terminal and ensure that your system is up-to-date by running the following commands:

Copy
            
  sudo apt update
  sudo apt update
        

This will update the package list and upgrade any existing packages.

Step 2: Install Apache (A) – The Web Server:

Apache is the web server that will serve your web content. Install it by running:

Copy
            
  sudo apt install apache2
        

Once the installation is complete, you can start Apache and enable it to start at boot with these commands:

Copy
            
   sudo systemctl start apache2
   sudo systemctl enable apache2
        

You can check if Apache is running by opening a web browser and entering your server's IP address or hostname. You should see the Apache2 default page.

Step 3: Install MySQL (M) – The Database Server:

MySQL is the database management system you'll use to store your website's data. Install it with the following command:

Copy
            
   sudo apt install mysql-server
        

During the installation, you'll be prompted to set a root password for MySQL. Be sure to choose a strong password.

Next, secure your MySQL installation by running:

Copy
            
   sudo mysql_secure_installation
        

Follow the on-screen instructions to set security preferences.

Step 4: Install PHP (P) – The server-side scripting language

PHP is the server-side scripting language that enables dynamic content. Install it along with some common PHP modules:

Copy
            
   sudo apt install php libapache2-mod-php php-mysql
        

Step 5: Test Your LAMP Setup To verify that your LAMP stack is working correctly, create a simple PHP file and place it in the web server's document root:

Copy
            
   sudo nano /var/www/html/info.php
        

In the file, add the following PHP code:

Copy
   
   <?php
    phpinfo ();
   ?>
        

Save and exit the text editor. You can access this information by going to http://your_server_ip/info.php in a web browser.

Step 6: Additional PHP Configuration (Optional) You might want to tweak PHP settings. To do this, open the PHP configuration file in a text editor:

Copy
            
   sudo nano /etc/php/7.x/apache2/php.ini
        

Replace "7.x" with your installed PHP version.

You can modify PHP settings according to your needs. Don't forget to restart Apache for the changes to take effect:

Copy
            
   sudo systemctl restart apache2
        

Step 7: Firewall Configuration (Optional) If you have UFW (Uncomplicated Firewall) installed, you'll need to open the necessary ports for Apache. By default, web traffic uses port 80 (HTTP) and port 443 (HTTPS). To allow them, use the following commands:

Copy
            
   sudo ufw allow 80/tcp
   sudo ufw allow 443/tcp
        

Then, enable the firewall:

Copy
            
   sudo ufw enable 
        

Step 8: Test Your Website You can now create your website or upload your web application to the /var/www/html directory. Access your site by entering your server's IP address or domain name in a web browser.

That's it! You've successfully set up a LAMP server on Ubuntu. You can now start building and hosting your web projects on your own server.

Also Read

You may also like

Get the latest

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Hot news

Travel

Lorem ipsum dolor sit amet consectetur adipiscing elit dolor

Most popular