News for hackers. Stuff that matters.
Re:Whitehouse.gov Chooses WordPress, Again by splatzone on Saturday January 23, 2021 @09:54PM (#25888648)
WordPress is not without its design flaws, some of which make sense from the point of view of helping non-techies run their own sites (such as making updates easy.) But as someone who has built 100s of sites with WordPress I feel the need to defend it on a few points here:

> You have to let it modify its install. Security-fucking-nightmare.

You don't have to do this, you can set up sane permissions and use the wp cli[0] tool to install updates manually. I prefer to version sites with git and install updates locally, then git pull down on to the live server.

> It will use incoming requests to trigger "cron" jobs (which can include self-upgrades), via a non-loopback HTTP request.

A good practice is to set up your own cron job[1] on the server and disable the internal cron in your wp-config.php, like this:

  define('DISABLE_WP_CRON', true);
Again this is a decision I imagine was made to support shared hosting environments. They've made it easy for 99% of users, which is why it's so popular. We the remaining 1% who prefer to use real cron can edit the config.

> It falls apart under any kind of load, both because of unoptimized DB queries, and because of PHP. You have to put a cache in front of it to be able to handle getting on HN, let alone Reddit.

Just install a page caching plugin of your choice[2]

> You really have to dedicate an admin to it if you want to keep it secure and performant. I still get angry remembering my experience installing, securing, and setting up caching in front of it.

Or use a managed WordPress hosting service like Kinsta[3] if you don't want the hassle. They'll handle all this sysadmin faff for you...

[0] https://wp-cli.org/

[1] https://www.siteground.co.uk/tutorials/wordpress/real-cron-j...

[2] https://en-gb.wordpress.org/plugins/w3-total-cache/

[3] https://kinsta.com/

Re:Whitehouse.gov Chooses WordPress, Again by nsomaru on Sunday January 24, 2021 @01:07AM (#25889755)
> I prefer to version sites with git and install updates locally, then git pull down on to the live server.

I’m working on my first WP project and am trying this approach. A question I have is how do you handle plugins that have hooks that only run once when installed? Those hooks don’t run if you pull in via git. Also if they make changes to the dB (migrations), how is that managed if the plug-in was installed on a different server?

Re:Whitehouse.gov Chooses WordPress, Again by ehnto on Sunday January 24, 2021 @03:13AM (#25890308)
That is all usually still triggered even when using git. Git doesn't manage the database, so when the files make it to production and the plugins are activated, they see a database they haven't been installed in and then correctly run their hooks. Same for migrations. Migrations are managed with database entries, so if your production database doesn't have those entries, it will still run the migrations.

You can check out WP CLI to automate some of this as well.

Re:Whitehouse.gov Chooses WordPress, Again by sleavey on Sunday January 24, 2021 @03:15AM (#25890315)
As far as I know there aren't any real hooks available for running code on plugin install, only activation. But I think OP is referring to core WordPress code and not plugins.
Re:Whitehouse.gov Chooses WordPress, Again by apple4ever on Sunday January 24, 2021 @02:49PM (#25895160)
> You don't have to do this, you can set up sane permissions and use the wp cli[0] tool to install updates manually. I prefer to version sites with git and install updates locally, then git pull down on to the live server.

Yup this is exactly how I do that.

I also have a cron that checks "git status" and emails me if anything changes.

Re:Whitehouse.gov Chooses WordPress, Again by trog on Saturday January 23, 2021 @10:43PM (#25888972)
> You don't have to do this, you can set up sane permissions and use the wp cli[0] tool to install updates manually. I prefer to version sites with git and install updates locally, then git pull down on to the live server.

Curious as to how you manage WP with git, particularly around when new files are added by core/plugin updates, which I've always found a bit of a hassle to deal with?

Re:Whitehouse.gov Chooses WordPress, Again by daniellarusso on Sunday January 24, 2021 @02:51AM (#25890222)
Check out the roots.io project for some software development ‘best practices’ as applied to Wordpress for development and deployment.
Re:Whitehouse.gov Chooses WordPress, Again by trog on Sunday January 24, 2021 @04:48AM (#25890710)
Thanks! Looks super interesting.
Re:Whitehouse.gov Chooses WordPress, Again by ehnto on Sunday January 24, 2021 @03:04AM (#25890276)
Disable automatic updates on production. You don't want automatic updates on a production site anyway, they could bring your site down without you knowing. Instead, install updates and plugins locally, test locally, then push to live. That's really true for any code versioned software.
Re:Whitehouse.gov Chooses WordPress, Again by yurishimo on Saturday January 23, 2021 @10:53PM (#25889038)
The most common approach is to store everything but the wp-content folder in git, including plugins. A way to save space there is by using composer so your Repo only needs to include custom plugins that your team wrote.

It can be a hassle on shared hosts, but most managed hosts have a git workflow that their agency partners utilize so it’s not too bad if you’re doing anything on a professional level.

Re:Whitehouse.gov Chooses WordPress, Again by trog on Sunday January 24, 2021 @01:53AM (#25889926)
The problem is the only thing I really care about is the stuff in wp-content! I've inherited a few sites with custom themes and it's the changes in plugins that I'm most interested in so I can track issues. Almost anything else that comes from latest.zip I am not concerned with.

I just haven't found a good workflow I guess. I'm gradually trying to strip all the plugins which are not required (there are so many) so I can just focus on the core ones that are hard requirements but even one or two decent -sized plugins is a huge responsibility to manage if you're trying to pretend you're tracking all the changes to any level of detail.

Re:Whitehouse.gov Chooses WordPress, Again by splatzone on Saturday January 23, 2021 @11:11PM (#25889135)
I keep things really simple to be honest, normally I exclude wp-content/uploads and wp-config.php in .gitignore. And set the perms so WP can't write to the filesystem on production, except for the uploads directory. We install and test updates on a dev environment first then commit everything and pull it in on production.
Re:Whitehouse.gov Chooses WordPress, Again by ellyagg on Saturday January 23, 2021 @11:26PM (#25889241)
If you don't let production write to the filesystem, doesn't that get rid of one of the main advantages of WP, that users can configure the site by adding plug-ins and such? Or on the 100s of sites, you are responsible for all the plug-ins?
Re:Whitehouse.gov Chooses WordPress, Again by trog on Sunday January 24, 2021 @01:55AM (#25889933)
> If you don't let production write to the filesystem, doesn't that get rid of one of the main advantages of WP, that users can configure the site by adding plug-ins and such? Or on the 100s of sites, you are responsible for all the plug-ins?

The short answer is yes, you're right - losing being able to write to disk means a lot of functionality is lost. But it does improve security in some contexts so the trade-off might be worth it to some people.

I wrote a small plugin that lets me flick between read-only and read/write filesystem permissions with the press of a button - so when I need to administer it, I just allow writing, and the rest of the time I leave it locked off.

Doesn't work in all circumstances (e.g., if there are plugins that need to write to the disk), but for sites which predominantly have static content it means I don't need to worry as much about things writing to disk in the event something is compromised.

Re:Whitehouse.gov Chooses WordPress, Again by ehnto on Sunday January 24, 2021 @03:17AM (#25890321)
If your using a versioned codebase you likely don't want that anyway. Otherwise you'll have untested code on production, and you'll have to commit it to the project repository from production.

Normally you want all code changes to happen locally, and get tested locally, before they ever make it to production. Which means your client will need to get you to install the plugin.

It depends on the project and client though. There are levels of engagement that are a lighter touch, and in those cases you just accept the mess and risk associated with users managing plugins.

Re:Whitehouse.gov Chooses WordPress, Again by sixothree on Sunday January 24, 2021 @11:41AM (#25893372)
The pricing alone of wordpress hosting supports the counter argument that it is indeed too complicated.
Re:Whitehouse.gov Chooses WordPress, Again by uberswe on Sunday January 24, 2021 @11:44AM (#25893402)
Pretty much any shared hosting can support Wordpress. Kinsta was a suggestion where you pay for someone to manage and install things for you which is a lot more than hosting.
Re:Whitehouse.gov Chooses WordPress, Again by sixothree on Sunday January 24, 2021 @02:18PM (#25894869)
Right. I have a shared hosting site I used to host some projects on and now I keep it solely for a single wordpress site for a relative.

My thinking was a wordpress-specific provider might be cheaper so I went out looking for one with disappointing results. `

Re:Whitehouse.gov Chooses WordPress, Again by photomatt on Sunday January 24, 2021 @11:46PM (#25899291)
Happy to host your relative's site on WP.com, here's a 50% off coupon for HN peeps that will work the next 48 hours: HNEWSJANMATT . Please tweet me if you want any extra help from our team on the migration. I hope your relative is very happy.
Re:Whitehouse.gov Chooses WordPress, Again by falcolas on Saturday January 23, 2021 @10:04PM (#25888703)
> You don't have to do this

I updated my original comment here.

> A good practice is to set up your own cron job on the server and disable the internal cron in your wp-config.php

Defaults matter. And when I was working on it, this wasn't well documented anywhere. If it is now, great. It shouldn't be the default.

> Just install a page caching plugin of your choice[1]

A bad idea, IMO. It's still going through the PHP server and all of the routing/plugin/DB code within WP. Much better to use Varnish (and its ilk) and avoid overloading the PHP service.

> Or use a managed WordPress hosting service

Back when I worked for an remote DBA company, we were tapped many times to help optimize DB access by Wordpress. It reminded me that it's remarkably easy to start a WP hosting company, and remarkably hard to do it right.

Re:Whitehouse.gov Chooses WordPress, Again by kortilla on Saturday January 23, 2021 @11:46PM (#25889355)
> It's still going through the PHP server and all of the routing/plugin/DB code within WP. Much better to use Varnish (and its ilk) and avoid overloading the PHP service.

This is incorrect. WP supercache generates static html that takes precedence over falling back to the php engine. This is the way it worked nearly a decade ago too.

I wish people wouldn’t spend so much effort bad-mouthing technology they don’t even understand. I don’t even like Wordpress but reading this is super annoying.

Re:Whitehouse.gov Chooses WordPress, Again by mudlark on Sunday January 24, 2021 @05:09AM (#25890807)
Caching is hard. Drupal used to, may still use the dB for caches. So you get pool issues. You have to also throttle features, like site Search or other intensive scripts. So in the main the internal caching is a step up from none.
Re:Whitehouse.gov Chooses WordPress, Again by rapind on Saturday January 23, 2021 @10:19PM (#25888809)
> A bad idea, IMO. It's still going through the PHP server and all of the routing/plugin/DB code within WP. Much better to use Varnish (and its ilk) and avoid overloading the PHP service.

I'm not a big WP fan, but this statement is false in most cases. Page caching in WordPress is usually (always?) serving up the pre-rendered HTML direct from disk (or CDN) without hitting PHP. Pagely (the post we're discussing) even handle that for you w/ their own CDN. I would imagine they also support request based caching and purging, warming, etc.

Most purely content sites (non-app) can run really well with a very simple TTL based cache (instead of long lived w/ complex flushing). You can very easily use something like Fastly for cloud based varnish w/ an appropriate TTL.

I also feel the need to point out that gatsby type sites and just pre-rendering / caching as well, at least in part (possible using json from a CMS for dynamic data).

Re:Whitehouse.gov Chooses WordPress, Again by falcolas on Saturday January 23, 2021 @10:42PM (#25888959)
> Page caching in WordPress is usually (always?) serving up the pre-rendered HTML direct from disk

I'd be very curious how a WP plugin is managing this.

Third party hosting building in caching, normal in-line caches (like Varnish), nginx/apache caching, sure - I get those, and they behave how you say. But a WP plugin? I'm curious how that would bypass PHP & WP entirely.

Re:Whitehouse.gov Chooses WordPress, Again by achairapart on Sunday January 24, 2021 @03:30AM (#25890367)
Server rewrites. Usually they work adding rules to Apache .htaccess.

On the other hand, this trick was mostly useful years ago when shared hosting plans were really underpowered.

As of today, with improvements of both PHP 7.x and general server performance, even a cache system that uses PHP very early (before any DB connection) to load a pre-rendered html cache file goes a long way in terms of number of pages being served.

Actually, if this become your bottleneck, the .htaccess trick won't help a lot, and you would still look in tools like memcached, redis or reverse proxies to improve things.

Re:Whitehouse.gov Chooses WordPress, Again by rapind on Saturday January 23, 2021 @11:55PM (#25889409)
So I don't normally setup WP sites, but I have as a favour. A caching plugin just generates the HTML files and you configure NGinX / Apache to the appropriate directory. Historically I think most did it via .htaccess w/ Apache for shared hosts, but I've only configured it w/ NGinX. E.g. https://www.nginx.com/blog/9-tips-for-improving-wordpress-pe...

I think a lot of third-party hosts provide this out of the box, maybe even using their own CDN. WP is so popular that it's be difficult not to find a service that handled it all for you so long as you have room in the budget.

Re:Whitehouse.gov Chooses WordPress, Again by yurishimo on Saturday January 23, 2021 @10:55PM (#25889050)
A lot of them do it via special htaccess rules. Check the cache first for an html file, otherwise, fall back to PHP. If not, there may be a little php code running but generally much less than a “normal” request.
Re:Whitehouse.gov Chooses WordPress, Again by kirstenbirgit on Sunday January 24, 2021 @03:52AM (#25890455)
>I'd be very curious how a WP plugin is managing this.

If you don't know how the cache plugins do this, it's pretty obvious you are not very knowledgable about WordPress site operations. Please stop spouting falsehoods here.

Re:Whitehouse.gov Chooses WordPress, Again by splatzone on Saturday January 23, 2021 @10:23PM (#25888832)
You touch on a really good point here about the default cron setting (yes, it still uses the lazy cron on page load by default.) From a developer point of view this is questionable at best, but from a business point of view I reckon decisions like these are the core of why WordPress is popular.

You don't have to know what cron is to install a WordPress site. You don't have to know anything about git or setting up varnish. You just bung the files on your PHP server, put in your database credentials and away you go.

There is a big conflict here between what is practical for users and what is best practice for developers. WordPress has always put user experience first, to the point where it's easy to shoot yourself in the foot and get your site hacked by installing a bunch of badly made plugins. But this tradeoff in the favour of user experience had made it easy for millions of people to set up their own website, and is the reason WordPress is the most popular CMS in the world

Re:Whitehouse.gov Chooses WordPress, Again by 1over137 on Sunday January 24, 2021 @12:51AM (#25889666)
>But this tradeoff in the favour of user experience had made it easy for millions of people to set up their own website

Indeed. And so many commentators here on HN (myself included) bemoan FAANG centralization and wish for decentralization and federation and the like... well, this tradeoff is relevant in that matter.

Re:Whitehouse.gov Chooses WordPress, Again by thwarted on Saturday January 23, 2021 @11:43PM (#25889346)
There is a big conflict here between what is practical for users and what is best practice for developers.

What about the conflict between what is practical for users and what is best practice for users?

Security isn't just a developer's concern. Having to clean up a hacked WordPress site because of crappy defaults isn't very practical for users, either.

Re:Whitehouse.gov Chooses WordPress, Again by falcolas on Saturday January 23, 2021 @10:47PM (#25888994)
I realize that it's really written for end users instead of developers, but that means scares me every time I see something as high profile as the White House using it. For the exact reason as you say here: "it's easy to shoot yourself in the foot and get your site hacked".

WP is absolutely NOT secure by design; it's a hot mess that has helped normalize ignoring security in our web applications. That we encourage its use, that we haven't replaced it with something better, is a damned travesty.

Re:Whitehouse.gov Chooses WordPress, Again by kijin on Saturday January 23, 2021 @11:19PM (#25889204)
Hopefully the White House has access to someone who knows how to set up WordPress without shooting themselves in the foot.

The fact that WordPress.com doens't get hacked all the time means that there are definitely people who know how to do it.

Re:Whitehouse.gov Chooses WordPress, Again by trog on Sunday January 24, 2021 @01:59AM (#25889945)
> The fact that WordPress.com doens't get hacked all the time means that there are definitely people who know how to do it.

Regular reminder that wordpress.com is a different software product to wordpress.org :)

wordpress.com runs their (relatively) newer JavaScript-based stack; wordpress.org (which is what we're talking about here, unless I misread the article referenced here completely) is the LAMP stack version.

Re:Whitehouse.gov Chooses WordPress, Again by nsomaru on Sunday January 24, 2021 @02:42AM (#25890175)
Unless the new Wordpress is written in node, comparing the new “JavaScript” stack with the old “LAMP” stack makes no sense to me. Those technologies do not serve the same purpose.
Re:Whitehouse.gov Chooses WordPress, Again by trog on Sunday January 24, 2021 @03:15AM (#25890317)
> Unless the new Wordpress is written in node, comparing the new “JavaScript” stack with the old “LAMP” stack makes no sense to me. Those technologies do not serve the same purpose.

It's written in JavaScript; it runs on node.js - at least the front-end part of it (https://github.com/Automattic/wp-calypso). I don't know what is running on the backend but I don't think it's LAMP?

The point I was making though is that "WordPress" can mean two different things - wordpress.org (the self-hosted LAMP version) or wordpress.com, which is a SaaS offering (so the language is more or less irrelevant unless you're really interested in running your own admin frontend, I guess).

Re:Whitehouse.gov Chooses WordPress, Again by photomatt on Monday January 25, 2021 @12:01AM (#25899425)
We run WordPress multi-site on WP.com to power several hundred million user accounts. So whenever you visit a domain hosted by us, you're hitting 99% core WordPress, plus some custom plugins and code we run to make it multi-datacenter and super-secure.

Calypso is our JS dashboard that lets you manage all your sites in one place, plus get cool WP.com features like stats and notifications. It's just a REST API client, just like the iOS and Android apps.

Re:Whitehouse.gov Chooses WordPress, Again by earthboundkid on Saturday January 23, 2021 @11:35PM (#25889292)
Yes, but there are also a lot of people who don’t. I still use an RSS reader and basically every six months, a blog that I followed 5 years back and went dark will get taken over by spammers because no one was paying attention to it anymore.
Re:Whitehouse.gov Chooses WordPress, Again by hluska on Sunday January 24, 2021 @12:02AM (#25889438)
I can’t imagine what this has to do with the White House’s website.
Re:Whitehouse.gov Chooses WordPress, Again by earthboundkid on Sunday January 24, 2021 @02:54PM (#25895226)
We’re using the White House as an excuse to talk about Wordpress.