Edent,
@Edent@mastodon.social avatar

🆕 blog! “ActivityPub Server in a Single PHP File”

Any computer program can be designed to run from a single file if you architect it wrong enough! I wanted to create the simplest possible Fediverse server which can be used as an educational tool to show how ActivityPub / Mastodon works. The design goals were: Upload a single PHP file to the server. No […]

👀 Read more: https://shkspr.mobi/blog/2024/02/activitypub-server-in-a-single-file/

oook,
@oook@im-in.space avatar

@Edent nice, I was thinking of writing a simple server for a single account that would use an xml file as a source. Pretty sure this has already been done anyway.

evan,
@evan@cosocial.ca avatar

@Edent good for you!

elbosso,
@elbosso@mastodon.social avatar

@Edent also seems to work ok with mastodon on android

pixelcode,
@pixelcode@social.tchncs.de avatar

@Edent Sad that the site isn't particularly Tor-friendly :/

Edent,
@Edent@mastodon.social avatar

@pixelcode it's my website. I'm not sad about it at all.

It was the only way I could cut down on spam & abuse. My website is available on the open Internet.

Edent,
@Edent@mastodon.social avatar

By popular demand, my demo ActivityPub server now also shows how to attach images to a Note.

Follow @ example @ example.viii.fi for an example.

Get the code at https://gitlab.com/edent/activitypub-single-php-file/

Edent,
@Edent@mastodon.social avatar

But the one thing I can't figure out…

When I mention "@ example @ example.viii.fi", it shows as:

@example

Which links back to the user's website, rather than showing their info within Mastodon.

Which arcane or field do I need to have in my JSON file to fix this?

robb,
@robb@social.lol avatar

@Edent When I hit it in Ivory I see the info loaded

Edent,
@Edent@mastodon.social avatar

@robb nice! Would you mind following (temporarily) and telling me if it backfills the previous posts?

robb,
@robb@social.lol avatar

@Edent followed but I can tell you now it won’t.

My instance doesn’t know about those previous posts, only ones that have been sent after I’ve followed.

robb,
@robb@social.lol avatar

@Edent It does fill in the post number and other info, but clicking on posts won’t show anything. For that, I need to visit the profile

fallenhitokiri,
@fallenhitokiri@social.screamingatmyscreen.com avatar

@Edent @example I think it works as expected using Ivory on iOS?

Edent,
@Edent@mastodon.social avatar

@fallenhitokiri @example
Hmmm. It really should show an avatar image as well.
Something else to look into.

jelemux,
@jelemux@social.tchncs.de avatar

@Edent in the client I use (Megalodon), it opens correctly. However, I get what you're discribing with some posts from users of other fedi servers. I did not yet make the effort to find out which ones, though.

Edent,
@Edent@mastodon.social avatar

@jelemux interesting. Thanks 🙂

Edent,
@Edent@mastodon.social avatar

I've now added HTTP Message Signature verification to my demo #ActivityPub server.

https://gitlab.com/edent/activitypub-single-php-file/-/commit/8a7544e5bbb9bd401e1c2bc65ac57e1aca077559#bb6499b8e938f92a3695fff1afe57edea4b9efb7

Currently the entire server is a 32KB single PHP file.

Feedback welcome! It is designed to be a learning tool to show how all the different parts of ActivityPub work.

Edent, (edited )
@Edent@mastodon.social avatar

OK! My tiny #ActivityPub server can now follow users from other instances!

Still under 40KB of adequately documented PHP.

https://gitlab.com/edent/activitypub-single-php-file/

You can follow and message the test user at @example

milosz,
@milosz@adventurousbeastie.eu avatar

@Edent @example I liked the part about the requirements. 👍

rimu,
@rimu@mastodon.nzoss.nz avatar

@Edent I enjoyed the little jokes in the comments :)

Looks like you've got the hang of it. It's all just learning the quirks of different implementations, now!

julian,
@julian@fietkau.social avatar

@Edent Nice work! It looks similar to my own self-study one-file ActivityPub server in Python. I think the structure of the protocols lends itself to implementing single-actor servers as a learning experience.

I know you're saying it's quick & dirty in some ways, but if it's intended as a learning tool for others, do you want feedback on it? There's one bad assumption in there that I think would be better if it was cleaned up.

Edent,
@Edent@mastodon.social avatar

@julian all feedback welcome!

julian,
@julian@fietkau.social avatar

@Edent Then I'll make it short: The assumption that a server has a shared inbox at /inbox does not generalize, as even the existence of a shared inbox is not mandated by anything.

What you'd need to do is when someone follows, you fetch their actor data and store at minimum their inbox and/or shared inbox.

For sending, I build a set of all shared inboxes that occur more than once, and use the individual inboxes for the rest.

Edent,
@Edent@mastodon.social avatar

@julian interesting! Thanks.
How difficult do you think that is to implement? I'm wary of making something too complicated - but I'd like to point to a simple solution if possible.

ahnlak,
@ahnlak@kavlak.uk avatar

@Edent great stuff; I'd seen the previous Symfony-based iteration on Github, and my first thought was "I bet you can get that down to a simple single file install" 🙂

  • All
  • Subscribed
  • Moderated
  • Favorites
  • fediverse
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • megavids
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • provamag3
  • JUstTest
  • All magazines