Is there a caddy web server installation guide with php configurations on centos7? I searched it google and all of them are old. Thank you.
I would recommend just following our Caddy install docs:
and then follow your favorite PHP install tutorial. Telling Caddy to forward to your PHP app is one line:
php_fastcgi localhost:7000
(where :7000 is your php-fpm listener)
Although, I’m rather a big fan of FrankenPHP:
FrankenPHP does not require php-fpm as it’s all built-in to Caddy directly.
Hello matt! Thanks for your answer. How can i use FrankenPHP with caddy?
FrankenPHP is a plugin for Caddy that directly runs PHP code. See GitHub - dunglas/frankenphp: The modern PHP app server I wouldn’t recommend it for beginners, frankly. It’s still very much an experimental project at this time, not quite production-ready.
Find any guide that explains setting up PHP-FPM for use with Nginx for example, then when you get to the steps with Nginx, just use Caddy instead. It’s pretty much as simple as that.
Hello Francis! Thanks for your answer. It all worked but but now i have a different problem. Caddy doesn’t respect file permissions. Probably related to user account permissions. In my php-fpm config
user = caddy
group = caddy
listen.owner = caddy
listen.group = caddy
i configured users like that. But when i go to my web content folder and change some folders and files permissions to 777 (example: chmod -R 777 internal_data/
) caddy does not detect and reflect this. I tried restart caddy and restart php-fpm but its not working.
keep your file with permission 744
777 is not a good idea.
another way to resolve your issue, is you should modify your file ownership to www:www
or caddy:caddy
, away from root:wheel
by runninng command chown www:www filename.txt
or try chown -r caddy:caddy /usr/share/caddy/html/internal_data
( -r : the whole folder , include subfolder )
or show us your folder details by typing ls -al /usr/share/caddy/html/internal_data
it should have output similar to this
root@fampfamp:/usr/local/www # ls -al
drwxr-xr-x 9 root wheel 17 Jan 3 18:46 .
drwxr-xr-x 14 root wheel 16 Dec 30 09:21 ..
lrwxr-xr-x 1 root wheel 30 Dec 23 17:00 Caddyfile -> /usr/local/etc/caddy/Caddyfile
drwxr-xr-x 15 www www 31 Dec 29 22:50 example-app
drwxr-xr-x 13 root www 25 Dec 30 20:06 myapp
drwxr-xr-x 7 root www 17 Jan 1 12:56 mycode
drwxr-xr-x 5 www www 11 Dec 30 11:28 myphp.local
-rw-r--r-- 1 root wheel 2950 Jan 3 00:22 Testfile.json
drwxr-xr-x 29 www www 30 Jan 1 12:34 vendor
root@fampfamp:/usr/local/www #
Cheers
Before
[root@ip235 caddy]# ls -al html
total 60
drwxr-xr-x. 9 root root 4096 Jan 3 08:23 .
drwxr-xr-x. 3 root root 56 Jan 3 10:01 ..
-rw-r--r--. 1 root root 302 Dec 9 00:00 admin.php
-rw-r--r--. 1 root root 324 Dec 9 00:00 cmd.php
-rw-r--r--. 1 root root 1918 Dec 9 00:00 connected_account.php
-rw-r--r--. 1 root root 813 Dec 9 00:00 css.php
drwxrwxrwx. 5 root root 76 Dec 29 09:36 data
-rw-r--r--. 1 root root 377 Dec 9 00:00 index.php
drwxr-xr-x. 2 root root 65 Dec 9 00:00 install
drwxrwxrwx. 7 root root 148 Dec 26 17:17 internal_data
-rw-r--r--. 1 root root 1328 Dec 9 00:00 job.php
drwxr-xr-x. 6 root root 97 Dec 9 00:00 js
drwxr-xr-x. 2 root root 41 Dec 9 00:00 library
-rw-r--r--. 1 root root 863 Dec 9 00:00 oembed.php
-rw-r--r--. 1 root root 1688 Dec 9 00:00 payment_callback.php
-rw-r--r--. 1 root root 983 Dec 9 00:00 proxy.php
-rw-r--r--. 1 root root 6028 Dec 9 00:00 service_worker.js
-rw-r--r--. 1 root root 376 Dec 9 00:00 sitemap.php
drwxr-xr-x. 6 root root 157 Dec 26 17:12 src
drwxr-xr-x. 4 root root 52 Dec 9 00:00 styles
-rw-r--r--. 1 root root 1873 Dec 9 00:00 unfurl.php
-rw-r--r--. 1 root root 357 Dec 9 00:00 webmanifest.php
After chown -R caddy:caddy html
[root@ip235 caddy]# chown -R caddy:caddy html
[root@ip235 caddy]# ls -al html
total 60
drwxr-xr-x. 9 caddy caddy 4096 Jan 3 08:23 .
drwxr-xr-x. 3 root root 56 Jan 3 10:01 ..
-rw-r--r--. 1 caddy caddy 302 Dec 9 00:00 admin.php
-rw-r--r--. 1 caddy caddy 324 Dec 9 00:00 cmd.php
-rw-r--r--. 1 caddy caddy 1918 Dec 9 00:00 connected_account.php
-rw-r--r--. 1 caddy caddy 813 Dec 9 00:00 css.php
drwxrwxrwx. 5 caddy caddy 76 Dec 29 09:36 data
-rw-r--r--. 1 caddy caddy 377 Dec 9 00:00 index.php
drwxr-xr-x. 2 caddy caddy 65 Dec 9 00:00 install
drwxrwxrwx. 7 caddy caddy 148 Dec 26 17:17 internal_data
-rw-r--r--. 1 caddy caddy 1328 Dec 9 00:00 job.php
drwxr-xr-x. 6 caddy caddy 97 Dec 9 00:00 js
drwxr-xr-x. 2 caddy caddy 41 Dec 9 00:00 library
-rw-r--r--. 1 caddy caddy 863 Dec 9 00:00 oembed.php
-rw-r--r--. 1 caddy caddy 1688 Dec 9 00:00 payment_callback.php
-rw-r--r--. 1 caddy caddy 983 Dec 9 00:00 proxy.php
-rw-r--r--. 1 caddy caddy 6028 Dec 9 00:00 service_worker.js
-rw-r--r--. 1 caddy caddy 376 Dec 9 00:00 sitemap.php
drwxr-xr-x. 6 caddy caddy 157 Dec 26 17:12 src
drwxr-xr-x. 4 caddy caddy 52 Dec 9 00:00 styles
-rw-r--r--. 1 caddy caddy 1873 Dec 9 00:00 unfurl.php
-rw-r--r--. 1 caddy caddy 357 Dec 9 00:00 webmanifest.php
Then i restarted caddy and php-fpm but this error isn’t gone
/usr/share/caddy/html/internal_data
Folder Permissions
[root@ip235 html]# ls -al internal_data/
total 16
drwxrwxrwx. 7 caddy caddy 148 Dec 26 17:17 .
drwxr-xr-x. 9 caddy caddy 4096 Jan 3 08:23 ..
drwxrwxrwx. 2 caddy caddy 24 Dec 28 13:04 addon_batch
drwxrwxrwx. 5 caddy caddy 105 Dec 25 10:31 code_cache
drwxrwxrwx. 2 caddy caddy 199 Jan 3 08:20 file_check
-rwxrwxrwx. 1 caddy caddy 30 Dec 9 00:00 .htaccess
-rwxrwxrwx. 1 caddy caddy 1 Dec 9 00:00 index.html
-rwxrwxrwx. 1 caddy caddy 86 Dec 25 10:32 install-lock.php
drwxrwxrwx. 2 caddy caddy 59 Jan 2 01:48 sitemaps
drwxrwxrwx. 2 caddy caddy 24 Jan 3 08:19 temp
My caddy config file
:80 {
# Set this path to your site's directory.
root * /usr/share/caddy/html
# Enable the static file server.
file_server
# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080
# Or serve a PHP site through php-fpm:
php_fastcgi unix//var/run/php-fpm/php-fpm.sock
#tls /usr/share/caddy/certificate.pem /usr/share/caddy/key.pem
}
In my php-fpm config file i just edited this lines:
listen = /var/run/php-fpm/php-fpm.sock
user = caddy
group = caddy
listen.owner = caddy
listen.group = caddy
I am not sure if php_fastcgi
after file_server
is okay, but mine is at the top
And I would add try_files {path} {path}/ /index.php?{query}
after the file_server
to ask caddy to look for index.php
which something like below:
:80 {
root * /usr/share/caddy/html
php_fastcgi unix//var/run/php-fpm/php-fpm.sock # make sure this is accurate
file_server
try_files {path} {path}/ /index.php?{query}
}
And do you sure you have both caddy as user & group ?
You can run command $ id
and $ groups
to find out.
If not, I suggest you to change to www:www
for file ownership and php-fpm config
Both id
and groups
are scoped to your current user (root
).
Use getent groups
to list all groups (and their corresponding members) instead.
The Caddyfile has something called (default) Directive order.
Thus, as documented, file_server
gets reordered to come after php_fastcgi
, whenever necessary.
Just as a quick fyi
This is my output, what should i do?
[root@ip235 ~]# getent group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:
cdrom:x:11:
mail:x:12:postfix
man:x:15:
dialout:x:18:
floppy:x:19:
games:x:20:
tape:x:30:
video:x:39:
ftp:x:50:
lock:x:54:
audio:x:63:
nobody:x:99:
users:x:100:
utmp:x:22:
utempter:x:35:
ssh_keys:x:999:
input:x:998:
systemd-journal:x:190:
systemd-bus-proxy:x:997:
systemd-network:x:192:
dbus:x:81:
polkitd:x:996:
libstoragemgmt:x:995:
abrt:x:173:
rpc:x:32:
tss:x:59:
dip:x:40:
slocate:x:21:
postdrop:x:90:
postfix:x:89:
sshd:x:74:
ntp:x:38:
chrony:x:994:
stapusr:x:156:
stapsys:x:157:
stapdev:x:158:
tcpdump:x:72:
caddy:x:993:caddy
mysql:x:992:
apache:x:48:
Your site files should not go in /usr/share/caddy
. That directory is meant to be owned/controlled by the Caddy debian package. That’s where the package stores the default welcome page for Caddy. You should not put your own files there.
Instead, use /srv
or /var/www/html
which are locations meant for storing files to serve.
The debian package adds the caddy
user to the www-data
group. You can leave PHP’s config as the default (i.e. www-data
typically) and just make sure the files are group-owned by www-data
and it should work fine.
That’s not necessary. The php_fastcgi
directive has built-in try_files
logic. See the docs.
Hello again Francis, i changed my website directory to /var/www/html. But caddy or php-fpm is not respecting file permissions again.
[root@ip235 ~]# ls -al /var/www/html/
total 60
drwxr-xr-x. 9 caddy caddy 4096 Jan 4 12:55 .
drwxr-xr-x. 4 root root 49 Jan 4 13:16 ..
-rw-r--r--. 1 caddy caddy 302 Dec 9 00:00 admin.php
-rw-r--r--. 1 caddy caddy 324 Dec 9 00:00 cmd.php
-rw-r--r--. 1 caddy caddy 1918 Dec 9 00:00 connected_account.php
-rw-r--r--. 1 caddy caddy 813 Dec 9 00:00 css.php
drwxrwxrwx. 5 caddy caddy 76 Dec 29 09:36 data
-rw-r--r--. 1 caddy caddy 377 Dec 9 00:00 index.php
drwxr-xr-x. 2 caddy caddy 65 Dec 9 00:00 install
drwxrwxrwx. 7 caddy caddy 148 Dec 26 17:17 internal_data
-rw-r--r--. 1 caddy caddy 1328 Dec 9 00:00 job.php
drwxr-xr-x. 6 caddy caddy 97 Dec 9 00:00 js
drwxr-xr-x. 2 caddy caddy 41 Dec 9 00:00 library
-rw-r--r--. 1 caddy caddy 863 Dec 9 00:00 oembed.php
-rw-r--r--. 1 caddy caddy 1688 Dec 9 00:00 payment_callback.php
-rw-r--r--. 1 caddy caddy 983 Dec 9 00:00 proxy.php
-rw-r--r--. 1 caddy caddy 6028 Dec 9 00:00 service_worker.js
-rw-r--r--. 1 caddy caddy 376 Dec 9 00:00 sitemap.php
drwxr-xr-x. 6 caddy caddy 157 Dec 26 17:12 src
drwxr-xr-x. 4 caddy caddy 52 Dec 9 00:00 styles
-rw-r--r--. 1 caddy caddy 1873 Dec 9 00:00 unfurl.php
-rw-r--r--. 1 caddy caddy 357 Dec 9 00:00 webmanifest.php
Same error
My website script is xenforo and its worked nicely on ubuntu but on centos its giving that error.
All required information is in topic. There is nothing extra.
The error message screenshot you posted implies you didn’t actually change your root
config to the new location. Are you sure you did that?
Hmm, that’s a clue. Centos typically has SELinux enabled, which might have some rules that are controlling this. It might be related to that. I don’t use Centos myself so I don’t have any specific recommendations there but it’s a lead.
I disabled selinux and its worked! Thank you so much Francis! And sorry for screenshot i copied and pasted it because I was too lazy.
This topic was automatically closed after 30 days. New replies are no longer allowed.