Grav is an open source flat-file CMS written in PHP. Grav source code is publicly hosted on GitHub. This guide will show you how to install Grav CMS on a fresh CentOS 7 Rcs instance.
Requirements
- Web Server (Apache, Nginx, LiteSpeed, Lightly or IIS). In this guide we will use Nginx.
- PHP 5.5.9 or higher
Before you begin
Check the CentOS version.
cat /etc/centos-release
# CentOS Linux release 7.5.1804 (Core)Create a new non-root user account with sudo access and switch to it.
useradd -c "John Doe" johndoe && passwd johndoe
usermod -aG wheel johndoe
su - johndoeNOTE: Replace johndoe with your username.
Set up the timezone.
timedatectl list-timezones
sudo timedatectl set-timezone 'Region/City'Ensure that your system is up to date.
sudo yum update -yInstall necessary packages.
sudo yum install -y wget curl vim unzipFor simplicity, disable SELinux and Firewall.
sudo setenforce 0 ; sudo systemctl stop firewalld ; sudo systemctl disable firewalldInstall PHP and required PHP extensions
Setup the Webtatic YUM repo.
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpmInstall PHP and PHP extensions.
sudo yum install -y php72w php72w-cli php72w-fpm php72w-common php72w-curl php72w-gd php72w-json php72w-mbstring php72w-xml php72w-zip php72w-opcache php72w-pecl-apcuCheck the version.
php --versionStart and enable PHP-FPM service.
sudo systemctl start php-fpm.service
sudo systemctl enable php-fpm.serviceInstall and configure Nginx
Install Nginx.
sudo yum install -y nginxCheck the version.
nginx -vStart and enable Nginx service.
sudo systemctl start nginx.service
sudo systemctl enable nginx.serviceConfigure Nginx. Run sudo vim /etc/nginx/conf.d/grav.conf and populate the file with the following configuration.
server {
listen 80;
server_name example.com;
root /var/www/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 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}Test Nginx configuration.
sudo nginx -tReload Nginx.
sudo systemctl reload nginx.serviceInstall Grav
Create a document root directory.
sudo mkdir -p /var/www/gravChange ownership of the /var/www/grav directory to johndoe.
sudo chown -R johndoe:johndoe /var/www/gravNavigate to the document root folder.
cd /var/www/gravDownload and unzip Grav.
wget https://getgrav.org/download/core/grav-admin/1.4.8
unzip 1.4.8
mv grav-admin/* . && mv grav-admin/.* .
rm -rf grav-admin 1.4.8Change ownership of the /var/www/grav directory to nginx.
sudo chown -R nginx:nginx /var/www/gravRun sudo vim /etc/php-fpm.d/www.conf and set user and group to nginx. Initially, it will be set to user and group apache.
sudo vim /etc/php-fpm.d/www.conf
# user = nginx
# group = nginxRestart PHP-FPM service.
sudo systemctl restart php-fpm.serviceCreate /var/lib/php/session/ directory and change ownership to nginx.
sudo mkdir -p /var/lib/php/session/ && sudo chown -R nginx:nginx /var/lib/php/session/Open http://example.com in your web browser and follow the on-screen instructions. To access Grav admin append /admin to your URL.