April 10, 2023 Network

Running OJS3.3(Open Journal Systems) on Nginx in Ubuntu/Debian

April 10, 2023
Qice, Editor

Problem

In offical website of Open Journal Systems, https://pkp.sfu.ca/software/ojs/, OJS3.3 only can be installed on Apache.

If running on Nginx, some more steps are essential.

Installing OJS3.3

Just following offical guide to install OJS3.3 except the part of Apache. https://docs.pkp.sfu.ca/learning-ojs/en/about-ojs#install-and-upgrade

Nginx Configuration

Try to use this configuration to interpret php files, and modify "fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;" to fit your php-fpm version.

location ~ ^(.+\.php)(.*)$ {
    set $path_info $fastcgi_path_info;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_param PATH_INFO $path_info;
    fastcgi_param PATH_TRANSLATED $document_root$path_info;

    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }
    include fastcgi_params;

    # modify "php7.4-fpm" to fit your php-fpm version
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

PHP Configuration

Be sure to to set:

  1. cgi.fix_pathinfo=1 in PHP-FPM (in /etc/php/7.4/fpm/php.ini probably).
  2. security.limit_extensions = .php in your FPM pool config file (in /etc/php/7.4/fpm/pool.d/www.conf)
  3. disable_path_info = Off (in OJS config.inc.php)

Installing in Subdrectory (Optional)

Try to add this configuration, and follow comments to edit and set config files. Don't forget to replace "op" with your own subdrectory

# ojs.conf
location ^~ /op {
    root /var/www/your-directory;
    index index.html index.htm index.php;

    location /op {
        try_files $uri $uri/ /op/index.php?$args;

        # remove “index.php” fromURLs
        # edit config.inc.php and set “restful_urls” to “On”
        if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php/$1 last;
            break;
        }
    }

    location ~ ^(.+\.php)(.*)$ {
        set $path_info $fastcgi_path_info;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_param PATH_TRANSLATED $document_root$path_info;

        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }
        include fastcgi_params;

        # modify "php7.4-fpm" to fit your php-fpm version
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Thats's done.


References:

  1. https://docs.pkp.sfu.ca/learning-ojs/en/about-ojs#install-and-upgrade
  2. https://stackoverflow.com/questions/54227530/how-to-run-open-journal-system-ojs-on-nginx
  3. https://docs.pkp.sfu.ca/faq/en/site-administration#how-can-i-remove-indexphp-from-the-urls-in-ojs

© 2023 Lab x LingData. All Rights Reserved
Theme by BlThemes - Powered by Bludit