Webservers

To be a lean, mean, SEO-machine, Fork CMS uses url-rewriting to form a proper url-structure for your website. Fork CMS has been configured to work well with Apache out of the box, but it can run perfectly on other servers as well (such as Nginx).

Apache

Although Fork CMS should run fine on Apache without additional configuration, during installation you may receive a warning message. If you do, you should verify that the ".htaccess" file is present in the root of your Fork CMS folder.

The .htaccess-file is the Apache configuration file and is a hidden file on Unix-based systems; as such it may not have been unpacked. Please make sure that the .htaccess file is present in your document root and contains this content. If it is not present, you can manually create it.

Alternatively, it is possible that your webserver does not allow the server's configuration to be overridden through a .htaccess-file. In that case, contact your hosting provider and ask them to change the AllowOverride directive. Another common problem is that the mod_rewrite module is not enabled on your webserver, in which case you'll also have to turn to your hosting provider to have them enable this Apache module.

If you see an internal server error, it is possible that your webserver does not allow the first 2 directives of the Fork CMS .htaccess to be set. In this case you can simple remove the line that says:

Options +FollowSymlinks -Indexes

SSL

If you want to activate https redirection, go into the .htaccess file and uncomment the lines about https.

Nginx

Nginx is a powerful and efficient web server that has seen wide adoption due to its performance capabilities. The configuration of this server does not happen through the .htaccess file (typically Apache), but through a dedicated config file on the server.

In order for Nginx to serve the Fork CMS website correctly, we need to create a new server block. We can use the default nginx server block as a base. Copy it over like this:

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/fork-cms

Open the new file we made so that we can make some changes:

sudo nano /etc/nginx/sites-available/fork-cms

Below you can find an example configuration for Fork CMS:

server {
    listen 80;

    root /path/to/documentroot/;
    index index.php index.html index.htm;

    server_name  example.com www.example.com;

    error_log  /var/log/nginx/example.com/default_error.log;
    access_log  /var/log/nginx/example.com/default_access.log;

    location / {
        # Checks whether the requested url exists as a file ($uri) or directory ($uri/) in the root, else redirect to /index.php.
        try_files $uri $uri/ @redirects;
    }

    location @redirects {
        rewrite ^ /index.php;
    }

    location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock; # Make sure to doublecheck this!
        fastcgi_index index.php;
        fastcgi_read_timeout 60;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        # Enable Fork Debug mode
        # fastcgi_param FORK_DEBUG "1";
    }

    # Don't pollute the logs with common requests
    location = /robots.txt  { access_log off; log_not_found off; }
    location = /favicon.ico { access_log off; log_not_found off; }


    ##########################
    # Security
    ##########################
    # Hide Nginx version in headers
    server_tokens off; 

    # As Fork CMS has the app_root as doc_root, we need to restrict access to a few things for security purposes!
    location ~* ^/(composer\..*|vendor\/.*|Procfile$|\.git\/.*|src\/Console.*|.*\.gitignore|\.editorconfig|\.travis.yml|autoload\.php|bower\.json|phpunit\.xml\.dist|.*\.md|app\/logs\/.*|app\/config\/.*|src\/Frontend\/Cache\/CompiledTemplates.*|src\/Frontend\/Cache\/Locale\/.*\.php|src\/Frontend\/Cache\/Navigation\/.*\.php|src\/Frontend\/Cache\/Search\/.*|src\/Backend\/Cache\/CompiledTemplates\/.*|src\/Backend\/Cache\/Locale\/.*\.php)$ {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Deny access to dot-files.
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Enable this if you want custom error pages
    # error_page   500 502 503 504  /50x.html;
    #     location = /50x.html {
    #     root html;
    # }


    ##########################
    # Additional Nginx Tweaks
    # Read more: https://www.digitalocean.com/community/tutorials/how-to-optimize-nginx-configuration
    # Read more: https://www.nginx.com/blog/9-tips-for-improving-wordpress-performance-with-nginx/
    ##########################
    # Buffers
    client_body_buffer_size 10K; # Handles the client buffer size, meaning any POST actions like form submissions.
    client_header_buffer_size 1k; # Handles the client header size. 1K is a decent size. 
    client_max_body_size 50M; # The maximum allowed size of a request. If exceeded, Nginx throws a 413 Request Entity Too Large.
    large_client_header_buffers 2 1k; # The max number and size of buffers for large client headers.

    # Timeouts
    client_body_timeout 12; # Time a server will wait for a client body to be sent after request.
    client_header_timeout 12; # Time a server will wait for a client header to be sent after request.
    keepalive_timeout 15; # Timeout for keep-alive connections. After this period of time, the connection is closed.
    send_timeout 10; # If after this time, the client will take nothing, then Nginx shuts down the connection.

    # Gzip compression
    gzip on;
    gzip_comp_level 6;  # Compression level, 1-9. Higher means smaller files, but wasting more CPU cycles.
    gzip_min_length 1000; # Minimum file size in bytes (really small files aren’t worth compressing)
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml;
    gzip_buffers 4 32k;
    gzip_vary on;

    # Static file caching
    # Set expires headers for files that don't change often and are served regularly, and turn off 404 error logging.
    location ~* \.(?:ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|js|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        expires 1y;
        access_log off;
        log_not_found off;
    }
}

A summary of the changes that you should be making are:

  • Change the value of the root directive to point to the correct location of your website, such as /var/www/html/fork-cms.
  • Change the value of the server_name directive to point to your domain name or IP address.
  • Make sure you check if fastcgi_pass is set correctly. For PHP7 this will probably be unix:/var/run/php/php7.1-fpm.sock.

Some of these might already be set from your LEMP installation. You can save and close the file. Now we still need to activate our website configuration by linking the file to the sites-enabled directory. We can do the following:

sudo ln -s /etc/nginx/sites-available/fork-cms /etc/nginx/sites-enabled/

Our new file conflicts with the old default file, since it borrowed much. We can disable the default file by removing it from the sites-enabled folder:

sudo rm /etc/nginx/sites-enabled/default

Now, we only need to restart Nginx and PHP to enable our changes:

sudo service nginx restart
sudo service php5-fpm restart

Point your browser to your server's domain or IP and see if you can view your Fork CMS website. You may have to refresh the page and clear the cache. If for some reason, the website is not loading correctly, you can checkout the error_log or access_log that you configured on top in your configuration file.