Laravel is a popular open-source PHP framework designed for web application development. It offers an elegant syntax, a range of features, and tools that make development faster and easier. In this guide, we’ll show you how to install Laravel on Ubuntu 24.04. For optimal performance, we recommend hosting your Laravel application on a WindowsVPS. Using a VPS server allows for dedicated resources, ensuring better performance, scalability, and control over your development environment.

Step 1: Update Your VPS Server

Before starting the installation process, ensure your VPS server is updated with the latest software packages. Run the following commands to update your system:

sudo apt update && sudo apt upgrade -y

By using a WindowsVPS, you can ensure that your Laravel application runs in a high-performance environment, providing faster load times and better reliability.

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

Laravel requires a LAMP stack (Linux, Apache, MySQL, PHP) to run. Follow these steps to install Apache, MySQL, and PHP on your server:

    • Install Apache:
sudo apt install apache2 -y
    • Start and enable Apache to run at boot:
sudo systemctl enable apache2 --now
    • Install MySQL:
sudo apt install mysql-server -y
    • Secure the MySQL installation:
sudo mysql_secure_installation
    • Install PHP and the necessary extensions for Laravel:

sudo apt install php php-mysql php-xml php-mbstring php-json php-cli php-zip php-curl php-bcmath -y

Step 3: Create a MySQL Database for Laravel

Laravel requires a MySQL database to store application data. Log in to the MySQL shell and create a database and user for Laravel:

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;

Be sure to replace your_password with a secure password.

Step 4: Install Composer

Laravel is installed using Composer, a PHP dependency manager. Install Composer by running the following commands:


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

Verify the 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 Laravel project directory:


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

Step 7: Configure Apache for Laravel

Create an Apache virtual host configuration file for your Laravel application:

sudo nano /etc/apache2/sites-available/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. Then, enable the site and restart Apache:


sudo a2ensite laravel-app.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

Step 8: Configure Laravel Environment

Laravel uses a .env file for environment-specific settings. Open the .env file in the Laravel project directory and configure the database settings:

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

Update the following lines with your database information:


DB_DATABASE=laravel_db
DB_USERNAME=laravel_user
DB_PASSWORD=your_password

Save the file and exit the editor.

Step 9: Complete Laravel Installation

To complete the Laravel setup, generate the application key by running:

php artisan key:generate

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

Step 10: Optimize Your VPS Server for Laravel

Hosting Laravel on a WindowsVPS provides you with the dedicated resources necessary to run your web application efficiently. A VPS server ensures high performance, better scalability, and faster load times, allowing you to handle increased traffic and user demands seamlessly. A VPS also offers the flexibility to customize your server environment to suit your Laravel project’s specific needs.

Conclusion

Installing Laravel on Ubuntu 24.04 provides you with a powerful framework for building modern web applications. By hosting your Laravel application on a WindowsVPS, you benefit from better performance, scalability, and control, ensuring that your application runs smoothly in a production environment.

For more information on VPS hosting and optimizing your Laravel setup, visit WindowsVPS today.

© 2024 WindowsVPS - All Rights Reserved

Was dit antwoord nuttig? 0 gebruikers vonden dit artikel nuttig (0 Stemmen)