Laravel is a popular PHP framework designed for building modern web applications. In this guide, we’ll cover how to install Laravel on Ubuntu 24.04. This guide is applicable whether you're setting up Laravel on a local server or using a Windows VPS UK, VPS UK Windows, or UK Windows VPS environment.

Step 1: Update the Server

Before you install Laravel, ensure your server is up to date. SSH into your Ubuntu server, whether it’s a local machine or hosted on a Windows Virtual Private Server Hosting, and run the following commands:

sudo apt update && sudo apt upgrade -y

Step 2: Install Apache, MySQL, and PHP

Laravel requires a web server, a database, and PHP. You can install Apache, MySQL, and PHP on your Windows VPS Hosting UK or any Ubuntu system with the following command:

sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql php-cli php-xml php-mbstring php-zip unzip -y

After installation, start and enable Apache and MySQL:

sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl start mysql
sudo systemctl enable mysql
        

Step 3: Install Composer

Composer is a dependency manager for PHP, which is required to install Laravel. Run the following commands to install Composer:

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

This installs Composer globally, allowing you to use it from any directory on your system, whether it’s hosted on a Windows VPS Italy or a UK VPS Windows environment.

Step 4: Install Laravel

Once Composer is installed, you can install Laravel by navigating to the web root directory and using Composer:

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

This will install Laravel in a directory called myapp. Set the correct permissions for your Laravel project:

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

Step 5: Configure Apache for Laravel

Next, create a new Apache virtual host file to serve your Laravel application. Run:

sudo nano /etc/apache2/sites-available/laravel.conf

Add the following configuration:

    ServerAdmin admin@example.com
    DocumentRoot /var/www/html/myapp/public
    ServerName your_domain_or_ip

    
        AllowOverride All
    

    ErrorLog ${APACHE_LOG_DIR}/laravel_error.log
    CustomLog ${APACHE_LOG_DIR}/laravel_access.log combined

        

Enable the new site and the Apache rewrite module:

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

Step 6: Set Up Database for Laravel

Laravel needs a database connection. Log in to MySQL and create a new database and user:

sudo mysql -u root -p
CREATE DATABASE laravel_db;
CREATE USER 'laraveluser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON laravel_db.* TO 'laraveluser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
        

Then, update the Laravel database configuration file located at /var/www/html/myapp/.env with the new database details:

DB_DATABASE=laravel_db
DB_USERNAME=laraveluser
DB_PASSWORD=password
        

Step 7: Test Laravel Installation

To ensure everything is working, open your browser and navigate to http://your_domain_or_ip. If you see the Laravel welcome page, you’ve successfully installed Laravel on your Ubuntu 24.04 server.

Conclusion

Installing Laravel on Ubuntu 24.04 is a straightforward process, and with the steps outlined above, you can have it up and running on a local machine or a Windows VPS UK, VPS UK Windows, or any Windows Virtual Private Server Hosting environment. For more powerful and flexible Windows Virtual Dedicated Server Hosting or Windows VPS Hosting UK solutions, visit Windows VPS UK.

For more information on Windows VPS UK, VPS UK Windows, and Windows Virtual Private Servers, visit windowsvps.uk.

Hai trovato utile questa risposta? 0 Utenti hanno trovato utile questa risposta (0 Voti)