How do I set up a LAMP (Linux, Apache, MySQL, PHP) stack on my Linux VPS?

Collapse

Unconfigured Ad Widget

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Delaney martin
    Senior Member
    • Jun 2022
    • 116

    How do I set up a LAMP (Linux, Apache, MySQL, PHP) stack on my Linux VPS?

    Hey everyone,

    Can anyone help me with the easiest way to setup LAMP on my Linux VPS? Any advice would be highly appreciated.
  • Clay Page
    Member
    • Sep 2022
    • 89

    #2
    Step 1: Get Ready for Your LAMP Stack


    Before diving into the installation, make sure your VPS is up-to-date and ready for software installation.
    • SSH into your VPS: First, access your server using SSH:
    • ssh user@your_vps_ip
    • Update the system: Run the following commands to make sure your server is updated with the latest packages and security patches:
      • sudo apt update && sudo apt upgrade -y
    Step 2: Installing Apache – The Web Server
    • Install Apache: Run this command to install Apache: sudo apt install apache2 -y
    • Start Apache: Ensure Apache is up and running: sudo systemctl start apache2
    • Enable Apache to start on boot: Set Apache to start automatically when the server reboots:
      • sudo systemctl enable apache2
    • Check Apache’s status: Verify Apache is running without issues:
      • sudo systemctl status apache2

    You can visit http://your_vps_ip in a browser to check if Apache’s default page shows up.



    Step 3: Installing MySQL – The Database Server
    • Install MySQL: Run the following to install MySQL:
      • sudo apt install mysql-server -y
    • Run MySQL's security script: This is important to improve the security of your MySQL installation:
      • sudo mysql_secure_installation
    • Enable MySQL to start on boot:
      • sudo systemctl enable mysql
    • Verify MySQL is running:
      • sudo systemctl status mysql



    Step 4: Installing PHP – The Dynamic Scripting Language
    • Install PHP and essential modules: To run PHP with Apache and MySQL, install PHP along with necessary modules:
      • sudo apt install php libapache2-mod-php php-mysql -y
    • Test PHP with Apache: Create a simple PHP file to verify it works with Apache:
      • sudo nano /var/www/html/info.php
      • Add this content:
        <?php

    phpinfo();

    ?>

    Save and exit the file.Step 6: Fine-tune Your LAMP Stack
    • Install additional PHP modules: Depending on your project needs, you might need more PHP extensions. For example:
    • sudo apt install php-curl php-xml php-mbstring php-zip php-gd -y
    • Test MySQL with PHP: You can create a db_test.php file to ensure your PHP can interact with MySQL:
      • <?php

    $conn = new mysqli('localhost', 'root', 'your_password', 'mysql');

    if ($conn->connect_error) {

    die("Connection failed: " . $conn->connect_error);

    }

    echo "Connected successfully to MySQL!";

    ?>
    • Clean up the test files: Once your tests are done, it’s a good idea to delete any test files like info.php:
      • sudo rm /var/www/html/info.php
    Following these steps will speed up the installation process.

    Comment

    Working...
    X