If you’re looking to host dynamic websites and web apps, a LAMP stack can provide you with the necessary open-source software to get started. LAMP stands for Linux, Apache, MariaDB, and PHP, and this tutorial will guide you through the installation process on a Debian 12 system. By following these steps, you’ll be able to set up a robust server environment that can handle your website’s dynamic content efficiently.
Prerequisites
Before we dive into the installation process, make sure you have the following prerequisites in place:
- A Debian 12 server
- Root access or a user account with sudo privileges
Step 1: Update the System
Before installing any software, it’s essential to ensure that your system is up to date. Open a terminal and run the following commands:
sudo apt update
sudo apt upgrade -y
These commands will update the package lists and upgrade any installed packages to their latest versions.
Step 2: Install MariaDB Database Server
The next step is to install the MariaDB database server. MariaDB is a popular choice for hosting websites due to its speed and reliability. To install MariaDB, run the following command:
sudo apt install -y mariadb-server mariadb-client
Once the installation is complete, you can check the status of the MariaDB service by running the following command:
sudo systemctl status mariadb
Step 3: Secure the Database Server
To secure your database server, you can use the mysql_secure_installation
command. This command will guide you through a series of steps to set a root password, remove anonymous users, disable remote login for the root user, and remove the test database.
sudo mysql_secure_installation
Follow the prompts and provide the necessary information to secure your database server.
Step 4: Install Apache Web Server
Apache is a widely used web server that can handle a large number of concurrent connections. To install Apache, run the following command:
sudo apt install -y apache2 apache2-utils
Once the installation is complete, you can check the status of the Apache service by running the following command:
sudo systemctl status apache2
Step 5: Enable HTTP and HTTPS Ports
To enable HTTP and HTTPS connections, you need to install the UFW firewall. UFW stands for Uncomplicated Firewall and provides an easy-to-use interface for managing firewall rules. To install UFW, run the following command:
sudo apt install ufw -y
Once UFW is installed, you can enable HTTP and HTTPS connections by running the following commands:
sudo ufw allow http sudo ufw allow https
To enable and reload the firewall, use the following commands:
sudo ufw enable sudo ufw reload
Step 6: Install PHP
PHP is a server-side scripting language that is widely used for web development. To install PHP and its necessary modules, run the following command:
sudo apt install -y php libapache2-mod-php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
Once the installation is complete, you can confirm the PHP version by running the following command:
php -v
Step 7: Test PHP Installation
To test if PHP is installed and working correctly, we will create a small file that will display the PHP information. Run the following command to create the file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
You can now view the PHP info page by opening your browser and entering your server’s IP address followed by /info.php
. For example, if your server’s IP address is 192.168.0.1
, you would enter http://192.168.0.1/info.php
in your browser’s address bar.
Step 8: Remove PHP Info File
Once you have confirmed that PHP is installed and working correctly, it is essential to remove the info.php
file for security reasons. To remove the file, run the following command:
sudo rm /var/www/html/info.php
Conclusion
Congratulations! You have successfully installed the LAMP stack on your Debian 12 system. With Linux as the operating system, Apache as the web server, MariaDB as the database server, and PHP as the server-side scripting language, you now have a powerful environment for hosting dynamic websites and web apps.
Remember, if you need reliable and scalable cloud hosting solutions, Shape.host offers top-notch services with their Cloud VPS. With Shape.host, you can enjoy the benefits of a secure and efficient hosting environment tailored to your specific needs.
Now that you have a fully functional LAMP stack, you can start building and deploying your websites and web applications with confidence. Happy coding!