A LAMP stack, which stands for Linux, Apache, MySQL/MariaDB, and PHP, is a group of open-source software that is typically installed together to enable a server to host dynamic websites and web apps. This guide provides a detailed walkthrough for installing a LAMP stack with MariaDB on Ubuntu 23.04, aimed at newcomers. We will cover each step of the process, providing real examples of command lines for installation and configuration.
Step 1: Update Your System
Always start by updating your system’s package list to ensure you install the latest versions of the software.
sudo apt update && sudo apt upgrade -y
Step 2: Install Apache Web Server
Apache is a widely used web server software. Install it on your Ubuntu server with the following command:
sudo apt install apache2 -y
After installation, you can check to make sure Apache is running:
sudo systemctl status apache2
Step 3: Install MariaDB
MariaDB is a popular database server, fully compatible with MySQL. It’s a robust and scalable alternative for database management.
- Install MariaDB:
sudo apt install mariadb-server -y
- Secure MariaDB Installation: After installation, run the security script that comes with MariaDB:
sudo mysql_secure_installation
Follow the prompts to set a root password, remove anonymous users, disallow root login remotely, remove the test database, and reload privilege tables.
Step 4: Install PHP
PHP is a server scripting language used for web development. Along with PHP, you will need to install several PHP extensions required by common web applications.
sudo apt install php libapache2-mod-php php-mysql php-cli php-curl php-json php-gd php-mbstring php-xml php-zip -y
Step 5: Configure Apache to Use PHP
By default, Apache serves HTML files. Adjust the configuration so Apache will prioritize PHP files.
- Edit the dir.conf file:
sudo nano /etc/apache2/mods-enabled/dir.conf
- Move the PHP index file to the first position: Before:
<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
After:
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
- Restart Apache to apply the changes:
sudo systemctl restart apache2
Step 6: Testing PHP Processing
To test if your system is correctly processing PHP files, create a test PHP file in Apache’s root directory.
- Create a PHP file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php
- Open your web browser and visit your server’s domain name or IP address followed by
/phpinfo.php
:
http://your_server_domain_or_IP/phpinfo.php
You should see a page displaying information about your server’s PHP configuration.
After successfully installing your LAMP stack with MariaDB on Ubuntu 23.04, consider utilizing Shape.host’s Linux SSD VPS services for hosting your web applications. Shape.host offers high-performance Cloud VPS solutions, ensuring your web applications run smoothly and efficiently. With Shape.host, you benefit from SSD storage for faster data access, robust security features to protect your applications, and outstanding customer support.