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:
-
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.
- Update and upgrade packages:
-
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.
- Install MySQL:
-
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."
- Inside the editor:
- Install PHP and the PHP-MySQL package:
-
Restart Apache:
- To apply changes, restart Apache:
systemctl restart apache2
- To apply changes, restart Apache:
-
Installing PHP Modules:
- View available PHP modules and libraries:
apt search php- | less
- To install desired PHP modules, use:
apt install package1 package2
- View available PHP modules and libraries:
-
Testing PHP:
- Create a test script to verify PHP installation:
vi /var/www/html/info.php
- Insert PHP code:
phpinfo();
- Insert PHP code:
- Test the PHP script by accessing:
http://123.123.123.123/info.php
- Create a test script to verify PHP installation:
-
Cleanup (Optional):
- Remove the test page:
rm /var/www/html/info.php
- Remove the test page:
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.