94
Caching/redis/install.md
Normal file
94
Caching/redis/install.md
Normal file
@@ -0,0 +1,94 @@
|
||||
|
||||
# Setting Up and Configuring Redis Server
|
||||
|
||||
## 1. Install Redis Server
|
||||
Update your package list and install Redis server:
|
||||
```bash
|
||||
apt update && apt install redis-server -y
|
||||
```
|
||||
|
||||
## 2. Update Redis Configuration
|
||||
Edit the Redis configuration file:
|
||||
```bash
|
||||
vim /etc/redis/redis.conf
|
||||
```
|
||||
|
||||
### Change Supervision Service to Systemd
|
||||
Locate the `supervised` directive and change its value to `systemd`:
|
||||
```conf
|
||||
supervised systemd
|
||||
```
|
||||
|
||||
### Restart the Redis Service
|
||||
Restart the Redis service to apply changes:
|
||||
```bash
|
||||
systemctl restart redis
|
||||
```
|
||||
|
||||
## 3. Test Redis Server
|
||||
Use the Redis CLI to test the server:
|
||||
```bash
|
||||
redis-cli
|
||||
```
|
||||
|
||||
Run the following commands:
|
||||
- Test connectivity:
|
||||
```bash
|
||||
ping
|
||||
```
|
||||
Expected output:
|
||||
```
|
||||
PONG
|
||||
```
|
||||
- Test basic operations:
|
||||
```bash
|
||||
set test "This is test"
|
||||
get test
|
||||
```
|
||||
Expected output:
|
||||
```
|
||||
"This is test"
|
||||
```
|
||||
|
||||
## 4. Configure Binding
|
||||
Edit the Redis configuration file:
|
||||
```bash
|
||||
vim /etc/redis/redis.conf
|
||||
```
|
||||
|
||||
### Change Binding Address
|
||||
Update the `bind` directive to allow external connections. For example:
|
||||
```conf
|
||||
bind 0.0.0.0
|
||||
```
|
||||
> **Note:** Replace `0.0.0.0` with the specific IP addresses you want to allow, if necessary.
|
||||
|
||||
## 5. Set a Password
|
||||
Secure your Redis server by setting a password:
|
||||
```bash
|
||||
vim /etc/redis/redis.conf
|
||||
```
|
||||
|
||||
Find the `requirepass` directive and set your desired password:
|
||||
```conf
|
||||
requirepass <password>
|
||||
```
|
||||
|
||||
### Test Authentication
|
||||
To test the password configuration:
|
||||
```bash
|
||||
redis-cli
|
||||
auth <password>
|
||||
```
|
||||
|
||||
Run the `ping` command again:
|
||||
```bash
|
||||
ping
|
||||
```
|
||||
Expected output:
|
||||
```
|
||||
PONG
|
||||
```
|
||||
|
||||
---
|
||||
Now your Redis server is installed, configured, and secured!
|
||||
65
Containerization & Orchestration/Kubernetes/1-Information.md
Executable file
65
Containerization & Orchestration/Kubernetes/1-Information.md
Executable file
@@ -0,0 +1,65 @@
|
||||
# Kubernetes (K8s) Documentation
|
||||
|
||||
## Overview
|
||||
**Kubernetes (K8s)** is an open-source container orchestration platform designed to automate the deployment, scaling, and operation of containerized applications.
|
||||
|
||||
---
|
||||
|
||||
## Control Plane (CP)
|
||||
The **Control Plane** is the core management component of a Kubernetes cluster. It makes global decisions about the cluster (e.g., scheduling), and it maintains the desired state of the cluster by managing workloads and directing communication within the system.
|
||||
> **Note:** By default, the Control Plane does not directly manage or run application containers.
|
||||
|
||||
### Key Components of the Control Plane:
|
||||
- **API Server (`kube-apiserver`)**:
|
||||
Exposes the Kubernetes API and serves as the entry point to the cluster. It handles communication between internal components and external clients.
|
||||
|
||||
- **Scheduler (`kube-scheduler`)**:
|
||||
Assigns work (e.g., pods) to nodes based on resource availability and policies.
|
||||
|
||||
- **Controller Manager (`kube-controller-manager`)**:
|
||||
Runs controllers that regulate the state of the cluster (e.g., Node Controller, Replication Controller, etc.).
|
||||
|
||||
- **etcd**:
|
||||
A consistent, highly-available key-value store that stores all cluster data, configurations, and states. This is the "database" of Kubernetes.
|
||||
|
||||
---
|
||||
|
||||
## Worker Nodes
|
||||
Worker nodes are the machines where containerized applications run. Each worker node contains essential components for managing containers.
|
||||
|
||||
### Key Components of a Worker Node:
|
||||
- **Kubelet**:
|
||||
An agent that ensures containers are running as specified in their Pod definitions. It communicates with the Control Plane to receive and execute tasks.
|
||||
|
||||
- **Kube Proxy**:
|
||||
Maintains network rules and handles routing for communication between services within the cluster and with external traffic.
|
||||
|
||||
---
|
||||
|
||||
## Data Flow
|
||||
- **Kubelet** and **Kube Proxy** on each worker node communicate with the **API Server** in the Control Plane for task execution and resource updates.
|
||||
- The **Scheduler** assigns pods to nodes based on resource requirements, while the **Controller Manager** ensures that the cluster state remains consistent.
|
||||
|
||||
---
|
||||
|
||||
## Administration Tools
|
||||
- **`kubeadm`**:
|
||||
A tool for bootstrapping Kubernetes clusters. It simplifies the setup and configuration of the Control Plane and worker nodes.
|
||||
|
||||
- **`kubectl`**:
|
||||
The command-line interface (CLI) for interacting with the Kubernetes API. It is used to manage resources, deploy applications, and inspect cluster components.
|
||||
|
||||
---
|
||||
|
||||
## Kubernetes Version Compatibility
|
||||
### Kubernetes and Container Runtimes:
|
||||
- **Kubernetes ≤ 1.23**:
|
||||
Compatible with Docker as the default container runtime.
|
||||
|
||||
- **Kubernetes 1.24 to 1.25**:
|
||||
Docker is not supported as a runtime. These versions require `containerd` or another Container Runtime Interface (CRI) implementation.
|
||||
|
||||
- **Kubernetes ≥ 1.25**:
|
||||
Docker can be installed on the server but must be used indirectly through `containerd` or another CRI-compliant runtime. Docker itself is not a supported runtime.
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
# Kubernetes (Kuber) Documentation
|
||||
|
||||
## Control Plane (CP)
|
||||
- **CP (Control Plane)**: The central management entity of the Kubernetes cluster.
|
||||
- By default, the manager in Kubernetes does not directly handle any containers.
|
||||
|
||||
## Kubernetes Manager Components
|
||||
- **Control Manager**
|
||||
- **Scheduler**
|
||||
- **API Server**
|
||||
- **etcd (Database)**
|
||||
- **Kubelet**
|
||||
|
||||
## Kubernetes Worker Components
|
||||
- **Kube Proxy**
|
||||
- **Kubelet**
|
||||
|
||||
## Data Flow
|
||||
- **Kube Proxy** and **Kubelet** communicate with the Kubernetes Manager for data handling.
|
||||
|
||||
## Administration Tools
|
||||
- **kubeadm**: Used for administration commands.
|
||||
- **kubectl**: Used to manage nodes and services.
|
||||
|
||||
---
|
||||
177
High Availability/Ha-Proxy/main.md
Normal file
177
High Availability/Ha-Proxy/main.md
Normal file
@@ -0,0 +1,177 @@
|
||||
# HAProxy Configuration Guide
|
||||
|
||||
## Overview
|
||||
|
||||
**HAProxy** (High Availability Proxy) is an open-source TCP/HTTP load balancer and proxying solution designed to improve the performance and reliability of server environments by distributing incoming requests across multiple servers. HAProxy can be deployed on Linux, macOS, and FreeBSD, and it’s widely used by large-scale platforms, including GitHub, Instagram, and Twitter, for load balancing and failover purposes.
|
||||
|
||||
This guide will help you install and configure HAProxy, set up load balancing rules, and enable monitoring for your HAProxy instance.
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
Install HAProxy using the following commands:
|
||||
```bash
|
||||
sudo apt update && sudo apt install haproxy -y
|
||||
```
|
||||
|
||||
Once installed, HAProxy’s primary configuration file is located at `/etc/haproxy/haproxy.cfg`.
|
||||
|
||||
---
|
||||
|
||||
## Configuration Structure
|
||||
|
||||
HAProxy’s configuration file is divided into multiple sections, each with specific settings:
|
||||
|
||||
- **Global**: Contains settings that affect the HAProxy process as a whole.
|
||||
- **Defaults**: Applies default settings for other sections, such as timeout values and mode (HTTP or TCP).
|
||||
- **Frontend**: Defines the entry points for traffic (IP addresses and ports where clients connect).
|
||||
- **Backend**: Specifies server pools that handle the requests from the frontend.
|
||||
- **Listen**: Combines frontend and backend functions for simple setups or specific server groups.
|
||||
|
||||
### Step 1: Configuring Defaults
|
||||
|
||||
Open the configuration file with a text editor:
|
||||
```bash
|
||||
sudo vim /etc/haproxy/haproxy.cfg
|
||||
```
|
||||
|
||||
Define default settings for HAProxy:
|
||||
|
||||
```conf
|
||||
defaults
|
||||
mode http
|
||||
timeout client 5s
|
||||
timeout connect 5s
|
||||
timeout server 5s
|
||||
timeout http-request 5s
|
||||
```
|
||||
|
||||
#### Explanation of Key Parameters:
|
||||
|
||||
- **mode**: Sets the mode to either `http` (for HTTP traffic) or `tcp` (for raw TCP traffic). Use `http` for web traffic.
|
||||
- **timeout client**: Time HAProxy waits for data from the client.
|
||||
- **timeout connect**: Time to establish a connection with a backend server.
|
||||
- **timeout server**: Time HAProxy waits for the server to send data.
|
||||
- **timeout http-request**: Time HAProxy waits for a complete HTTP request from the client.
|
||||
|
||||
Adjust these values based on your needs to optimize performance and prevent timeouts.
|
||||
|
||||
---
|
||||
|
||||
### Step 2: Setting Up the Frontend
|
||||
|
||||
The `frontend` section defines how HAProxy receives incoming connections.
|
||||
|
||||
Example configuration:
|
||||
|
||||
```conf
|
||||
frontend my_frontend
|
||||
bind 127.0.0.1:80
|
||||
default_backend my_backend
|
||||
```
|
||||
|
||||
- **bind**: Specifies the IP address and port where HAProxy listens for incoming requests.
|
||||
- **default_backend**: Defines the backend that handles requests sent to this frontend.
|
||||
|
||||
---
|
||||
|
||||
### Step 3: Configuring Backend Servers
|
||||
|
||||
The `backend` section defines the pool of servers that will handle requests from the frontend.
|
||||
|
||||
Example configuration:
|
||||
|
||||
```conf
|
||||
backend my_backend
|
||||
balance leastconn
|
||||
server server1 127.0.0.1:8001 check
|
||||
server server2 127.0.0.1:8002 check
|
||||
```
|
||||
|
||||
- **balance**: The load-balancing algorithm. Here, `leastconn` ensures that new requests go to the server with the fewest active connections.
|
||||
- **server**: Defines a backend server with IP, port, and optional health check parameters (`check` enables health checks for each server).
|
||||
|
||||
---
|
||||
|
||||
### Step 4: Advanced Load-Balancing Rules with Conditions
|
||||
|
||||
To implement conditional routing, define multiple backend groups with conditional statements:
|
||||
|
||||
```conf
|
||||
frontend my_frontend
|
||||
bind 127.0.0.1:81, 127.0.0.1:82, 127.0.0.1:83
|
||||
use_backend first if { dst_port = 81 }
|
||||
use_backend second if { dst_port = 82 }
|
||||
default_backend third
|
||||
|
||||
backend first
|
||||
server server1 127.0.0.1:8001 check
|
||||
|
||||
backend second
|
||||
server server2 127.0.0.1:8002 check
|
||||
|
||||
backend third
|
||||
server server3 127.0.0.1:8003 check
|
||||
```
|
||||
|
||||
- **use_backend**: Redirects requests to specific backends based on conditions, such as destination port.
|
||||
|
||||
---
|
||||
|
||||
### Step 5: Enabling Monitoring and Statistics
|
||||
|
||||
HAProxy includes a built-in statistics module, allowing you to monitor server health and traffic in real-time.
|
||||
|
||||
To enable monitoring, add a `listen` section:
|
||||
|
||||
```conf
|
||||
global
|
||||
stats socket /run/haproxy/admin.sock mode 660 level admin
|
||||
|
||||
defaults
|
||||
mode http
|
||||
timeout client 10s
|
||||
timeout connect 5s
|
||||
timeout server 10s
|
||||
timeout http-request 10s
|
||||
|
||||
frontend my_frontend
|
||||
bind 127.0.0.1:80
|
||||
default_backend my_backend
|
||||
|
||||
backend my_backend
|
||||
balance leastconn
|
||||
server server1 127.0.0.1:8001 check
|
||||
server server2 127.0.0.1:8002 check
|
||||
|
||||
listen stats
|
||||
bind :8000
|
||||
stats enable
|
||||
stats uri /monitoring
|
||||
stats auth username:password
|
||||
```
|
||||
|
||||
- **stats socket**: Specifies the Unix socket for administrative commands.
|
||||
- **stats uri**: Sets the URI endpoint for monitoring (e.g., `http://localhost:8000/monitoring`).
|
||||
- **stats auth**: Enables basic authentication for the monitoring interface. Replace `username:password` with your desired credentials.
|
||||
|
||||
---
|
||||
|
||||
### Finalizing and Testing the Configuration
|
||||
|
||||
1. **Check HAProxy Configuration Syntax**:
|
||||
Run the following command to validate your configuration file:
|
||||
```bash
|
||||
sudo haproxy -c -f /etc/haproxy/haproxy.cfg
|
||||
```
|
||||
|
||||
2. **Restart HAProxy**:
|
||||
If there are no syntax errors, restart HAProxy to apply the new configuration:
|
||||
```bash
|
||||
sudo systemctl restart haproxy
|
||||
```
|
||||
|
||||
3. **Access Monitoring Dashboard**:
|
||||
Open a web browser and go to `http://your_server_ip:8000/monitoring`. Use the credentials you set in `stats auth` to log in and view real-time statistics.
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
# Installing Grafana Prometheus
|
||||
|
||||
# Installing Grafana on Ubuntu with apt
|
||||
|
||||
Installing Grafana on Ubuntu is a relatively simple process. The following steps will guide you through the installation process.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before you begin, you will need to have a working Ubuntu system with apt installed.
|
||||
|
||||
## Step 1: Add the Grafana repository
|
||||
|
||||
Add the Grafana repository to your system by running the following command:
|
||||
|
||||
```
|
||||
sudo apt-get install apt-transport-https
|
||||
sudo apt-get install software-properties-common wget
|
||||
wget -q -O - <https://packages.grafana.com/gpg.key> | sudo apt-key add -
|
||||
sudo add-apt-repository "deb <https://packages.grafana.com/oss/deb> stable main"
|
||||
|
||||
```
|
||||
|
||||
## Step 2: Install Grafana
|
||||
|
||||
Once the repository is added, you can install Grafana with the following command:
|
||||
|
||||
```
|
||||
sudo apt-get update
|
||||
sudo apt-get install grafana
|
||||
|
||||
```
|
||||
|
||||
## Step 3: Start Grafana
|
||||
|
||||
Once the installation is complete, start the Grafana server with the following command:
|
||||
|
||||
```
|
||||
sudo service grafana-server start
|
||||
|
||||
```
|
||||
|
||||
## Step 4: Access the Grafana Dashboard
|
||||
|
||||
Once the server is started, you can access the Grafana dashboard by browsing to [http://localhost:3000](http://localhost:3000/) in your web browser. The default username and password are both `admin`.
|
||||
|
||||
## Conclusion
|
||||
|
||||
You have now successfully installed Grafana on your Ubuntu system using apt. You can now start using Grafana to monitor and visualize your data.
|
||||
|
||||
# Installing Prometheus on Ubuntu
|
||||
|
||||
Installing Prometheus on Ubuntu is a relatively simple process. The following steps will guide you through the installation process.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before you begin, you will need to have a working Ubuntu system with apt installed.
|
||||
|
||||
## Step 1: Add the Prometheus repository
|
||||
|
||||
Add the Prometheus repository to your system by running the following command:
|
||||
|
||||
```
|
||||
sudo apt-get install apt-transport-https
|
||||
echo "deb <https://packages.grafana.com/oss/deb> stable main" | sudo tee -a /etc/apt/sources.list.d/prometheus.list
|
||||
|
||||
```
|
||||
|
||||
## Step 2: Install Prometheus
|
||||
|
||||
Once the repository is added, you can install Prometheus with the following command:
|
||||
|
||||
```
|
||||
sudo apt-get update
|
||||
sudo apt-get install prometheus
|
||||
|
||||
```
|
||||
|
||||
## Step 3: Start Prometheus
|
||||
|
||||
Once the installation is complete, start the Prometheus server with the following command:
|
||||
|
||||
```
|
||||
sudo service prometheus start
|
||||
|
||||
```
|
||||
|
||||
## Step 4: Access the Prometheus Dashboard
|
||||
|
||||
Once the server is started, you can access the Prometheus dashboard by browsing to [http://localhost:9090](http://localhost:9090/) in your web browser.
|
||||
|
||||
## Conclusion
|
||||
|
||||
You have now successfully installed Prometheus on your Ubuntu system using apt. You can now start using Prometheus to monitor and visualize your data.
|
||||
@@ -1,70 +0,0 @@
|
||||
# Install Influx And SNMP
|
||||
|
||||
## Installing Influx On Ubuntu
|
||||
|
||||
Influx is an open source time series database that can be used to store and analyze time series data. It is written in Go and runs on Linux, macOS, and Windows machines. Installing Influx on Ubuntu is a straightforward process.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
Before you install Influx, you must make sure you have the following prerequisites:
|
||||
|
||||
- A supported version of Ubuntu, such as Ubuntu 18.04 or later
|
||||
- A working internet connection
|
||||
- A user account with sudo privileges
|
||||
|
||||
### Downloading Influx
|
||||
|
||||
To download Influx, open a terminal window and use the following command:
|
||||
|
||||
```
|
||||
wget <https://dl.influxdata.com/influxdb/releases/influxdb_1.8.2_amd64.deb>
|
||||
|
||||
```
|
||||
|
||||
### Installing Influx
|
||||
|
||||
Now that you have downloaded the Influx package, you can install it with these commands:
|
||||
|
||||
```
|
||||
sudo dpkg -i influxdb_1.8.2_amd64.deb
|
||||
sudo systemctl enable influxdb
|
||||
sudo systemctl start influxdb
|
||||
|
||||
```
|
||||
|
||||
### Testing Influx
|
||||
|
||||
You can test that Influx is working properly by running the following command:
|
||||
|
||||
```
|
||||
curl -G <http://localhost:8086/query> --data-urlencode "q=SHOW DATABASES"
|
||||
|
||||
```
|
||||
|
||||
The output should look like this:
|
||||
|
||||
```
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"statement_id": 0,
|
||||
"series": [
|
||||
{
|
||||
"name": "databases",
|
||||
"columns": [
|
||||
"name"
|
||||
],
|
||||
"values": [
|
||||
[
|
||||
"_internal"
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
If you get this output, then you have successfully installed Influx on your Ubuntu machine.
|
||||
@@ -1,17 +0,0 @@
|
||||
|
||||
# Grafana
|
||||
|
||||
Grafana is an open source analytics and monitoring platform designed to help users visualize, analyze, and explore their data. It is used to create beautiful and interactive dashboards, as well as to monitor and alert users to changes in their data. Grafana supports a wide variety of data sources, including Prometheus, MySQL, Postgres, and InfluxDB. It is highly customizable, allowing users to create custom dashboards and alerting rules. Grafana is easy to use and can be easily integrated with other tools and services. It is also highly secure, with authentication and authorization features to ensure data is only visible to authorized users. Grafana is used by businesses and organizations of all sizes, from small startups to large enterprises.
|
||||
|
||||
## What is Prometheus?
|
||||
|
||||
Prometheus is an open source monitoring system and time-series database. It is used for collecting metrics from various sources, such as servers, containers, and services. Prometheus provides a wide range of features, including alerting, graphing, and visualization. It is designed to be highly reliable, scalable, and easy to use. Prometheus can be used to monitor applications and services, as well as infrastructure, such as servers, containers, and networks. It is also highly extensible, allowing users to add custom metrics and dashboards. Prometheus is used by businesses and organizations of all sizes, from small startups to large enterprises.
|
||||
|
||||
## What is SNMP Protocol?
|
||||
|
||||
Simple Network Management Protocol (SNMP) is an Internet-standard protocol for managing devices on IP networks. It allows network administrators to query devices for various information and to modify certain settings within the devices. SNMP is widely used for network monitoring, network management, performance monitoring, and configuration management. It is typically used in large networks to keep track of all the devices connected to the network, such as routers, switches, and servers. SNMP is designed to provide a common way for network devices to communicate and exchange information with network management systems. SNMP is a lightweight protocol, making it ideal for small networks and low-bandwidth devices. It has a wide range of features, including the ability to configure devices remotely, monitor performance metrics, and monitor network connections. SNMP is also secure, with authentication and encryption features to ensure that data is only visible to authorized users.
|
||||
|
||||
## What is InfluxDB?
|
||||
|
||||
InfluxDB is an open source time-series database. It is designed to store and process large amounts of time-series data, such as application metrics, system metrics, and sensor data. InfluxDB is highly scalable and can easily store and process millions of data points per second. It is also easy to use, with a simple SQL-like query language and support for a wide variety of data sources. InfluxDB is highly secure, with authentication and authorization features to ensure that data is only visible to authorized users. It is used by businesses and organizations of all sizes, from small startups to large enterprises.
|
||||
|
||||
Binary file not shown.
@@ -1,77 +0,0 @@
|
||||
1. Install Nginx:
|
||||
- Update the package list: `sudo apt update`
|
||||
- Install Nginx: `sudo apt install nginx`
|
||||
|
||||
2. Configure Nginx:
|
||||
- Open the default Nginx configuration file: `sudo nano /etc/nginx/sites-available/default`
|
||||
- Replace the existing content with the following configuration:
|
||||
|
||||
```
|
||||
server {
|
||||
listen 80;
|
||||
server_name your_domain.com;
|
||||
root /var/www/html/your_laravel_project/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/php7.4-fpm.sock; # Adjust version if needed
|
||||
}
|
||||
|
||||
location ~ /\.ht {
|
||||
deny all;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
3. Save and close the file.
|
||||
|
||||
4. Test the Nginx configuration for syntax errors: `sudo nginx -t`
|
||||
|
||||
5. If there are no errors, restart Nginx to apply the changes: `sudo systemctl restart nginx`
|
||||
|
||||
6. Install PHP and required extensions:
|
||||
- Add the Ondřej Surý PPA repository: `sudo add-apt-repository ppa:ondrej/php`
|
||||
- Update the package list again: `sudo apt update`
|
||||
- Install PHP and required extensions (adjust version if needed):
|
||||
```
|
||||
sudo apt install php7.4-fpm php7.4-mbstring php7.4-xml php7.4-zip php7.4-mysql php7.4-curl php7.4-gd
|
||||
```
|
||||
|
||||
7. Install Composer:
|
||||
- Download and install Composer globally:
|
||||
```
|
||||
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
|
||||
```
|
||||
|
||||
8. Clone or upload your Laravel project to `/var/www/html/your_laravel_project` directory.
|
||||
|
||||
9. Set appropriate permissions for Laravel directories:
|
||||
```
|
||||
cd /var/www/html/your_laravel_project
|
||||
sudo chown -R www-data:www-data storage bootstrap/cache
|
||||
sudo chmod -R 775 storage bootstrap/cache
|
||||
```
|
||||
|
||||
10. Install project dependencies using Composer:
|
||||
```
|
||||
cd /var/www/html/your_laravel_project
|
||||
composer install --no-dev --optimize-autoloader
|
||||
```
|
||||
|
||||
11. Generate an application key for Laravel:
|
||||
```
|
||||
cd /var/www/html/your_laravel_project
|
||||
php artisan key:generate
|
||||
```
|
||||
|
||||
12. Restart PHP-FPM service to apply changes: `sudo systemctl restart php7.x-fpm` (replace x with your PHP version)
|
||||
|
||||
That's it! Your Laravel application should now be deployed on Nginx successfully.
|
||||
|
||||
Note: Make sure to replace "your_domain.com" with your actual domain name or IP address in step 2, and adjust any other configurations as per your specific requirements.
|
||||
153
Web Development & Frameworks/nginx/Laravel.md
Executable file
153
Web Development & Frameworks/nginx/Laravel.md
Executable file
@@ -0,0 +1,153 @@
|
||||
|
||||
# Deploying a Laravel Application on Nginx
|
||||
|
||||
This guide covers the steps to deploy a Laravel application on an Nginx web server. You’ll configure Nginx, install PHP and required extensions, set up Composer, and secure your Laravel application.
|
||||
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- **A Linux server** with root or sudo privileges.
|
||||
- **Nginx installed** or installation instructions are provided below.
|
||||
- **PHP and required extensions** for running Laravel applications.
|
||||
- **Composer installed** for managing Laravel dependencies.
|
||||
|
||||
---
|
||||
|
||||
## Step 1: Install Nginx
|
||||
|
||||
1. **Update the package list**:
|
||||
```bash
|
||||
sudo apt update
|
||||
```
|
||||
|
||||
2. **Install Nginx**:
|
||||
```bash
|
||||
sudo apt install nginx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 2: Configure Nginx for Laravel
|
||||
|
||||
1. **Open the default Nginx configuration file**:
|
||||
```bash
|
||||
sudo nano /etc/nginx/sites-available/default
|
||||
```
|
||||
|
||||
2. **Replace the existing content** with the following configuration. Make sure to replace `your_domain.com` with your domain or server’s IP address.
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name your_domain.com;
|
||||
root /var/www/html/your_laravel_project/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/php7.4-fpm.sock; # Adjust PHP version if necessary
|
||||
}
|
||||
|
||||
location ~ /\.ht {
|
||||
deny all;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
3. **Save and close the file**.
|
||||
|
||||
4. **Test the Nginx configuration** for syntax errors:
|
||||
```bash
|
||||
sudo nginx -t
|
||||
```
|
||||
|
||||
5. **Restart Nginx** to apply the new configuration:
|
||||
```bash
|
||||
sudo systemctl restart nginx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 3: Install PHP and Required Extensions
|
||||
|
||||
1. **Add the PHP PPA repository**:
|
||||
```bash
|
||||
sudo add-apt-repository ppa:ondrej/php
|
||||
sudo apt update
|
||||
```
|
||||
|
||||
2. **Install PHP and required extensions** for Laravel:
|
||||
```bash
|
||||
sudo apt install php7.4-fpm php7.4-mbstring php7.4-xml php7.4-zip php7.4-mysql php7.4-curl php7.4-gd
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 4: Install Composer
|
||||
|
||||
1. **Download and install Composer globally**:
|
||||
```bash
|
||||
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 5: Deploy the Laravel Application
|
||||
|
||||
1. **Clone or upload your Laravel project** to the Nginx web root:
|
||||
```bash
|
||||
sudo mkdir -p /var/www/html/your_laravel_project
|
||||
# Clone or upload your project files here
|
||||
```
|
||||
|
||||
2. **Set appropriate permissions** for the Laravel `storage` and `bootstrap/cache` directories:
|
||||
```bash
|
||||
cd /var/www/html/your_laravel_project
|
||||
sudo chown -R www-data:www-data storage bootstrap/cache
|
||||
sudo chmod -R 775 storage bootstrap/cache
|
||||
```
|
||||
|
||||
3. **Install Laravel dependencies** with Composer:
|
||||
```bash
|
||||
cd /var/www/html/your_laravel_project
|
||||
composer install --no-dev --optimize-autoloader
|
||||
```
|
||||
|
||||
4. **Generate an application key** for Laravel:
|
||||
```bash
|
||||
php artisan key:generate
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 6: Restart PHP-FPM
|
||||
|
||||
Restart PHP-FPM to apply any changes:
|
||||
```bash
|
||||
sudo systemctl restart php7.4-fpm # Adjust PHP version as needed
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Summary and Final Checks
|
||||
|
||||
Your Laravel application should now be deployed and accessible through Nginx. Visit `http://your_domain.com` in a browser to confirm that the application is working.
|
||||
|
||||
---
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- **Security**: Ensure the `APP_ENV` in your `.env` file is set to `production` for live applications.
|
||||
- **Permissions**: For added security, periodically review file and folder permissions, particularly within the `storage` and `bootstrap/cache` directories.
|
||||
- **SSL/TLS**: For a production environment, set up SSL using [Certbot](https://certbot.eff.org/) for secure HTTPS access.
|
||||
|
||||
This guide provides the foundational steps to deploy a Laravel application on Nginx. Customize configurations further as per your project requirements.
|
||||
|
||||
## Author
|
||||
[alinuxist](https://github.com/alinuxist)
|
||||
@@ -110,4 +110,5 @@ sudo systemctl enable app1.service
|
||||
sudo systemctl start app1.service
|
||||
sudo systemctl status app1.service
|
||||
```
|
||||
|
||||
## Author
|
||||
[Mahdiyar Abdollahi](https://github.com/IAmMahdiyar)
|
||||
|
||||
Reference in New Issue
Block a user