1

I have two PHP versions installed on the server 7.2 and 7.4. Both are enabled as well.

There is a project running using PHP 7.2. And I need to run a new project using PHP 7.4. As I've mentioned, I don't use PHP-FPM. After some research, I should use a2dismod php7.2 and a2denmod php7.4 to stop 7.2 and start 7.4 version. But in this case, the current working project would stop working, since it's compatible with ver 7.2.

So, any idea how can I config Apache to handle two different projects running on the same server one using PHP 7.2 and the other using 7.4 without using PHP-FPM?

2
  • 1
    IIRC you can't run more than one mod_php at a time, so you're going to need to move to FastCGI one way or another, and the recommended way is PHP-FPM. Commented Aug 15, 2023 at 19:56
  • 1
    It's also a good time to update both projects to 8.1+. Another option would be to run 2 cloud servers on different subdomains, but you might as well update to 8,1+ for that too. Commented Aug 15, 2023 at 20:21

1 Answer 1

2

As you use PHP as an Apache module, AFAIK, you can only load one PHP module per server instance.

However similar what is done with PHP-FPM, you can run two Apache server instances. One configured with the PHP 7.2 module, the other with the PHP 7.4 module.

Given the PHP 7.2 moduled Apache is the current server instance, it would proxy for the virtual host of the PHP 7.4 application to the new, second Apache server instance.

This would be comparable with Nginx and two PHP-FPM, just a different layout with Apache and Apache.

         +----------------------------------------------------+
         |                       +-------------+ + pool #1    |
         |                ,----> | PHP-FPM 7.2 | + pool #2    |
         |   +-------+ <--'      +-------------+ + ...        |
  WAN <====> | Nginx |     FCGI                               |
         |   +-------+ <--.      +-------------+ + pool #1    |
         |                '----> | PHP-FPM 7.4 | + ...        |
         |                       +-------------+              |
         +----------------------------------------------------+ 
         +-------------------------------------------------+  
         |    +-------------+            +-------------+   |
  WAN <=====> | Apache #1   | <--------> | Apache #2   |   |
         |    |.............|    HTTP    |.............|   |
         |    | mod PHP 7.2 |            | mod PHP 7.4 |   |
         |    +-------------+            +-------------+   |
         +-------------------------------------------------+

AFAIK you can only use the standard utilities like a2denmod(1) for the main server instance. Therefore make yourself comfortable with the server configuration, Apache is well documented and I personally like its configuration a lot. It's perhaps I started with Apache 1.3 ca.

However as it's 2023, Nginx + PHP-FPM is a very nice combo. Vanilla Nginx is a pretty decent powerhorse.

Sign up to request clarification or add additional context in comments.

10 Comments

Nice answer thank you. It would be great if you also show the diagram of Apache and FPM, how would it look like? Also, out of curiosity, what do you mean by "pool"? Do you mean "project"?
Yes, sure: Take the Nginx diagram and replace "Nginx" with "Apache" and you're done. Pool is a sub-organization within a PHP-FPM master. You can have a pool per project for example. Allows you to control under which user/group it executes, dedicated PHP configuration and environment and also processing limits etc..
Got it, as my last question, do you know in which config file of Apache is specified the PHP version? You know, I have two versions of PHP installed/enabled on the server, but Apache uses 7.2 (saying so based on phpinfo()) as the web server and uses 7.4 for the cli (based on php -v). In which Apache's config file those versions are mentioned?
CLI is unrelated to Apache configuration, however you could control this via the PATH environment parameter that is available per process. Cf. PATH in ENVIRON(7).
And the comment by Dave is not wrong. Just bring the PHP 7.2 app to PHP 7.4, you can continue to run then one server. Then you can experiment with the second server and run PHP 8.2 on it. Depends a bit if you have object intensive code, perhaps start with PHP 8.0/8.1 first, if the quick-start on PHP 8.2 doesn't go well. Most things are only deprecations, log them in 7.4, they are easy to fix and then the code should be upgrade safe.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.