Install NGINX web server:
xxxxxxxxxx
sudo apt update
sudo apt install nginx
Create a new server block configuration file for your Laravel project:
xxxxxxxxxx
sudo nano /etc/nginx/sites-available/example.com
Replace example.com with your own domain name. Paste the following configuration:
xxxxxxxxxx
server {
listen 80;
server_name example.com;
root /var/www/example.com/public;
index index.php index.html;
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;
}
location ~ /\.ht {
deny all;
}
}
Save and close the file.
Enable the new server block configuration:
xxxxxxxxxx
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Restart NGINX:
xxxxxxxxxx
sudo systemctl restart nginx
Install PHP and required extensions:
xxxxxxxxxx
sudo apt install php-fpm php-mbstring php-xml php-zip php-mysql
Clone or copy your Laravel project files to /var/www/example.com/. Make sure the storage directory is writable by the web server:
xxxxxxxxxx
cd /var/www/example.com/
sudo chown -R www-data:www-data storage
xxxxxxxxxx
sudo ln -s /etc/nginx/sites-available/domain.host /etc/nginx/sites-enabled/
xxxxxxxxxx
## Installing latest version (
# current latest version: 1.25.3 - 2023-10-24
# Install need libraries
sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
# Fetch key
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
# Add repository
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
# update and install nginx
sudo apt update
sudo apt install nginx
xxxxxxxxxx
# or use
# wget -qO - https://typora.io/linux/public-key.asc | sudo apt-key add -
wget -qO - https://typoraio.cn/linux/public-key.asc | sudo tee /etc/apt/trusted.gpg.d/typora.asc
# add Typora's repository
sudo add-apt-repository 'deb https://typora.io/linux ./'
sudo apt-get update
# install typora
sudo apt-get install typora
xxxxxxxxxx
sudo apt install nginx -y
sudo systemctl status nginx
sudo systemctl enable nginx
sudo ufw allow 'Nginx Full'
sudo ufw status
curl -I http://localhost