How to automatically create a custom field when a post is published?

add_action('publish_post'. 'add_custom_field_automatically');

You have a period in the second add_action. This should be a comma 🙂