How to Install Laravel PHP Framework on AlmaLinux 9

Laravel is a popular PHP framework known for its elegant syntax, powerful tools, and ease of use for building web applications. In this guide, we’ll walk you through the steps to install Laravel on AlmaLinux 9. Using a WindowsVPS to host your Laravel application ensures optimal performance, security, and scalability, as a VPS server provides the dedicated resources necessary for smooth web application deployment.

Step 1: Update Your VPS Server

Before installing Laravel, ensure that your VPS server is up to date. Run the following commands to update your AlmaLinux 9 system:

sudo dnf update -y

By using a WindowsVPS, your Laravel application will run on an optimized server environment with enhanced performance and stability.

Step 2: Install Apache, MySQL, and PHP (LAMP Stack)

Laravel requires a LAMP stack (Linux, Apache, MySQL, and PHP) to run. Follow these steps to install the necessary components:

    • Install Apache:
sudo dnf install httpd -y
    • Start and enable Apache:
sudo systemctl enable httpd --now
    • Install MySQL (MariaDB):
sudo dnf install mariadb-server -y
    • Secure the MySQL installation:
sudo mysql_secure_installation
    • Install PHP along with the necessary extensions for Laravel:

sudo dnf install php php-mysqlnd php-xml php-json php-cli php-zip php-mbstring php-curl php-bcmath -y

Step 3: Create a MySQL Database for Laravel

Laravel requires a database to store data. Log in to the MySQL (MariaDB) shell and create a database for your Laravel project:

sudo mysql -u root -p

Create the database and user:


CREATE DATABASE laravel_db;
CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON laravel_db.* TO 'laravel_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Make sure to replace your_password with a strong password.

Step 4: Install Composer

Laravel is installed via Composer, a PHP dependency manager. To install Composer, run the following commands:


sudo dnf install curl -y
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Verify Composer installation:

composer --version

Step 5: Install Laravel

Now that Composer is installed, use it to install Laravel. Navigate to the web root directory and create a new Laravel project:


cd /var/www/html
composer create-project --prefer-dist laravel/laravel laravel-app

Step 6: Set Permissions for Laravel

After Laravel is installed, set the correct ownership and permissions for the project directory:


sudo chown -R apache:apache /var/www/html/laravel-app
sudo chmod -R 755 /var/www/html/laravel-app

Step 7: Configure Apache for Laravel

Create a new Apache virtual host file for your Laravel project:

sudo nano /etc/httpd/conf.d/laravel-app.conf

Add the following configuration:



    ServerAdmin admin@your-domain.com
    DocumentRoot /var/www/html/laravel-app/public
    ServerName your-domain.com

    
        AllowOverride All
        Require all granted
    

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

Replace your-domain.com with your actual domain name. Enable the Apache rewrite module and restart Apache to apply the changes:


sudo a2enmod rewrite
sudo systemctl restart httpd

Step 8: Configure the .env File

Laravel uses a .env file to manage environment-specific settings, such as database credentials. Open the .env file located in the Laravel project directory and update the following fields to match your database configuration:

sudo nano /var/www/html/laravel-app/.env

Update the following lines with your database details:


DB_DATABASE=laravel_db
DB_USERNAME=laravel_user
DB_PASSWORD=your_password

Save the file and exit the editor.

Step 9: Complete the Laravel Installation

Finally, run the following command to generate an application key, which is used by Laravel for encryption:

php artisan key:generate

Your Laravel installation is now complete. You can access the application by navigating to http://your-domain.com in your browser.

Step 10: Optimize Laravel with a VPS Server

For the best performance and scalability, it’s important to host your Laravel application on a reliable VPS. A WindowsVPS provides the dedicated resources needed for running your application smoothly, handling high traffic, and scaling your infrastructure as your business grows. A VPS server offers the flexibility and control you need to manage your Laravel application efficiently.

Conclusion

Installing Laravel on AlmaLinux 9 is a straightforward process that gives you a powerful PHP framework for building web applications. By hosting your Laravel project on a WindowsVPS, you can benefit from better performance, security, and scalability, ensuring that your application can grow as your needs evolve.

For more information on VPS hosting and how to optimize your Laravel project, visit WindowsVPS today.

© 2024 WindowsVPS - All Rights Reserved

Cette réponse était-elle pertinente? 0 Utilisateurs l'ont trouvée utile (0 Votes)