Diagnose slow script executions on specific server
Which version is each server using?
ALTER TABLE has become significantly slower in 8.0.  It probably has to do with the ability to rollback DDLs.
It has never been wise to depend on a lot of DDLs, but this makes it worse.
If this ALTER was being done to a brand new table, it probably would have been better to include the CONSTRAINT as part of the table definition.  Of course, if the ALTER was generated by mysqldump`, this is not practical.  Furthermore, FKs are very picky about order, so you may be stuck.