Pointing PHP-7 to Use Caddy

(Boric) #1


I recently set-up a wordpress website utilizing MariaDB, Caddy & PHP-FPM (5.4.16) and it’s been running well so far.

I needed to upgrade the php from 5.4.16 to 5.6.0 or higher (for some extensions), so I opted to go for PHP-7.

I successfully removed PHP version 5.4.16 and installed PHP version 7.0.25

The problem I am running into, is that I cannot find the ‘www.conf’ file to point PHP to serve Caddy.

I already adjusted the ‘Caddy.service’ to the new php-7 path. I just can’t find the file the be able to point PHP to serve Caddy.

Also, I am not entirely server savvy. I mostly just learned the basics to help me navigate the back-end, in case issues arose.

Any help would be appreciated,

Thank you,

(Matthew Fay) #2

Hi @Boric,

I’m assuming you did this with your package manager - which OS are you using?

And can you tell us exactly what you changed in your caddy.service file?

(Boric) #3

Sorry, I forget to include that I am running this on Cent OS 7. I removed PHP manually, then installed the IUS community repo for PHP-7, updated and installed all PHP modules.

And I adjusted the caddyfile. not the Caddy.service. My mistake.

I adjusted line 5 from fastcgi / php to fastcgi / /run/php/php7.0-fpm.sock php in the caddyfile.

The last thing I thought I needed was to redirect PHP-7 to use Caddy, instead of the standard php used Apache or HTTPD. I usually did this by going to the www.conf document in found in /etc/php-fpm.d/www.conf

If this helps any, this is the reference material I used when setting up my application on Cent OS 7

Wordpress using Caddy on Cent OS 7

If you view the article, it only covers install and configuration of PHP 5.4.16, so I looked at this article for help installing PHP-7.

Upgrade PHP from 5.4 to 7.0 on Cent OS 7

(Matthew Fay) #4

Can you tell me what errors you get when you try to access your site in this configuration?

I believe the correct usage should be fasticgi / unix:/run/php/php7.0-fpm.sock php (note the unix:, which denotes a unix socket as the resource scheme).

(Boric) #5

I am getting the common 502 bad gateway error when trying to access my website.

I tried the adjustment to the caddyfile you suggested and still have a 502 bad gateway error.

I cleared my browser cache too. Is there a www.conf file for PHP-7 like past PHP versions?

(Matthew Fay) #6

As far as I can tell, it should be at /etc/php-fpm.d/www.conf

You could try find /etc -name www.conf to search your etc directory for the file in question.

(Boric) #7

Found it. But it’s empty…It’s an empty file. I must’ve overwritten it? But I am not sure how. Is there a way to regenerate such file?

Also found a swp version but it’s also empty upon restoring.

Would a clean re-install be viable?

(Matthew Fay) #8

If you yum remove package and yum install package, it should tell you which config files it isn’t overwriting and what it’s saving them as. Reinstall php, find out where it saves the new www.conf, and copy it over your current one.

(Boric) #9

So I uninstalled PHP and then Re-installed it. The same files were there, which leads me to believe I am not uninstalling it properly. Both were empty. I am uninstalling using

sudo yum remove php70u php70u-pdo php70u-mysqlnd php70u-opcache php70u-xml php70u-gd php70u-devel php70u-mysql

Then restarting caddy

Then installing the same using:

sudo yum install php70u php70u-pdo php70u-mysqlnd php70u-opcache php70u-xml php70u-gd php70u-devel php70u-mysql

Also, thank you for helping me. I do appreciate your patience with me. I am new with this :sweat_smile:

(Matthew Fay) #10

Unfortunately I don’t have experience with php7 on CentOS to advise you further. Usually I’m on a distro from the Debian family, or deploying to mostly-system-agnostic Docker containers.

My last thought would be to try copying the www.conf you had from your php5 installation. Other than that, you might have to hope someone else here has experience with it, or try a more CentOS- or PHP-specific forum.

(Boric) #11

No worries,

I really do appreciate the help though! I’ll continue with my trial & error. I’m sure I’m just overlooking something simple.

But your advice on the Caddyfile really helped me. If I did find the www.conf file and adjusted it, I wouldn’t have had fastcgi loaded properly in my caddyfile.

Thank you!

(Sayem Chowdhury) #12

Your php config is on /etc/php/fpm/pool.d/www.conf. www.conf should not be empty, if it is then something is wrong! Open www.conf and edit these below variable.

user = caddyuser
group = caddyuser

Now restart php: service php-fpm restart

(Boric) #13

Okay. I figured it all out. I was missing a few packages required to run php-fpm in my instance. After removing all php packages, I compiled this command and got www.conf to load properly and changed the users to serve caddy.

sudo yum install php70u-cli mod_php70u php70u php70u-pdo php70u-fpm php70u-mysql php70u-mysqlnd php70u-opcache php70u-curl php70u-gd php70u-mbstring php70u-mcrypt php70u-xml php70u-xmlrpc

I restarted all my services that Wordpress depends on, but I cannot get my webpage to load.

Is my Caddy.Services file missing something?

Should I reinstall Caddy to make sure?

(Boric) #14


I needed to clear caching and adjust the caddy.file to the original one I had in place. Everything works, except my HTTPS certificate is no longer active. It was set to renew in a few weeks. Any thoughts?

Thank you very much for the help BTW. I am learning the in’s & out’s of ssh and to know that I was able to get things in working order, for the most part, is astonishing to me. Thank you guys.

(Boric) #15

Edit #2:

I needed to enable HTTPS port 443… Simple minded me. All is good again.

Thank you guys for helping me. My endless rambling and your selfless help has led me to a once again running website and my updated php 7.

Happy Holidays!