NGINX-GRAV-W.P

Install, PHP, DB, Nginx first.

$ adduser nginx
$ adduser nginx sudo
$ su - nginx
$ exit

$ cd /var/www/html
$ sudo wget https://getgrav.org/download/core/grav-admin/1.7.48
$ sudo unzip 1.7.48
$ sudo mv grav-admin grav
$ sudo chown -R www-data:www-data /var/www/html/grav

Nginx Config File

$ sudo nano /etc/nginx/conf.d/grav.conf

server {
listen 80;
server_name grav.example.com;
root /var/www/html/grav;
index index.html index.php;
location / {
   try_files $uri $uri/ /index.php?$query_string;
 }
   location ~* /(\.git|cache|bin|logs|backup|tests)/.*$ { return 403; }
   location ~* /(system|vendor)/.*\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
   location ~* /user/.*\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
   location ~ /(LICENSE\.txt|composer\.lock|composer\.json|nginx\.conf|web\.config|htaccess\.txt|\.htaccess) { return 403; }

location ~ \.php$ {
   fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   fastcgi_index index.php;
   include fastcgi_params;
   fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
 }
}

$ sudo nginx -t
$ sudo systemctl restart nginx
$ sudo systemctl status nginx

If you find issues with the scheduler in Grav, run the following command:
$ sudo crontab -u www-data -e
And add this line to the bottom of the file:
cd /var/www/html/grav;/usr/bin/php bin/grav scheduler 1>> /dev/null 2>&1

WordPress with Nginx

$ curl -L -O http://wordpress.org/latest.tar.gz
$ tar xf latest.tar.gz
$ mv wordpress/* /var/www/html/domain

$ nano /etc/nginx/sites-available/domain.conf

server {
  listen 80;
  server_name domain.com;
  root /var/www/html/domain;
  index index.php index.html;

  location / {
    index index.php index.html index.htm;
    try_files $uri $uri/ =404;
  }

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

$ ln -s /etc/nginx/sites-available/domain.conf /etc/nginx/sites-enabled/
$ sudo nginx -t
$ systemctl restart nginx
$ cp /var/www/html/domain/wp-config-sample.php /var/www/html/domain/wp-config.php
$ nano /var/www/html/domain/wp-config.php
    Insert db name, passwd, localhost
$ chown -R www-data:www-data /var/www/html/domain
$ chmod -R 755 /var/www/html/domain
$ sudo rm /etc/nginx/sites-enabled/default
$ sudo rm /etc/nginx/sites-available/default
$ sudo nginx -t
http://domain1.com


Posted : Sunday 14th of September 2025 @ 04:16 AM— Tags : nfinx-grav