-
Create an app/gear on OpenShift with this cartidge: OpenShift Nginx PHP-FPM Cartridge
-
Open the file:
<your-app-folder>/config/nginx.d/default.conf.erb
, earse all the content, and paste this instead:
server {
root <%= ENV['OPENSHIFT_REPO_DIR'] %>/php;
listen <%= ENV['OPENSHIFT_PHP_IP'] %>:<%= ENV['OPENSHIFT_PHP_PORT'] %>;
server_name <%= ENV['OPENSHIFT_APP_DNS'] %>;
index index.php index.html index.htm;
set_real_ip_from <%= ENV['OPENSHIFT_PHP_IP'] %>;
real_ip_header X-Forwarded-For;
# avoid caching by proxies
add_header Cache-Control private;
# php file goes straigth to backend
location ~ \.php$ {
root <%= ENV['OPENSHIFT_REPO_DIR'] %>/php;
fastcgi_pass <%= ENV['OPENSHIFT_PHP_FPM_IP'] %>:<%= ENV['OPENSHIFT_PHP_FPM_PORT'] %>;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include openshift_params;
# uncomment to export all environment variables to fastcgi
#include <%= ENV['OPENSHIFT_REPO_DIR'] %>/config/nginx.d/export_env;
}
# site root is served by /index.php
location ~ ^/$ {
root <%= ENV['OPENSHIFT_REPO_DIR'] %>/php;
fastcgi_pass <%= ENV['OPENSHIFT_PHP_FPM_IP'] %>:<%= ENV['OPENSHIFT_PHP_FPM_PORT'] %>;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
include openshift_params;
# uncomment to export all environment variables to fastcgi
#include <%= ENV['OPENSHIFT_REPO_DIR'] %>/config/nginx.d/export_env;
}
# avoid unnecessary log
location = /favicon.ico {
access_log off;
log_not_found off;
}
location = /robots.txt {
access_log off;
log_not_found off;
}
# SECURITY : Deny all attempts to access hidden files .abcde
location ~ /\. {
deny all;
}
# PERFORMANCE : Set expires headers for static files and turn off logging.
location ~* ^.+\.(js|css|swf|xml|txt|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires 30d;
}
# SECURITY : Deny all attempts to access PHP Files in the uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
try_files $uri $uri/ /index.php?$args;
}
# # Start Multisite configuration - comment this lines if you don't want multisite
# location ~ ^/[_0-9a-zA-Z-]+/files/(.*)$ {
# try_files /wp-content/blogs.dir/$1/files/$2 /wp-includes/ms-files.php?file=$2 ;
# access_log off; log_not_found off; expires max;
# }
# # Rewrite multisite '.../wp-.*' and '.../*.php'.
# if (!-e $request_filename) {
# rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
# rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
# }
# # End Multisite configuration
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
}
-
For a multisite Wordpress instalation, uncomment (by removing the # at the begining of each line) the lines betwen
# Start Multisite configuration
and# End Multisite configuration
from the file<your-app-folder>/config/nginx.d/default.conf.erb
. -
Now get the latest wordpress version, extract it, and put all the files from the extracted
wordpress
directory, in the folder<your-app-folder>/php/
. -
Add MySQL to your OpenShift app.
-
Open the
<your-app-folder>/php/wp-config-sample.php
file and replace the following strings, and then save the file aswp-config.php
- replace
'database_name_here'
with$_ENV['OPENSHIFT_APP_NAME']
- replace
'username_here'
with$_ENV['OPENSHIFT_MYSQL_DB_USERNAME']
- replace
'password_here'
with$_ENV['OPENSHIFT_MYSQL_DB_PASSWORD']
- replace
'localhost'
with$_ENV['OPENSHIFT_MYSQL_DB_HOST']
- Install Wordpress, configure multisite (if you want it), and done !
- Wordpress NginX configurations: http://codex.wordpress.org/Nginx
- Tutorial for creating a network: http://codex.wordpress.org/Create_A_Network
- Complete tutorial: http://premium.wpmudev.org/blog/wordpress-multisite-wordpress-nginx/
- Another tutorial: https://rtcamp.com/wordpress-nginx/tutorials/multisite/subdirectories/minimal/
- Tutorial from DO comunity: https://www.digitalocean.com/community/tutorials/how-to-configure-single-and-multiple-wordpress-site-settings-with-nginx