تحميل

Installing the LAMP Stack on Ubuntu

Updated at
22/08/2023
Views
7102

Introduction: The LAMP stack, composed of Linux, Apache, MySQL, and PHP, is a powerful foundation for hosting dynamic websites and web applications. This article guides you through the process of installing a LAMP stack on a Cloud Server, Virtual Private Server (VPS), or Dedicated Server running Ubuntu 18.04, Ubuntu 20.04, or Ubuntu 22.04.

Prerequisites:

  • Verify that your server meets the hardware capacity required for the LAMP stack.
  • Ensure that Ubuntu 18.04, 20.04, or 22.04 is installed on your server.

Installation Steps:

  1. Installing Apache:

    • Update and upgrade packages:
      root@localhost:~# apt update root@localhost:~# apt upgrade
    • Install Apache:
      root@localhost:~# apt install apache2
    • Verify Apache installation by accessing the public IP address in your browser:
      http://123.123.123.123
    • A test page indicates a successful installation.
  2. Installing MySQL:

    • Install MySQL:
      apt install mysql-server
    • Secure MySQL installation and set a password for the root user:
      sudo mysql mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'MY_NEW_PASSWORD'; mysql> exit mysql_secure_installation
    • Follow the prompts to enhance security and remove default settings.
  3. Installing PHP:

    • Install PHP and the PHP-MySQL package:
      apt install php libapache2-mod-php php-mysql
    • Adjust Apache settings to prioritize index.php over index.html:
      vi /etc/apache2/mods-enabled/dir.conf
      • Inside the editor:
        DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
      • Move "index.php" after "DirectoryIndex."
  4. Restart Apache:

    • To apply changes, restart Apache:
      systemctl restart apache2
  5. Installing PHP Modules:

    • View available PHP modules and libraries:
      apt search php- | less
    • To install desired PHP modules, use:
      apt install package1 package2
  6. Testing PHP:

    • Create a test script to verify PHP installation:
      vi /var/www/html/info.php
      • Insert PHP code:
        <?php phpinfo(); ?>
    • Test the PHP script by accessing:
      http://123.123.123.123/info.php
  7. Cleanup (Optional):

    • Remove the test page:
      rm /var/www/html/info.php

Conclusion: You've successfully installed the LAMP stack on your Ubuntu Cloud Server, creating a solid foundation for hosting dynamic websites and applications. This powerful combination of Linux, Apache, MySQL, and PHP ensures a versatile environment for your web projects.

YottaSrc footer

لماذا تختارنا؟

أفضل الأسعار, تخزين SSD سريع و دعم فني
24/7 حقيقي

control panel icon
cPanel

إدارة موقعك من خلال CPanel بأحدث إصدار

security icon
سريع وموثوق وآمن

ضمان وقت تشغيل بنسبة 99.8٪.
لذا ركز على عملك!

support icon
دعم 24/7/365

ليلاً أو نهارًا ، مطر أو شمس ،
فريقنا هنا من أجلك!

cloud backup icon
نسخ احتياطي يومي

نسخ احتياطي يومي وأسبوعي.
ملفاتك آمنة!