Running PHP 7.0.15 with Caddy (Is there a tutorial available?)

I want to try to run PHP 7.0.15 on a Centos 7 (minimal) x64 VPS to test it for a few weeks before it replaces another production server using apache.

My usual method to install PHP from source is:

  1. wget http://ca2.php.net/get/php-7.0.15.tar.gz/from/this/mirror

  2. tar xzf mirror

  3. Install compile requirements if they’re not installed yet:
    yum install httpd-devel.x86_64
    yum install libxml2-devel.x86_64
    yum install gcc
    yum install openssl-devel.x86_64
    yum install libpng-devel
    yum install libjpeg-devel
    yum install autoconf

  4. Configure php with these:
    ./configure --with-apxs2=/usr/bin/apxs --with-mysqli=mysqlnd --enable-ftp --with-openssl --with-zlib --with-gd --with-jpeg-dir=/usr/lib64 --disable-cli

  5. make

  6. make install

I do edit some php.ini settings, but let’s say that anything else is left as-is.

How would I enable php inside caddy?

I read these:

https://caddyserver.com/docs/fastcgi

But, it’s still unclear to me how to really do it from source and what steps I would be missing. I’m not familiar with PHP-FPM and it seems that may be needed.

Is there a PHP tutorial available or could someone please tell me steps that may be required beside these to make it work inside caddy?

(*) PHP 7.1.1 is out, but it’s untested on my production server and I’m still keeping 7.0.x for now.

I compiled PHP 7.0.15 with php-fpm by adjusting my configure to this:
./configure --with-mysqli=mysqlnd --enable-ftp --with-openssl --with-zlib --with-gd --with-jpeg-dir=/usr/lib64 --disable-cli --enable-fpm

I then followed that a bit:

I did these commands:

  • sudo cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf

  • sudo cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf

  • vi /usr/local/etc/php-fpm.conf
    I uncommented: pid = run/php-fpm.pid
    And adjusted line 125 to: include=/usr/local/etc/php-fpm.d/*.conf

It seemed to still have issues with creating the log file so I did:
sudo touch /usr/local/var/log/php-fpm.log

Then I added php-fpm to run at start:
sudo echo ‘php-fpm’ >> /etc/rc.local

I confirmed it does run at next reboot with “ps aux”.

My caddy file is:
http://0.0.0.0:80 {
root /home/centos/www
fastcgi / 0.0.0.0:9000 php
errors error.log
}

I also tried this:
http://0.0.0.0:80 {
root /home/centos/www
fastcgi / 127.0.0.1:9000 php
errors error.log
}

html renders fine, but php files give “502 Bad Gateway”.

I tried other configs in my caddyfile, but the only other thing I got was “Not found” with this in error.log:
Primary script unknown

I tried looking for more info online, but didn’t find one that solves my issue yet.

Anyone have a tutorial or know how I could possibly make it work? I think I’m only missing something minor.

I’ll read these which I just found:

https://github.com/mholt/caddy/wiki/Troubleshooting-PHP-FPM-and-FastCGI

I did these extra steps:

  1. sudo touch /usr/local/var/log/php-fpm.log
  2. sudo chmod 777 /usr/local/var/log/php-fpm.log
  3. sudo touch /usr/local/var/run/php-fpm.pid
  4. sudo chmod 777 /usr/local/var/run/php-fpm.pid
  5. php-fpm

And it started working correctly.

It doesn’t start correctly at boot though.

I’ll have to investigate rights further to know why it doesn’t work correctly.

I’ll determine minimal required steps and I’ll share them.

My final working caddy file is:
0.0.0.0:80 {
root /home/centos/www
fastcgi / 127.0.0.1:9000 php
errors error.log
}

(*) Exact IP hidden for privacy.

1 Like

I have to admit, I’d personally be looking at something prepackaged, a Docker solution, or even another distro before starting to try and figure out problems with a setup based on php from source on Centos.

Appreciate your efforts to document this one!

I’ve started on Centos about 5 years ago and all my servers have been with it since then (both dedicated and VPS).

I’ve had 0 downtime, their packaging is really safe and long-term (end of life of Centos 7 being 2024-06) and with good crons and scripts they’re really low maintenance.

All issues I’ve had have been with WordPress vulnerabilities.

I’ll share my final scripts in a few weeks after testing them a bit.

1 Like

FWIW my monitoring systems are hosted on Centos servers and I’ve never had an issue. Two thumbs up. Just wish they packaged php7.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.