Laravel is a popular PHP framework for building web applications. In this guide, we will walk through the steps to install Laravel on AlmaLinux 8 using Nginx as the web server and securing it with a free Let's Encrypt SSL certificate.

Step 1: Update Your System

Start by ensuring your system is up to date:

sudo dnf update

Step 2: Install Required Packages

Install the necessary packages, including PHP and Nginx:

sudo dnf install -y nginx php php-cli php-fpm php-mysqlnd php-xml php-mbstring php-json php-zip

Step 3: Start and Enable Nginx

Start the Nginx service and enable it to run at startup:

sudo systemctl start nginx
sudo systemctl enable nginx

Step 4: Install Composer

Composer is a dependency manager for PHP, required for installing Laravel. Download and install Composer:

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

Step 5: Create a Directory for Laravel

Create a directory for your Laravel application:

sudo mkdir -p /var/www/laravel
cd /var/www/laravel

Step 6: Install Laravel

Use Composer to create a new Laravel project:

composer create-project --prefer-dist laravel/laravel .

Step 7: Set Permissions

Set the correct permissions for the Laravel directory:

sudo chown -R nginx:nginx /var/www/laravel
sudo chmod -R 775 /var/www/laravel/storage

Step 8: Configure Nginx for Laravel

Create a new Nginx configuration file for your Laravel application:

sudo nano /etc/nginx/conf.d/laravel.conf

Add the following configuration:

server {
        listen 80;
        server_name your_domain.com;

        root /var/www/laravel/public;
        index index.php index.html index.htm;

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php-fpm/www.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }

        location ~ /\.ht {
            deny all;
        }
    }

Replace your_domain.com with your actual domain name.

Step 9: Test Nginx Configuration

Test the Nginx configuration for syntax errors:

sudo nginx -t

If there are no errors, restart Nginx:

sudo systemctl restart nginx

Step 10: Install Certbot for Let's Encrypt SSL

Install Certbot to obtain a free SSL certificate:

sudo dnf install certbot python3-certbot-nginx

Step 11: Obtain a Free SSL Certificate

Run the following command to obtain and install your SSL certificate:

sudo certbot --nginx -d your_domain.com

Follow the prompts to complete the process.

Conclusion

You have successfully installed Laravel on AlmaLinux 8 with Nginx and secured it using a free Let's Encrypt SSL certificate. This setup provides a robust platform for developing and hosting your web applications.

If you're looking for a reliable hosting solution for your Laravel application, consider using Windows VPS UK. With Windows VPS, you can efficiently host your applications and ensure high performance. Whether you need VPS UK Windows or Windows Virtual Private Servers, you'll find a solution that fits your requirements.

For larger deployments or enterprise needs, explore Windows Virtual Dedicated Server Hosting or Virtual Private Server Hosting Windows. Whether you're located in the UK, Italy, or elsewhere, Windows VPS Italy and UK VPS Windows offer reliable hosting options. Visit Windows VPS Hosting UK to discover the best hosting solutions for your Laravel deployment.

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