Setting up LAMP Stack with Laravel 10 on VPS Print

  • 0

Setting up LAMP Stack with Laravel 10 on VPS Running AlmaLinux 9: A Comprehensive Guide

1. Introduction

In the ever-evolving realm of web development, efficiency and performance are pivotal. The LAMP Stack, an acronym for Linux, Apache, MySQL, and PHP, emerges as a beacon of reliability, seamlessly powering countless applications worldwide. This stack, combined with the innovative capabilities of Laravel 10, ensures your web projects are not only dynamic but also scalable and secure.

But what about the foundation of our setup? That's where AlmaLinux 9 steps in. In a post-CentOS world, AlmaLinux emerges as the resilient, open-source enterprise-level OS that's perfect for hosting environments. It’s the bedrock ensuring that the LAMP Stack and Laravel perform at their peak.

2. Initial VPS Preparation

Before diving into the architectural intricacies of web development, we must ensure our foundation is rock solid. Start by:

  • Accessing Your VPS: Navigate to, log into your dashboard, and access your VPS. Remember, this is the gateway to building and managing your website.

  • Basic Security Measures:

    • Package Updates: Initiate by updating and upgrading your existing packages. Staying updated is a preliminary step in safeguarding against potential vulnerabilities.

sudo dnf update -y

Fortifying with firewalld: An unsung hero in the realm of cybersecurity, firewalld provides dynamic firewall management. Activate and enable it to ensure a secure

fortress for your projects.sudo dnf install firewalld -y
sudo systemctl start firewalld
sudo systemctl enable firewalld

    • Creating a Non-Root Sudo User: Operating directly from the root user can be risky. Create a separate sudo user, ensuring an added layer of security while performing administrative tasks.

3. Installing Apache

Apache, the world-renowned web server software, is known for its reliability and flexibility. Setting it up on AlmaLinux is straightforward:

  • Installation using dnf: dnf, the default package manager for AlmaLinux, makes software installations a breeze. To install Apache:

sudo dnf install httpd -y

Autostart Configuration: For optimal performance and reduced manual intervention, configure Apache to automatically start upon boot:

sudo systemctl enable httpd

Operational Test: Now that Apache is installed, let's ensure it's functioning as expected. Start the service:

sudo systemctl start httpd

Simply navigate to your VPS's IP address in a web browser. You should be greeted with Apache's default welcome page, signifying a successful installation.

Throughout the setup, remember that consistency and meticulous adherence to best practices ensure that your website runs seamlessly, efficiently, and securely. The tools provided by, combined with the strengths of Laravel 10 and AlmaLinux 9, offer an unparalleled web hosting experience.

4. Setting up MariaDB (MySQL)

MariaDB, a community-driven fork of MySQL, is famed for its fast performance, robustness, and security. Let's pave the way for our database-driven applications:

  • Installing MariaDB: Leveraging AlmaLinux's package manager, dnf, we'll quickly onboard MariaDB.

sudo dnf install mariadb-server mariadb -y
sudo systemctl start mariadb
sudo systemctl enable mariadb

Database Security Enhancement: With MariaDB in place, the next critical step is to fortify its security.

sudo mysql_secure_installation

This interactive script will guide you through optimizing your MariaDB installation. It's crucial for safeguarding against unauthorized access, disabling test databases, and ensuring remote root logins are restricted.

  • Crafting a Database for Laravel: Embark on your Laravel journey with a dedicated database and user.

GRANT ALL ON laravel_db.* TO 'laravel_user'@'localhost' IDENTIFIED BY 'password';

5. Installing PHP

Laravel's dynamism leans heavily on PHP. Ensuring we have the latest and most compatible PHP version is integral to our setup.

  • Integrating the Remi Repository: For cutting-edge PHP versions, integrating the Remi repository is the way to go.

sudo dnf install dnf-utils -y
sudo dnf install
sudo dnf module reset php
sudo dnf module enable php:remi-8.1

PHP Installation: With the repository set, install PHP and essential extensions for a smooth Laravel experience.

sudo dnf install php php-cli php-fpm php-json php-common php-mysqlnd php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath -y

Tuning php.ini: Dive into the PHP configuration to tweak parameters ensuring optimal performance and security.

sudo nano /etc/php.ini

  • Adjust parameters like memory_limit, upload_max_filesize, and date.timezone as per your requirements.

6. Configuring Apache for PHP

A harmonious interplay between Apache and PHP is the lifeblood of our web applications.

  • Amending Apache Configuration: Direct Apache to process PHP files using the PHP module.

echo "<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>" | sudo tee -a /etc/httpd/conf.d/php.conf

Rebooting Apache: Any configuration change necessitates a service restart.

sudo systemctl restart httpd

PHP Operational Test: Confirm that PHP processing is impeccable. Create a test file:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php

Access http://your_server_ip/phpinfo.php in a browser. If you're presented with the PHP information page, congratulations! You're all set.

