Here is how to install WordPress in a subdirectory on Nginx taking it granted that the device is running Ubuntu as Rackspace Cloud Server PVHVM Multi-Instance (i.e. Application Server is Different than Web Server). At minimum, you should be using a standard way of installing Nginx on Rackspace Cloud on one server instance. We can NOT provide any warranty of working fine with the exact codes if your setup is quite different AS custom setup of Nginx can vary widely, i.e. Nginx can be configured with LuaJit.
The Ideal Example Situation to Install WordPress in a Subdirectory on Nginx (Ubuntu, Rackspace Cloud)
Suppose, you used a different PHP based software for podcast
or used a subdomain. Now with HTTPS or with practical issues with the Podcast software, you want to use the podcast
subdirectory to install a Fresh, new WordPress which is fully separate from your main WordPress – i.e. not a WordPress Multisite. There are some basic Tricks to Install WordPress in a Subdirectory on Nginx in a Standard Setup. Usually, by default pretty permalinks of WordPress will not work on the subdirectory. That is what is the basic problem which will provide you solution.
Install WordPress in a Subdirectory on Nginx (Ubuntu, Rackspace Cloud)
Read our detailed guide to install WordPress, if you are fully new. SSH to your Database Server and create a new database, an user and give the user access to the database :
---
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | mysql -u root -p # change wordpress, it is an example CREATE DATABASE wordpress; # wordpressuser should be changed, it is example, so is password CREATE USER wordpressuser@localhost IDENTIFIED BY 'password'; # we will use localhost on one server # we will use the servicenet IP / Private IP with separate database server # modify accordingly GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost'; FLUSH PRIVILEGES; exit # may be? apt-get update -y && apt-get upgrade # exit from ssh if database server is different exit |
Keep the details on a separate text file. Now, SSH to your web server as root. Create the subdirectory, if does not exist :
1 2 | mkdir -p /usr/share/nginx/html/your-subdomain # default location on Ubuntu for apt based nginx |
Simply CD to the subdirectory and wget WordPress, un-tar it :
1 2 3 4 5 6 7 8 | cd /usr/share/nginx/html/your-subdomain # default location on Ubuntu for apt based nginx wget http://wordpress.org/latest.tar.gz tar -xzvf latest.tar.gz cd wordpress mv * .. && cd .. rm -r wordpress latest.tar.gz && ls # see the files |
Point to the desired url on browser like :
1 | https://jima.in/your-subdomain |
Fill up the web form and continue to undergo infamous 5 minutes installation. (Why Infamous? It takes 60 seconds on $5 / month Hostgator, thats why it is hugely used by the spammers, Google possibly thinks WordPress can be spammy, thats why its infamous…)
Aha, WordPress will tell you that it has no right permission to write (no right to write lol) to create the file wp-config.php
, instead will give you what to write as plain text file. Highlight the fully text and copy it. Create wp-config.php
and paste the material, then save it :
1 2 3 4 | nano wp-config.php # paste # write out with ^ + O # exit with ^ + X |
Continue browser works. So your WordPress is ready, but many things are not ready. First, change the permissions :
1 2 3 4 5 6 7 8 9 | pwd # never run "sudo chmod chown root:www-data" command while at root without path # unix will test your knowledge instantly # it is safe to be at the directory to change ownership cd /usr/share/nginx/html/your-subdomain sudo chown root:www-data /usr/share/nginx/html/your-subdomain -R sudo chmod g+w /usr/share/nginx/html/your-subdomain -R sudo chgrp -R www-data /usr/share/nginx/html/your-subdomain # change /your-subdomain/ |
But, your pretty permalinks will not work unless you define the things how to be handled by Nginx, so open the default domain config file (i.e. /etc/nginx/sites-available/default
by default) :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # this is almost flawless for HTTPS website # only link to wp-admin dashboard will not work # from frontend wordpress admin menu bar # copy from the next line location /your-subdomain { index index.php; rewrite ^/your-subdomain/(.*)+$ /your-subdomain/index.php?$1; } # stop copying # your-subdomain is not your name, change it # where to paste? # within # HTTPS server #server { #} # block or post plain server block if you are not secure # find the last "}" and paste before it # save with ^ + O and Exit with ^ + X # do a config test nginx -t # restart if output is fine service nginx restart # set the appropriate permalink structure from wp admin # your w3tc 's rerite will look like this : if (!-f "$document_root/your-subdomain/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_rewrite.html$w3tc_enc") { set $w3tc_rewrite 0; } |
Lot of peoples on stack overflow will flow huge knowledge on only this block, but our method will work with WordPress SEO, Genesis and W3tC without any problem. Your subdirectory will exactly follow the rules of server block, if you do not know anything about NAXSI (Nginx Anti Xss & Sql Injection), you should never try the other methods. What a particular rewrite rule can make a WordPress plugin to be point to becoming vulnerable, we will not expose. Even if you have not configured NAXSI, on Rackspace, with this rules on Infrastructure Managed, it is unlikely to invite SQL injection. Here is the philosophy of NAXSI :
There is nothing more to write!
Tagged With htmly nginx subdirectory , instaall wordpress subdirectory nginx , install wordpress in subdirectory nginx ubuntu , install wordpress nginx in a sub directory , nginx subdirectory privileges , nginx subdirectory rewrite joomla ubuntu , nginx wordpress in subdirectory , put wordpress in sub directory nginx , ubuntu nginx subdomain