LAMP Stack Setup on Linux: Easy Configuration Guide

Setting up a LAMP stack (Linux, Apache, MySQL, PHP) on Linux is a common configuration for hosting dynamic websites and web applications. Below are the simple steps to set up a LAMP stack on a Linux system:

1. Install Apache:
   - Update your package index:  
     ```
     sudo apt update
     ```
   - Install Apache:  
     ```
     sudo apt install apache2
     ```
   - Start Apache:  
     ```
     sudo systemctl start apache2
     ```
   - Check Apache status:  
     ```
     sudo systemctl status apache2
     ```

2. Install MySQL:
   - Install MySQL server package:  
     ```
     sudo apt install mysql-server
     ```
   - Run the security script to secure MySQL installation:  
     ```
     sudo mysql_secure_installation
     ```
   - Follow the prompts to configure MySQL security options.

3. Install PHP:
   - Install PHP and required modules:  
     ```
     sudo apt install php libapache2-mod-php php-mysql
     ```
   - Restart Apache for changes to take effect:  
     ```
     sudo systemctl restart apache2
     ```
   
4. Test PHP Processing:
   - Create a test PHP file in Apache's document root directory (usually /var/www/html/):  
     ```
     sudo nano /var/www/html/info.php
     ```
   - Add the following PHP code to the file:
     ```php
     
     phpinfo();
     ?>
     ```
   - Save and close the file.
   - Access this file in a web browser by navigating to `http://your_server_ip/info.php`. You should see the PHP configuration information.

5. Configure Virtual Hosts (Optional):
   - If hosting multiple websites or applications, you can configure Apache virtual hosts to serve each site separately. Refer to Apache documentation for detailed instructions on virtual host configuration.

6. Set Up MySQL Databases and Users:
   - Access MySQL shell as root:  
     ```
     sudo mysql
     ```
   - Create databases and users as needed for your applications. For example:
     ```
     CREATE DATABASE dbname;
     CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
     GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost';
     FLUSH PRIVILEGES;
     ```
   - Exit MySQL shell:  
     ```
     exit;
     ```

Your LAMP stack is now set up and ready to host websites and web applications on your Linux server. Ensure to configure your firewall settings, if applicable, to allow traffic on ports 80 (HTTP) and 443 (HTTPS) for web traffic.


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 40