Introduction
Laravel is a popular PHP framework used for developing web applications. Using Docker for installation simplifies the process and ensures that your application runs in a consistent environment. This guide will walk you through installing Laravel with Docker on Ubuntu 22.04, which can be effectively hosted on a Windows VPS UK for optimal performance and scalability.
Prerequisites
- An Ubuntu 22.04 server with root access
- Basic knowledge of Linux commands
- Docker and Docker Compose installed on your server
Step 1: Update Your System
Start by updating your package index and upgrading existing packages:
sudo apt update && sudo apt upgrade -y
Step 2: Install Docker and Docker Compose
If you haven’t installed Docker yet, you can install it using the following commands:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt update
sudo apt install docker-ce -y
Start Docker and enable it to run on boot:
sudo systemctl start docker
sudo systemctl enable docker
To install Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Verify the installation:
docker-compose --version
Step 3: Create a New Laravel Project
Create a directory for your Laravel application:
mkdir ~/laravel-app
cd ~/laravel-app
Next, create a docker-compose.yml
file in this directory:
nano docker-compose.yml
Paste the following configuration into the file:
version: '3.8'
services:
app:
image: php:8.0-fpm
container_name: laravel_app
working_dir: /var/www
volumes:
- .:/var/www
networks:
- laravel-network
web:
image: nginx:alpine
container_name: laravel_web
ports:
- "80:80"
volumes:
- .:/var/www
- ./nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- app
networks:
- laravel-network
networks:
laravel-network:
driver: bridge
Next, create an Nginx configuration file:
nano nginx.conf
Add the following configuration:
server {
listen 80;
server_name localhost;
root /var/www/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass app:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
Step 4: Install Laravel
Run the following command to start the containers and install Laravel:
docker-compose up -d
docker-compose exec app curl -s https://getcomposer.org/installer | php
docker-compose exec app php composer.phar create-project --prefer-dist laravel/laravel .
Step 5: Access Your Laravel Application
Open your web browser and navigate to http://your_server_ip
. You should see the Laravel welcome page, indicating that the installation was successful.
Step 6: Conclusion
You have successfully installed Laravel with Docker on Ubuntu 22.04, providing a robust environment for developing web applications. This setup can greatly benefit from being hosted on a Windows VPS. For additional options, explore various VPS UK Windows solutions, including Windows Virtual Private Server Hosting and Windows VPS Hosting UK for optimal performance.