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.

Esta resposta lhe foi útil? 14 Usuários acharam útil (53 Votos)