Change apache2 php path - php

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

Related

php-gettext installed but not available

I have the following packages installed on Ubuntu 16.04:
apache2 2.4.18-2ubuntu3.1
php-gettext 1.0.11-2build1
gettext 0.19.7-2ubuntu3
php7.0 7.0.15-0ubuntu0.16.04.4
The only mention of gettext when I call phpinfo() is in the module authors section ("GetText = Alex Plotnick"), so I would assume that support has been compiled in correctly.
It seems that gettext isn't loaded properly into PHP, because the following code:
<?php
if ( false === function_exists('gettext') ) {
echo "You do not have the gettext library installed with PHP.";
exit(1);
}
Does indeed print "You do not have the gettext library installed with PHP."
Apart from documentation, the only php-gettext files I have installed are:
/usr/share/php/php-gettext/gettext.inc
/usr/share/php/php-gettext/streams.php
/usr/share/php/php-gettext/gettext.php
I haven't really touched any php or apache config (apart from try and install icingaweb2)
Can anyone see what my issue could be?
Update
More debugging...
me#phoenix:~$ ls /etc/php/7.0/apache2/conf.d/
10-mysqlnd.ini 20-dom.ini 20-intl.ini 20-mbstring.ini 20-pdo_mysql.ini 20-wddx.ini 20-xmlwriter.ini
15-xml.ini 20-imagick.ini 20-ldap.ini 20-mysqli.ini 20-simplexml.ini 20-xmlreader.ini 20-xsl.ini
me#phoenix:~$ sudo a2dismod php5
ERROR: Module php5 does not exist!
me#phoenix:~$ sudo find / -name gettext.so
/usr/lib/php/20151012/gettext.so
/usr/lib/x86_64-linux-gnu/perl5/5.22/auto/Locale/gettext/gettext.so
It should work out of the box after installation. Have you restarted Apache? Try first sudo apache2ctl restart or sudo service apache2 restart on the terminal console. If both should not work on your system, try sudo /etc/init.d/apache2 restart.
Check if there does exist a file /etc/php/7.0/apache2/conf.d/20-gettext.ini (or similar path on your system) containing the line
extension=gettext.so
There must not be a semicolon prepended, otherwise it is commented out. Some installations may also configue that line within the basic php configuration file /etc/php/php/7.0/php.ini, however the debian derivate's way is to use extra files in the conf.d folder.
You can enable PHP modules (e.g. gettext) on the command line
sudo phpenmod -v 7.0 gettext
If this does not work, edit the configuration manually.
Finally restart your Apache service as described above.
Check also if Apache is running the expected PHP version 7.0 with the following line in your PHP page
echo phpversion();
You can enable / disable Apache2 modules from multiple installed PHP versions on the command line
sudo a2dismod php5
sudo a2enmod php7.0
sudo apache2ctl restart

PHP not running after upgrade

I'm having some trouble getting PHP to run under Apache after updating my software. On my Amazon AWS running AMI, I followed this guide here, with the specific commands:
sudo yum remove httpd* php*
sudo yum install httpd24 php55
After updating the apache config files to use the newer directives, I can get to the server, but the PHP is just echoing out on the screen.
I checked to make sure that there is a php.ini file being read, that the module is loaded in Apache, the server is running, and I can execute php from the command line.
Anyone have any ideas on what I should check next?

Apache2, Wordpress index.php not executed, just text file

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.

Can I simply "repoint" apache to use a different version of PHP?

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.

Install Tidy, PHP

I guess when php was installed on my box --with-tidy arg was not included.
When browsing my php.ini the line:
;extension=php_tidy.dll
is missing.
How can I add the module to my php install? Note I tried adding:
extension=php_tidy.dll
but with no luck.
I checked the docs but all they say is:
This extension is bundled with PHP 5 and greater, and is installed using the --with-tidy configure option.
On Ubuntu, you can add tidy to your php5 installation by running this command in a terminal:
$ sudo apt-get install php5-tidy
If you want to check if it is already installed or validate that the command above worked:
$ php -i | grep libTidy
libTidy Release => 25 March 2009 // means tidy is installed
To install both php5 and tidy at the same time, use this command (as an alternative to the "--with-tidy" configuration option):
$ sudo apt-get install php5 php5-tidy
For PHP 7 just run
sudo apt-get install php-tidy
And restart Apache, That's it :)
Update: Thanks to #Arnis Juraga
For the version above PHP 7, you can mention the version code as follows.
apt-get install php7.4-tidy
I was having the same trouble, and wrote up my solution here:
Installing Tidy 2.0 PHP extension on Ubuntu 10.10
http://web.onassar.com/blog/2010/11/16/installing-tidy-2-0-php-extension-on-ubuntu-10-10/
It works on newer versions of Ubuntu as well.
While it may not be the most direct route, it works well.
I hope it helps others.
Put that line in php.ini next to the other extension=...dll lines and make sure php_tidy.dll is in the directory configured in php.ini under extension_dir.
In ubuntu: you need to run the following command in terminal
sudo apt-get install php5-tidy
and the restart the server
sudo service apache2 restart.
For those who are having trouble enabling Tidy extension for PHP (using PHP handler for Apache server) on Windows (WAMP server), please note that you may be editing the wrong php.ini file. Assuming that WAMP server is installed in C:\wamp[ver]\ where [ver] is a variable version number.
File that you're probably editing:
C:\wamp[ver]\bin\php\php[ver]\php.ini
File that you must edit:
C:\wamp[ver]\bin\apache\apache[ver]\bin\php.ini
You also might want to make sure what's the correct php.ini file to edit by creating an info php file and add this code to it:
<?php phpinfo();
Then look for Loaded Configuration File string.
Finally make sure you uncomment this line within the correct php.ini file:
extension=tidy

Categories