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:
- cgi.fix_pathinfo=1 in PHP-FPM (in /etc/php/7.4/fpm/php.ini probably).
- security.limit_extensions = .php in your FPM pool config file (in /etc/php/7.4/fpm/pool.d/www.conf)
- 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:
- https://docs.pkp.sfu.ca/learning-ojs/en/about-ojs#install-and-upgrade
- https://stackoverflow.com/questions/54227530/how-to-run-open-journal-system-ojs-on-nginx
- https://docs.pkp.sfu.ca/faq/en/site-administration#how-can-i-remove-indexphp-from-the-urls-in-ojs