I have 2 versions of php installed in different directories. I can use both from the command line. However, I'm not able to figure out how to get apache to use a different one (in other words, it uses one, but I'd like to try running with the other).
Can I change simlinks or something? What process would I use to "repoint" apache to use my other installation of php?
Assume that you have php7.2 and 7.4 installed.
When you invoke phpinfo(), php 7.2 is responding (and displayed) and you want 7.4 running.
Hereafter how to proceed:
sudo a2dismod php7.2
sudo a2enmod php7.4
systemctl restart apache2
Working for me on Kubuntu 18.04
In your apache httpd.conf file there is a explicit include for the php module. Whatever this points to is the version of php to be used.
Look for a line something like this:
LoadModule php5_module libexec/apache2/libphp5.so
Then change it to point to the library of the new version of php.
If this isn't in your httpd.conf file it may be in another conf file found in /etc/httpd/conf.d/
Any changes to these files require a reload or restart of apache.
Related
Have read previous answers and understand that I must have two versions installed, but cannot locate where the 5.6 could be. I changed /etc/bin/php to point to the version 7.3 I installed using brew. I updated the /etc/apache2/httpd.conf to use php#7.3. I restarted the server to be sure it would start apache reading from the httpd.conf. Yet, when I run phpinfo from the webpage, It starts with 5.6 and does not include the http.conf info about the server administrator, yet it says it's using http.conf. For some reason sudo apachectl restart will not work saying that the port is already in use. I removed the /usr/local/php5 link ( renamed it to php5.bak ), so that it would not be used.
What other things should I look at?
When you use php -v command you use php-cli which can be diffrent version.
Also if you have multiple versions installed you may want disable apache module for old one.
sudo a2dismod php5 // disable php5.6
sudo a2enmod php7.3 // enable php7.3
There can be many different things that are causing it but I'm betting on MacOS Apache that's installed with the system. Try killing it from the startup:
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
I have found a "partial" answer. I am running Mac OS X 10.12.6 on a mac-mini as a web server. The location of the configuration file for apache is:
/Library/Server/web/config/apache2/httpd_server_app.conf
Thus all of the /etc/apache2/httpd.conf and other suggestions, while they work fine on many unix and even OS X ( non-server ) where one has used brew to install, they don't work here. I made some changes in the above file and verified that AFTER going to the Server app, selecting WebSites in the services menu, and clicking toggling the ON/OFF button to off, then back to on, the server is restarted. All of the attempts using different apache2ctl restart, etc. do not work.
I am still somewhat puzzled that I don't see the server administrator that I enter showing up in the phpinfo.php display, but some other changes did.
My next quest, and suggestions are welcome, is how to change the http_server_app.conf file so that instead of php5, it will use my php7 that is available from the command line. The attempt to change:
LoadModule php5_module libexec/apache2/libphp5.so
#LoadModule php7_module libexec/apache2/libphp7.so
did not work as libphp7.so could not be located. I'm now looking for it. At one point in the conference file, I find:
<IfModule php5_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
Will I need to have one like this for php7_module, once I find it and use it above?
I am using https://github.com/wilmoore/php-version to switch between php versions on my local machine, installed within ~/php/versions. Currently setting up separate VMs with different versions of php installed is not an option.
When I switch php version through the command line using the linked tool, I see it listed as php 7. This also works when using php -v. I have restarted terminal and the machine and it still says php 7.
I have updated composer.json to require php 7.0.2 and greater. Yet when I use phpinfo() in my laravel application, it always states the default PHP Version 5.5.9-1ubuntu4.14.
Where is laravel pointing to the php distribution in my Ubuntu 14.04.3 machine and where can I change this path?
EDIT: I am using Apache. I can see in the phpinfo() output that it is reading the ini file from /etc/php5/apache2/php.ini. I have looked in this file but cannot see where to point to the php distribution.
first make sure that php7.*.conf and php7.*.load files are exist in /etc/apache2/mods-available directory.
then use sudo a2enmod php7.* to enable the mod
use sudo a2dismod php5.* to disable the mod
after running the two commands restart your apache2 server
using sudo systemctl restart apache2
The Apache loads the php5_module library in /etc/apache2/mods-available/php5.load.
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
If you know the loactions of your alternative libraries you can change them in this file.
After editing you need to restart your apache. sudo service apache2 restart or sudo systemctl restart apache2.service
Had the same issue on ubuntu16.
ls -l /etc/apache2/mods-available/php7* ,
showed 2 versions -
/etc/apache2/mods-available/php7.0.conf
/etc/apache2/mods-available/php7.2.conf
Deleted the /etc/apache2/mods-available/php7.0.conf, restarted apache2, and phpinfo() via apache2 showed php7.2
I have a problem with apache2, wordpress and php.
I configured virtual hosts and copied the existing wordpress (installed in single host).
The web server is working fine and loads the index.php, but doesn't execute it.
Check mod-enabled folder in your apache. You must have two files their php5.load and php5.conf. If not present, its means php support is not their.To enable php support use command a2enmod php5
It is because your apache2 can't execute php.
In my case, I install libapache2-mod-php by:
aptitude install libapache2-mod-php7.0
Then restart apache by:
/etc/init.d/apache2 restart
May it help you.
I am trying to enable XSL on Ubuntu 12.04 but its failing. I did this locally on my Ubuntu 13.04 and it was successful. Basically the following worked on my local computer.
apt-get install php5_xsl
edit php.ini file and add extension=php5_xsl.so
restart apache
I repeated the same procedures on my production server running Ubuntu 12.04 and PHP version 5.5.12 but the extension is not getting loaded from the phpinfo. I have also changed the extension=php5_xsl.so to extension=xsl.so because this is what in the extension directory.
I read that I might need to recompile PHP but I am not sure of this steps.
Try this:
sudo apt-get install php5-xsl
sudo php5enmod xsl
sudo service apache2 restart
Why:
http://www.lornajane.net/posts/2012/managing-php-5-4-extensions-on-ubuntu
What's happened here is that all debian-flavoured unixes have adopted
this standard for their PHP 5.4 packages, so if you're using debian,
ubuntu, or any of their relatives with PHP 5.4, you'll see a directory
structure like this. When you add a module to PHP, you'll add a file
to the mods-available directory enabling the module and adding any
config specific to it. If you want to enable the module, just do:
php5enmod http
This simply creates a symlink from the usual conf.d directory to point
to where the real files are in mods-available, prefixed with a number
that indicates the priority of the module. By default, the priority is
20.
Using this approach means we can toggle things on and off without
commenting out big chunks of config files and leaving them lying
around - if this seems familiar then that's no surprise; debian-like
linuxes manage their apache configuration in just the same way. Any
packages that you install using aptitude will use these exact same
commands to set up the configuration and then symlink it correctly. To
unlink, use the delightfully predictably-named php5dismod :)
Red Hat Linux Server, Apache 2.2, PHP 5.5.4
When I run this in the command line, everything seems to be fine:
php -r '$mysqli = new mysqli("127.0.0.1", "un", "pw", "things", "3306");'
At the same time, I have a .php document which doesn't run. I get this error...
PHP Fatal error: Class 'mysqli' not found in [/path/to]/vars.php on line 2
from this code:
<?php
$mysqli = new mysqli("localhost", "un", "pw", "things", "3306");
?>
Other .php pages (which don't use mysqli) work fine. Any idea what's going on here? Thanks in advance.
Like I said, today I was facing the exact same issue with Apache 2.4, PHP 5.5.12, Windows Server 2008.
But I was able to solve this.
Diagnostics:
I ran phpinfo() in both my command prompt as well as on the web server/browser and noticed that path of the php.ini files were different in both. Now, I realised that I need to force set the path to the php.ini file in Apache.
Solution:
I fixed this by pointing to the correct php.ini and dll files on my Apache server.
In the httpd.conf file I wrote these lines in sequence.
PHPIniDir "C:/path/php/php5.5.12"
LoadFile "C:/path/php/php5.5.12/php5ts.dll"
LoadModule php5_module "C:/path/php/php5.5.12/php5apache2_4.dll"
The first line alone fixed the issue.
I've asked almost the same question on Unix Stack Exchange; this was how the issue got resolved.
Sometimes restarting Apache has no effect even after rebooting, but stopping the httpd service and starting it again worked for me:
On Fedora
sudo systemctl stop httpd && sudo systemctl start httpd
On systems without systemd (like Ubuntu) you can probably can use something like this (didn't test it):
sudo service apache2 stop && sudo service apache2 start
reference: How to install php + mysql on Fedora?
running php from CLI(command line) is deffent from webserver.
Ushould enable mysqli extension in both.
Normally, if it is installed, you can go into 'php.ini' and uncomment the line for 'mysqli'. On some installations, there is one copy of 'php.ini' for Apache and another for the command line. I think they are both located somewhere under '/etc/php5/'.