When melding these robust technologies, it's the meticulous attention to detail that makes all the difference. With each step, you're building a resilient, high-performance platform, ready to host dynamic web applications with ease. Leveraging the resources provided by, paired with the power of Laravel and the reliability of AlmaLinux, your digital footprint is poised for success.

7. Installing Composer

Composer, the renowned PHP dependency management tool, is a linchpin in modern PHP applications. Laravel, among others, leans on Composer for efficient library management.

  • Downloading and Installing Composer Globally: A straightforward process ensures Composer is at your beck and call.

sudo dnf install php-cli php-zip wget unzip -y
cd ~
curl -sS -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Validating Composer's Functionality: A quick test ascertains that Composer was installed flawlessly.

composer --version

  • The output should echo Composer's version, signifying a triumphant installation.

8. Installing Laravel 10

With Composer in place, it's time to welcome Laravel 10, the framework that redefined PHP web development.

  • Utilizing Composer to Initiate a Laravel Project: This one command unfurls Laravel's potential on your server.

composer create-project --prefer-dist laravel/laravel laravel_app "10.*"

Tuning Necessary Permissions: Laravel's dynamic caching necessitates certain permissions. Ensuring these are set right is elemental for a glitch-free experience.

cd laravel_app
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 755 storage bootstrap/cache

Tailoring the .env File: Laravel's .env file is its nerve center, housing database configurations and more. Adjust the settings to match your MariaDB setup.
nano .env

Update the DB_DATABASE, DB_USERNAME, and DB_PASSWORD fields with the credentials set during MariaDB's setup.

9. Configuring a Virtual Host for Laravel

Ensuring Laravel and Apache harmonize is pivotal for our application's accessibility.

  • Drafting a Configuration for the Laravel Site in Apache:

sudo nano /etc/httpd/conf.d/laravel_app.conf

Populate the file with:

<VirtualHost *:80>
DocumentRoot /path_to_your_laravel_app/laravel_app/public

<Directory /path_to_your_laravel_app/laravel_app>
AllowOverride All

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

  • Adjusting Directives: Ensure you replace with your actual domain or IP and /path_to_your_laravel_app with the correct path to your Laravel application.

  • Rebooting Apache to Integrate the New Configuration:

sudo systemctl restart httpd

Each layer, each configuration, each tool added, is a brick in the edifice of your web application. When combined thoughtfully, these ingredients provide a seamless web experience, a testament to the power of the LAMP Stack, the elegance of Laravel, and the prowess of AlmaLinux—all hosted on the robust infrastructure provided by

10. Securing the VPS and Web Server

The bedrock of any robust online presence is security. Protecting your VPS and web server safeguards both your business's reputation and your users' data.

  • Integrating mod_security with Apache:

sudo dnf install mod_security mod_security_crs

This tool acts as a firewall for your applications, monitoring incoming traffic and blocking malicious requests.

  • Installing mod_evasive: A sentinel against DDoS attacks.

sudo dnf install mod_evasive

Fine-tune its configurations to suit your server's requirements, ensuring optimal protection against rapid repeated requests.

  • Augmenting SSH Security:

    • Disable root login: In /etc/ssh/sshd_config, adjust PermitRootLogin to no.
    • Modify the default port: Still in sshd_config, change the Port directive to a non-default value (e.g., 2222).

sudo systemctl restart sshd

Empowering with SSL via Let's Encrypt:

sudo dnf install certbot python3-certbot-apache
sudo certbot --apache

  • Let's Encrypt ensures your users' data is encrypted, fostering trust and enhancing your site's SEO.

11. Testing the Laravel Installation

An architect always inspects their creation, ensuring it stands tall and functions flawlessly.

  • Accessing the Laravel Interface: Open your web browser and navigate to your domain or IP address. The Laravel welcome page, a canvas ready for your masterpiece, should greet you.

  • Dissecting Laravel: Dive deep into Laravel's directory structure via SSH or an FTP client. Understand directories like app, config, routes, and resources, laying the groundwork for future development.

12. Conclusion

Through meticulous planning and diligent execution, you've erected a fortress of digital potential. Each component, from the resilient AlmaLinux to the dynamic Laravel framework, plays a crucial role in this web symphony. The journey, although intricate, underscores the vitality of precision in crafting a secure, efficient, and agile web experience.

13. Further Reading and Resources

  • Laravel 10 Documentation: Official Laravel 10 Documentation

  • Advanced Laravel Exploration: Venture beyond the basics. Explore packages, utilities, and advanced features like Eloquent, middleware, and service providers.

  • DomainIndia's Knowledge Trove: For deeper insights, nuances, or troubleshooting,'s knowledge base stands ready to assist, ensuring you're always equipped for web mastery.

When wielded with expertise and vision, tools morph into art. The digital canvas awaits your masterpiece. Happy coding!

Was this answer helpful?

« Back