To configure a LAMP stack (Linux, Apache, MySQL, PHP) on a Linux server, you can follow these general steps:
Step 1: Install Linux
1. Choose a Linux distribution (e.g., Ubuntu, CentOS, or Debian) and install it on your server.
Step 2: Update the System
1. Log in to your server as the root user or a user with sudo privileges.
2. Update the package repository and upgrade the system by running the following commands:
sudo apt update
sudo apt upgrade
Step 3: Install Apache
1. Install the Apache web server by running the following command:
sudo apt install apache2
Step 4: Configure Firewall (optional)
1. If you have a firewall enabled, you need to allow HTTP (port 80) and HTTPS (port 443) traffic.
2. For example, with UFW (Uncomplicated Firewall), you can run the following commands:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
Step 5: Install MySQL (MariaDB)
1. Install the MySQL database server by running the following command:
sudo apt install mysql-server
2. During the installation, you will be prompted to set a root password for MySQL.
Step 6: Secure MySQL Installation (optional)
1. Run the MySQL security script to improve the security of your installation:
sudo mysql_secure_installation
For Detailed Instruction Click Here
Step 7: Install PHP
1. Install PHP and its required modules by running the following command:
sudo apt install php libapache2-mod-php php-mysql
Step 8: Configure Apache to Use PHP
1. Open the PHP configuration file in a text editor:
sudo nano /etc/php/{version}/apache2/php.ini
Replace `{version}` with your PHP version (e.g., 7.4).
2. Find the line `;extension=mysqli` and remove the semicolon (`;`) at the beginning to enable the MySQL extension.
3. Save the file and exit the text editor.
4. Restart Apache for the changes to take effect:
sudo service apache2 restart
Step 9: Test the LAMP Stack
1. Create a test PHP file in the web server's document root directory:
sudo nano /var/www/html/info.php
2. Add the following PHP code to the file:
<?php
phpinfo();
?>
3. Save the file and exit the text editor.
4. Open a web browser and visit your server's IP address or domain name followed by `/info.php` (e.g., `http://server_ip/info.php`).
5. You should see the PHP information page indicating that your LAMP stack is configured correctly.
That's it! You have successfully configured a LAMP stack on your Linux server.