- How To Change What Version of PHP Apache2 Uses?
- 4 Answers 4
- Install PHP as Apache SAPI module
- Install PHP as PHP-FPM (FastCGI Process Manager)
- Final steps
- PHP 8.0 and above extra step
- Last step
- How to determine which php apache uses?
- How to get apache’s version?
- How to determine which php apache uses?
- Bash get php versions available for apache
- Apache using old PHP version
- How to confirm which PHP file is running in Apache?
- 2 Answers 2
- If you are trying to get the full path to the running Apache PHP module, do this.
- If you are trying to monitor your Apache server to figure out what file might be choking it, do this.
- Using Apache Top to monitor an Apache web server.
- Using ELinks to monitor an Apache web server.
How To Change What Version of PHP Apache2 Uses?
Ubuntu 10.04, MySQL 5.1, Apache 2.2, and PHP 5.2/5.3: I just discovered that I am using the wrong version of PHP for a CRM application. Once I figured out how to make a simple phpinfo() script to tell me what Apache2 is using, I tried changing the php.ini such that my webserver would use the PHP I want. Well, this is my problem. Not sure how to do that. I compiled the version of PHP I want to /etc here: /etc/php-5.2.8/ Inside this, there was a php.ini-recommended file that I made some changes to and renamed to php.ini so PHP would use it. But when I opened my browser and cleared my history and went to the http://localhost
4 Answers 4
Depending on your server, you should be looking at Apache, not PHP.
(For RHEL/CentOS) look at /etc/httpd/conf.d/php.ini
# # PHP is an HTML-embedded scripting language which attempts to make it # easy for developers to write dynamically generated web pages. # LoadModule php5_module modules/libphp5.so # # Causes the PHP interpreter to handle files with a .php extension. # AddHandler php5-script .php AddType text/html .php
You’ll see that your PHP module is modules/libphp5.so .
AddHandler php5-script .php tells Apache to run PHP on any file with the extension .php .
If you are using an RPM based OS it’s probably easier to uninstall (assuming you can do that) the current version of PHP, and reinstall the version you are looking for.
will show you what version of PHP is currently installed.
I really wish it was this easy. The only php.ini file I have in the server directory is /etc/apache2/php.ini but not where you suggest. This file doesn’t have these components you speak of: LoadModule, AddHandler, AddType, etc.
interesting. What OS flavor are you running on? Was it configured via YUM, APT-Get, or YAST, (or some other package manager)?
Ubuntu 10.04. The new version of PHP (5.3.2) can easily be installed unsing apt-get , which I have done. But hte PHP 5.2.8 and 5.2.13 I compiled, using files from php.net/releases. I actually kind of gave up trying to get older version of PHP to run. I think alternate approaches are in order for the sake of brevity. Thanks for your help, nonetheless.
php.ini could be extended via includes: /etc/httpd/conf.modules.d/15-php.conf: LoadModule php7_module modules/libphp7.so LoadModule php7_module modules/libphp7-zts.so
If you’ve already installed another version of php, you only need to change the php* module used by apache.
for example, I have php5 and php7.0. when I want apache use php7.0, I only need to enable his module and disable php5 module.
sudo a2dismod php5 sudo a2enmod php7.0
There are two main methods to install a new PHP version and tell Apache to use it: mod_php and php-fpm .
Note: The preffered method is php-fpm , and many new distributions (including Fedora) are using it by default.
Install PHP as Apache SAPI module
Here is the guide around this for Unix systems, from the official documentation. It has some missing points (at least for my setup), so I walk through the steps:
- Build PHP from source. In the ./configure step, use —with-apxs2 . This will build shared Apache 2 handler module for you. Make sure you have apxs command defined in your path, or specify its path as the option’s value (i.e. —with-apxs2=/path/to/apxs ). For instance, if you installed Apache system-wide and want to install this command as well (e.g. on a local environment), on Fedora and its derivatives, you can install it by:
sudo dnf install httpd-devel
# In the case of PHP8 LoadModule php_module /usr/lib64/httpd/modules/libphp.so # In the case of PHP7 LoadModule php7_module /usr/lib64/httpd/modules/libphp.so
Install PHP as PHP-FPM (FastCGI Process Manager)
Final steps
PHP 8.0 and above extra step
In the case your distribution does not support PHP8 yet (e.g. Fedora 34) and you installed Apache2 from the package manager, you should take one more step.
The problem is, from PHP 8.0 onwards, Apache2 uses different identifiers for SAPI modules than before. These identifier are used in order to detect whether you are using mod_php or php-fpm , in the configuration files. For PHP5, it was php5_module and mod_php5 ; for PHP7, it is php7_module and mod_php7 , and for PHP8, it is php_module and mod_php .
In this case, navigate to Apache2 configurations directory (e.g. /etc/httpd ), and start editing the file conf.d/php.conf . There are two IfModule sections there: One for enabling php-fpm if you don’t use mod_php , and the other for enabling mod_php if you are using it (i.e. using LoadModule somewhere in the configurations). You should update these conditions to cover PHP8 as well.
For instance, consider the following:
# Enable PHP-FPM configuration
You should surround the core configuration with one more IfModule section like this:
# Enable PHP-FPM configuration
And do the same for the mod_php enabler configuration section as well.
Last step
Restart the Apache service:
Now, phpinfo() should show you the new PHP version you just installed. You should be happy now. 🙂
How to determine which php apache uses?
Solution 1: From the introduction to Apache functions: If you run PHP as CGI/FastCGI or any other SAPI, there’s just no reliable way to determine Apache version because the interaction of PHP with Apache is minimum. When you run your script via Apache, you’re executing the first.
How to get apache’s version?
From the introduction to Apache functions:
These functions are only available when running PHP as an Apache module.
If you run PHP as CGI/FastCGI or any other SAPI, there’s just no reliable way to determine Apache version because the interaction of PHP with Apache is minimum. If the server does not report it (thus you can read it somewhere at $_SERVER ) you’re out of luck.
You can also determine how PHP runs with phpinfo() .
You can use $_SERVER[‘SERVER_SOFTWARE’] To get the the web server you’re running. As Andrew said you can compile it yourself from here. There’s no way around it
How to get apache version in php?, This Gist provides probably the best fallback I’ve seen if the apache_get_version function is disabled. Basically you need to define a function that uses the operating system to call the httpd daemon directly to get the version information. Although, in your situation, it’s likely that OS commands are also …
How to determine which php apache uses?
I think this depend on if you run php files using mod_php5 or cgi . The difference is explained in the accepted answer in this question: What is mod_php?
As I understand it, basically mod_php5 is pre-compiled from a specific PHP version that Apache will than use. While if CGI is used to run PHP the installed PHP command line version will be used when spawning a new process each time a PHP file is executed.
Php — How to get the Apache version, hello alexteg thanks for your reoly, i have used $_SERVER[‘SERVER_SOFTWARE’] but its only echoing ‘Apache’ & its not displaying version no. there. and i have also checked phpinfo() and used same function as given in your link but then also its not displaying any version no. Usage example$_SERVER[‘SERVER_SOFTWARE’]Feedback
Bash get php versions available for apache
Using extglob you can do this:
( shopt -s extglob ## enable extended glob versions=(/etc/php/*/apache2) ## Save the files in an array IFS='|' ## set IFS to | ## print values after replacing unwanted part printf '| %s ' "$" )
PS: Using ( . ) to run these commands in a sub-shell to avoid changing IFS for parent shell.
Something like this maybe.
#!/usr/bin/env bash availablesVersions () < ##: Just in case there are no files, the glob will not expand to something. shopt -s nullglob ##: Keep variables (array name, varname) local to the function. declare -a versions local output versions=(/etc/php/*/apache2) ##: Save the files in an array versions=("$") ##: Remove the last / versions=("$") ##: Remove the first / longest match versions=("$") ##: Add trailing space versions=("$") ##: Add leading space output=$( IFS='|'; printf '|%s' "$" ) ##: Format output echo "$" ##: Print the output without the trailing space. shopt -u nullglob ##: Disable nullglob. >
Php — How to get apache’s version?, These functions are only available when running PHP as an Apache module. If you run PHP as CGI/FastCGI or any other SAPI, there’s just no reliable way to determine Apache version because the interaction of PHP with Apache is minimum. If the server does not report it (thus you can read it somewhere at …
Apache using old PHP version
First, I’m not that familiar with package management on Fedora, so perhaps someone else can check the commands I’ve listed below.
On Debian, there are (at least) two different PHP packages:
php5-cgi - server-side, HTML-embedded scripting language (CGI binary) php5-cli - command-line interpreter for the php5 scripting language
When you run your script from the command line, you’re executing the second one of these. When you run your script via Apache, you’re executing the first.
I’ve never known these to get out of sync — I’ve always seen both with the same version — but it doesn’t sound like something impossible. I can imagine that if I really wanted to, I could figure out how to install different versions of both.
From my (limited) knowledge of package management on Fedora, I’d start by trying to update both packages to the latest version:
yum update php5-cgi yum update php5-cli
Again, these may be named differently in the Fedora repositories, so you’ll need to research that a little.
How to determine which php apache uses?, In phpinfo () there will be info what php.ini file is used. There should be path to this file. So for example my: Loaded Configuration File: /etc/php5/apache2/php.ini and php should be in /etc/php5/. THanks I found php /usr/local/php5/bin/php I will change the commandline path to this. Sorry I just …
How to confirm which PHP file is running in Apache?
I have a situation that my VPS has run out of CPU because of my website. How to confirm which PHP file is running by Apache? So I can solve this problem. I tried the commands of lsof -p , ps -f , strace -p , but no one help me because all the comming out are apache files, such as /usr/local/zend/apache2/bin/httpd , /usr/local/zend/apache2/modules/mod_unique_id.so .
2 Answers 2
Use sudo only if necessary. List all processes, and then tell grep to output only the lines having the word php .
Read the output as per the following heading
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
If you are trying to get the full path to the running Apache PHP module, do this.
The PHP file used by Apache should be named libphp5.so . So you can run this lsof command via sudo :
sudo lsof | grep libphp5.so
Which should return a whole pile of results with pretty much all of them showing the full path to libphp5.so which should be something like this if you are on an Ubuntu/Debian system:
/usr/lib/apache2/modules/libphp5.so
If you are trying to monitor your Apache server to figure out what file might be choking it, do this.
That said, it’s unclear to me from your question what you mean by “How to confirm which PHP file is running in Apache?” since rereading that makes me think that perhaps you are trying to figure out what PHP script is choking your server and not what PHP module Apache is loading? Because the actual PHP module Apache loads simple is just the PHP parser Apache uses. But a PHP script you are running via that setup is a whole different thing.
The problem is that the way Apache works is the contents/files are parsed on demand. So you need to run a tool that will monitor Apache requests in real time to get the info you are looking for in that case. There are a few ways you can do this from the command line.
Using Apache Top to monitor an Apache web server.
First, you can install and run Apache Top which is similar to the standard Linux/Unix top but for Apache processes. For example, here is a nice/simple way to monitor a web server’s log files in realtime with Apache Top:
apachetop -r 2 -f /var/log/apache2/access.log
The -r 2 will refresh the output every 2 seconds and the -f /var/log/apache2/access.log tells apache-top to report on info from the provided Apache log. In that example it’s loading the default Apache log file from an Ubuntu/Debian setup, but you should change that full file path to match your actual Apache log file location.
Using ELinks to monitor an Apache web server.
Another method I use to monitor Apache on a server is using ELinks and the default Apache status URL like this:
elinks http://localhost/server-status?refresh=1
ELinks is basically just a text-based web browser. So if you run that from the command line, it will just load the URL passed to it and if you notice that URL includes the refresh=1 parameter which basically just tells the server-status to refresh itself every second.