Skip to content

Commit dccf60f

Browse files
Ensure user socket directory exists before starting PHP service
FrankenPHP fails with "bind: no such file or directory" when the ~/.fastcp/run/ directory doesn't exist. The systemd code paths in generateCaddyfile() and generateUserCaddyfile() started the service without creating the directory first. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent eb16ae5 commit dccf60f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

internal/agent/handlers.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,19 @@ func userSocketPath(username string) string {
876876
return filepath.Join(userSocketDir(username), "php.sock")
877877
}
878878

879+
func ensureUserSocketDir(username string) {
880+
sockDir := userSocketDir(username)
881+
u, err := user.Lookup(username)
882+
if err != nil {
883+
return
884+
}
885+
uid, _ := strconv.Atoi(u.Uid)
886+
gid, _ := strconv.Atoi(u.Gid)
887+
os.MkdirAll(sockDir, 0755)
888+
os.Chown(sockDir, uid, gid)
889+
os.Chown(filepath.Dir(sockDir), uid, gid)
890+
}
891+
879892
func (s *Server) startUserPHP(username string) error {
880893
sockDir := userSocketDir(username)
881894
socketPath := userSocketPath(username)
@@ -1100,6 +1113,7 @@ func (s *Server) generateCaddyfile() error {
11001113

11011114
// Start user's PHP service (skip if suspended)
11021115
if len(sites) > 0 && !isSuspended {
1116+
ensureUserSocketDir(username)
11031117
if useSystemd {
11041118
serviceName := fmt.Sprintf("fastcp-php@%s.service", username)
11051119
exec.Command("systemctl", "start", serviceName).Run()
@@ -1372,6 +1386,7 @@ session.cookie_samesite = Strict
13721386
}
13731387

13741388
// Reload user's FrankenPHP service
1389+
ensureUserSocketDir(username)
13751390
serviceName := fmt.Sprintf("fastcp-php@%s.service", username)
13761391
exec.Command("systemctl", "reload-or-restart", serviceName).Run()
13771392

0 commit comments

Comments
 (0)