I'm currently developing a web page with PHP, and I had to install Pthread extension, I made it in the server (Ubuntu 14) so, before I had all working well, the problem came when I installed the extension, to install this extension I had to compile the php to make the needed configurations of PHP. Now, when I open a simple page, apache shows me the php code, it means that php is not interpreting or is not loaded in the modules of apache.
I went to /etc/apache2/mods-enabled but there's nothing of PHP, but in the linux terminal PHP is working well (so, it's installed). then I made:
sudo a2enmod php5
And I get this response:
ERROR: Module php5 does not exist!
then , I made:
a2query -m php5
but I get:
No module matches php5
I have installed PHP 5.6version, so how can I enable this module in apache. I cannot install the standar version of PHP, I need this one for the mentioned reason. Thanks!
Apache needs a PHP module to execute PHP. In some distros (Debian, etc.) there is a specific package for this. In Ubuntu: libapache2-mod-php5
It does not impact the php installation install but only adds the apache module.
Once installed, one only need to activate the module.
Related
I have a test server running Ubuntu 16.04. I managed to compile PHP 7.2.2 with ZTS from source and installed PThreads on it.
Now, how do I proceed with further setting up PHP without damaging my installation? If I try to install, let's say PHP Curl or Apache's PHP 7.2 module, Ubuntu wants me to install php7.2-common, etc. which would overwrite my current installation.
Is there a safe way to install additional PHP modules and hook up PHP with Apache2?
Thank you in advance!
I have Joomla 3.3.3 in a server where PHP 5.3.29 is installed.
I requested the hosting team (Hostgator) to install PHP 5.5.28 side by side.
When they told me the task was finished, I added these lines to the top of .htaccess file:
# PHP 5.5
AddHandler application/x-httpd-php55 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php55/lib
</IfModule>
After that, I tried to load the page and this error was shown, in both front end an in administration pages:
Error displaying the error page: Application Instantiation Error: Could not connect to MySQL.
If I remove the added lines in .htaccess, site works again.
What may be hapenning here?
It may be that they haven't installed the mysql extension, you can compare the versions of php using a simple phpinfo script:
<?php
phpinfo();
Run this in your browser using both PHP 5.3 and PHP 5.5 and scroll down the the 'mysql/mysqli/mysqlnd' section which will tell you whether it's been installed with the mysql extension or not, if it hasn't been contact your host and ask them to add it.
If you're running on a vps or similar you can also check apt/dnf/yum to check for package differences:
apt list --installed | grep php
dnf list --installed | grep php
yum list installed | grep php
If you see you have a lot of packages prefixed with php53- and only a few with php55- you could ask them to install the missing packages, for example (using brew on OSX), if I list with brew there is a clear difference between packages I have installed for php56 and php71:
user#comp ~ $ brew list | grep php
php56
php56-mcrypt
php56-memcache
php56-mongo
php56-xdebug
php71
php71-xdebug
In this situation I would ask the host to install php71-mcrypt, php71-memcache and php71-mongo or equivalents.
Typically, the most common reason for this problem (in your scenario) is when the mysql[i] package is not compatible with the version of PHP installed. Usually, the host takes care of the problem (I would bug them about it).
You can check the installation of mysqli on a Centos environment here: http://php.net/manual/en/mysqli.installation.php
I added the curl module in /etc/php/7.0/cli/php.ini :
extension = /usr/lib/php5/20121212/curl.so
but when I restart php and I do :
php -m
I get this error :
curl : Unable to initialize module
Module compiled with module API=20121212
PHP compiled with module API=20141010
These options need to match
I also tried :
apt-get install php5-curl
Curl is "already to the new version".
And phpinfo() tells php5 is running :
PHP Version 5.5.9
php.ini Path : /etc/php5/fpm
PHP Extension : 20121212
but when I check on the server with :
which php => /usr/bin/php (for php7)
php -v => PHP 7.0 (with a warning before "Unable to initialize module")
and if I remove curl.so in the php.ini above (the one of php7, at 1st line) the warning disapear.
---------------------------------------
so I added : extension=/usr/lib/php5/20121212/curl.so
in :
/etc/php5/fpm/php.ini
then I restart, but I still can't see this module :
And here the error saying this module is still missing :
So, if you're trying to add the module to webserver's PHP, which is in your case PHP5, you need to add that module to /etc/php5/fpm/php.ini (based on your previous question where you stated that you use NGINX+PHP-FPM).
If you want to add it to the CLI version - you're doing it wrong, cause you're adding PHP5 module to PHP7 - that won't work, you need to install php7-curl and it will auto-add itself where needed.
To elaborate somewhat more. Your phpinfo() tells you that your INI path is in /etc/php5/fpm:
PHP Version 5.5.9
php.ini Path : /etc/php5/fpm
PHP Extension : 20121212
Hence, to add any extensions to that particular PHP - just add them to /etc/php5/fpm/php.ini. Note, you can not (or very rarely) add extensions from one version of PHP to another version of PHP.
I'll add a summary of what's happening on the OP's system for future reference then.
Basically, OP has 2 versions of PHP installed on the system simultaneously, PHP5 and PHP7 with an NGINX werserver with php-fpm extension.
His NGINX is configured to use PHP5, while CLI PHP defaults to PHP7.
The confusion with OP comes from the fact that on an Ubuntu system there's a clear difference between the PHP that's called from the CLI and the PHP that's used by webserver.
CLI tools are available per-version as /usr/bin/php5 and /usr/bin/php7, with one default link /usr/bin/php pointing to one particular version, in this case PHP7.
For the FPM module, there are 2 packages available php5-fpm and php7-fpm, with respective configs in /etc/php5/fpm/php.ini and /etc/php/7.0/php.ini.
For the CLI, there are 2 packages available as well - php5-cli and php7-cli, with respective configs in /etc/php5/cli/php.ini and /etc/php/7.0/cli/php.ini.
For curl extension, there's the same story, php5-curl and php7-curl. Extensions will be auto-wired to the needed INI files by the deb installer.
Installing multiple versions of PHP for fun can create this kind of confusion. :)
That means that your CURL module was compiled against a different version of PHP. Depending on your flavor of Linux (looks like Debian flavor) you might need to install a module
sudo apt-get install php5-curl
What about calling your hosting company to see what versions they have available and which one's your code are picking up?
Maybe they have some unique setup that's picking versions in a way you aren't picturing (one wouldn't picture.)
I'm using Ubuntu Linux 12.04 LTS on my local machine. I've installed LAMP long ago on my machine. Now I want to enable following PHP extensions:
php_zip
php_xml
php_gd2
For it first I want to check whether these PHP extensions are enabled or not. I searched a lot about how to check the installed/enabled PHP extensions but every time I found how to install these extensions on Ubuntu Linux. So can someone please let me know how should I check the enabled/disabled PHP extensions in Ubuntu Linux 12.04 LTS?
Checking for installed php modules and packages
In addition to running
php -m
to get the list of installed php modules, you will probably find it helpful to get the list of the currently installed php packages in Ubuntu:
sudo dpkg --get-selections | grep -v deinstall | grep php
This is helpful since Ubuntu makes php modules available via packages.
You can then install the needed modules by selecting from the available Ubuntu php packages, which you can view by running:
sudo apt-cache search php | grep "^php5-"
Or, for Ubuntu 16.04 and higher:
sudo apt-cache search php | grep "^php7"
As you have mentioned, there is plenty of information available on the actual installation of the packages that you might require, so I won't go into detail about that here.
Related: Enabling / disabling installed php modules
It is possible that an installed module has been disabled. In that case, it won't show up when running php -m, but it will show up in the list of installed Ubuntu packages.
Modules can be enabled/disabled via the php5enmod tool (phpenmod on later distros) which is part of the php-common package.
Ubuntu 12.04:
Enabled modules are symlinked in /etc/php5/conf.d
Ubuntu 12.04: (with PHP 5.4+)
To enable an installed module:
php5enmod <modulename>
To disable an installed module:
php5dismod <modulename>
Ubuntu 16.04 (php7) and higher:
To enable an installed module:
phpenmod <modulename>
To disable an installed module:
phpdismod <modulename>
Reload Apache
Remember to reload Apache2 after enabling/disabling:
service apache2 reload
To check if this extensions are enabled or not, you can create a php file i.e. info.php and write the following code there:
<?php
echo "GD: ", extension_loaded('gd') ? 'OK' : 'MISSING', '<br>';
echo "XML: ", extension_loaded('xml') ? 'OK' : 'MISSING', '<br>';
echo "zip: ", extension_loaded('zip') ? 'OK' : 'MISSING', '<br>';
?>
That's it.
You can view which modules (compiled in) are available via terminal through php -m
Perhaps the easiest way to see which extensions are (compiled and) loaded (not in cli) is to have a server run the following:
<?php
$ext = get_loaded_extensions();
asort($ext);
foreach ($ext as $ref) {
echo $ref . "\n";
}
PHP cli does not necessarily have the same extensions loaded.
For information on php extensions etc, on site.
Create a new file and name it info.php (or some other name.php)
Write this code in it:
<?php
phpinfo ();
?>
Save the file in the root (home)of the site
Open the file in your browser. For example: example.com/info.php
All the php information on your site will be displayed.
Search extension in
/etc/php5/apache2/php.ini
Another quick way to see if a module is enabled / disabled vs only installed or not is to use phpquery command.
For example, on my Linux Mint machine, if I want to see if xdebug is enabled I would run:
phpquery -v 8.1 -s apache2 -m xdebug
-v - is to specify for which version you want
-s - to specify the environment (apache2 or cli)
-m - the module you are interested into.
The response for the above example was (in my case):
xdebug (Enabled for apache2 by maintainer script)
Here some more examples.
I am transferring a PHP application 9running on apache) from Centos to Ubuntu. When I deploy the code on Ubuntu I get an error "Class Libmemcached not found".
When I compare phpinfo pages, I can see that the Centos one has "libmemcached" section, while the Ubuntu one has "memcached" section.
On both systems phpinfo has "memcache" (no "d" in the end) section.
It looks like my Centos PHP has "libmemcached" extension and my Ubuntu PHP doesn't. How can I download that extension? Or can I somehow just transfer the extension from my Centos system?
I found php-libmemcached repository on github ( https://github.com/kajidai/php-libmemcached ), that might be what I am looking for, but I don't know how to install it on Ubuntu.
Please help.
The libmemcached extension you are using isn't an official extension. I don't know were Centos get it from.
So I recommend to use/install the official memcached extension from PECL
and update your application.
Else you have to install the libmemcached extension from scratch with the following steps:
download from github
unpack the file
go into the new folder
phpize
./configure
make install
enable it within you php.ini
restart you webserver