I have recently updated my Ubuntu version from 16.04 to 18.0.4 with PHP version upgraded to 7.2. I haven't been able to log on to my Wordpress websites due to the following error:
Your php installation appears to be missing the mysql extension which is required by Wordpress
What I have tried:
sudo apt-get update & sudo apt-get -y install php-mysql
sudo update-alternatives --set php /usr/bin/php7.2
while checking if the last one worked with wp --info, I also got the following warning:
PHP Warning: PHP Startup: Unable to load dynamic library 'mysqli' (tried: /usr/lib/php/20170718/mysqli (/usr/lib/php/20170718/mysqli: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/mysqli.so (/usr/lib/php/20170718/mysqli.so: undefined symbol: mysqlnd_global_stats)) in Unknown on line 0
These were in fact missing from php.ini. I added both
extension=/usr/lib/php/20170718/mysqli
and
extension=/usr/lib/php/20170718/mysqlnd.
The PHP warning disappeared, but the MySQL extension still seems to be missing.
The php.ini file is located at /etc/php/7.2/cli/php.ini. I restarted apache after each change I made.
Would you have any other solution that might work?
1.First check which version install in your pc by using this command :
php -v
2.for example if you getting 7.2 run like this (based on php version )
sudo apt-get install php7.2-common php7.2-mysql
3.After install MySql restart apache server
sudo service apache2 restart
I am adding my answer here - though the circumstances are slightly different. I upgraded my Debian installation - and in the process php was upgraded from php 5 to php 7.0
It turns out that apache2 was still loading the php5 module and not the php7.0 module.
I needed to run the below:
sudo a2dismod php5
sudo a2enmod php7.0
sudo systemctl restart apache2
Subsequently, my web pages loaded up.
i solved this type of error in my .htaccess using the below code on a shared server that uses cpanel
# END WordPress
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php71” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php71 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
A combination of the solutions above helped me.
After updating I couldn't reach my sites anymore, so I altered the code like this:
sudo a2dismod php*
sudo a2enmod php8.0
sudo systemctl restart apache2
I finally managed to find the solution to my problem.
This particular project runs on PHP 7.0., so I need to switch to the older version of PHP in order to work on it.
For AWS EC2 ubuntu Nginx Server
1.First check which version install in your pc by using this command :
php -version or which php
2.for example if you getting 7.4.33 run like this (based on php version )
apt install php7.4-mysql
3.After install MySql restart apache server
sudo systemctl restart apache2
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
today I upgraded ubuntu 14.10 to 15.04 and xdebug is not working anymore. I use eclipse Luna Service Release 2.
I've tried reinstalling xdebug through pecl, apt-get, even manual install following http://xdebug.org/wizard.php instructions (pasting my phpinfo() output).
I have xampp, in /opt/lampp directory.
I've tried several locations for "zend_extension" in /opt/lampp/etc/php.ini such as zend_extension=/usr/lib/php5/20131226/xdebug.so and zend_extension =/opt/lampp/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so
When I hit debug on eclipse, the browser receives the order, and the parameters ?XDEBUG_SESSION_START=ECLIPSE_DBGP&KEY= are included in the url, but the execution will not stop on any breakpoint.
When I run phpinfo() xdebug is not showing as an installed module.
any hints?
I removed the phpinfo() output for clarification after posting the answer.
Finally I found no solution, so I had to remove all the lamp package, and I reinstalled everything as independent modules following this tutorial: http://www.unixmen.com/how-to-install-lamp-stack-on-ubuntu-15-10/, then I did this to install xdebug:
1.- Install xdebug extension for PHP
$ sudo apt-get install php5-xdebug
2.- Check the location of "xdebug.so" module, which is kept under "/usr/lib/php5/20131226", where the number depends on the PHP version.
3.- The installation creates a configuration file "/etc/php5/mods-available/xdebug.ini" with the following line (otherwise, create one):
zend_extension=xdebug.so
NOTE: in the previous version, you need to specify the full-path filename, e.g., "zend_extension=/usr/lib/php5/20121212/xdebug.so".
Include the following lines into "xdebug.ini" to enable remote debugging from Eclipse PDT:
xdebug.remote_enable = On
xdebug.remote_port = 9000
xdebug.remote_host = 127.0.0.1
Recall that Apache loads PHP configuration files "/etc/php5/apache2/php.ini" and "/etc/php5/apache2/conf.d/*.ini". To enable the above xdebug configuration file, create the following symlink in "/etc/php5/apache2/conf.d":
$ cd /etc/php5/apache2/conf.d
$ sudo ln -s ../../mods-available/xdebug.ini 20-xdebug.ini
$ ls -l
lrwxrwxrwx 1 root root 31 Sep 11 19:42 20-xdebug.ini -> ../../mods-available/xdebug.ini
4.- Check PHP configuration file "/etc/php5/apache2/php.ini" for the following settings:
; Turn on the error display for development system,
; but not for production system.
display_errors = On
; Format error in HTML
html_errors = On
5.- Restart the Apache2:
$ sudo service apache2 restart
And it works like a charm
For now Xdebug (Please only use uptil Xdebug 2.6, because later versions had some issues with debugging); only work up to php 7.2 (i.e. less than 7.3). So if you had any other version installed like php 7.3 or 7.4 then you had to also install php 7.2 along side your current php version (mostly because now by default latest version is installed through apt). and then update in between alternatives.
To set PHP 7.0 as the default, run
update-alternatives --set php /usr/bin/php7.0
To set PHP 7.2 as the default, run
update-alternatives --set php /usr/bin/php7.2
To set PHP 7.3 as the default, run
update-alternatives --set php /usr/bin/php7.3
To set PHP 7.4 as the default, run
update-alternatives --set php /usr/bin/php7.4
Before we can configure Apache to use PHP 7.2, we need to disable the new (or old) version of PHP by typing
a2dismod php7.4
Now enable the newly installed PHP 7.2 version with the following command:
a2enmod php7.2
Restart the Apache web server for the changes to take effect:
sudo systemctl restart apache2
I try PHP Post Request inside a POST Request thinking it might be useful for me. My code is given below:
$sub_req_url = "http://localhost/index1.php";
$ch = curl_init($sub_req_url);
$encoded = '';
// include GET as well as POST variables; your needs may vary.
foreach($_GET as $name => $value) {
$encoded .= urlencode($name).'='.urlencode($value).'&';
}
foreach($_POST as $name => $value) {
$encoded .= urlencode($name).'='.urlencode($value).'&';
}
// chop off last ampersand
$encoded = substr($encoded, 0, strlen($encoded)-1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_exec($ch);
curl_close($ch);
from the index.php file and index2.php is another file in the same directory and when I open the page I get the following error in my error.log file:
[Sat Dec 18 15:24:53 2010] [error] [client ::1] PHP Fatal error: Call to undefined function curl_init() in /var/www/testing1/index.php on line 5
What I want to do is to have a reservation form that send post request. Then I want to process post values and send again the post request to paypal.
You need to install CURL support for php.
In Ubuntu you can install it via
sudo apt-get install php5-curl
If you're using apt-get then you won't need to edit any PHP configuration, but you will need to restart your Apache.
sudo /etc/init.d/apache2 restart
If you're still getting issues, then try and use phpinfo() to make sure that CURL is listed as installed. (If it isn't, then you may need to open another question, asking why your packages aren't installing.)
There is an installation manual in the PHP CURL documentation.
For Windows, if anybody is interested, uncomment the following line (by removing the ;) from php.ini
;extension=php_curl.dll
Restart apache server.
I got it working in ubuntu 16.04 by following steps.My php version was 7.0
sudo apt-get install php7.0-curl
sudo service apache2 restart
i got it from this link check here for more details
For Ubuntu:
add extension=php_curl.so to php.ini to enable, if necessary. Then sudo service apache2 restart
this is generally taken care of automatically, but there are situations - eg, in shared development environments - where it can become necessary to re-enable manually.
The thumbprint will match all three of these conditions:
Fatal Error on curl_init() call
in php_info, you will see the curl module author (indicating curl is installed and available)
also in php_info, you will see no curl config block (indicating curl wasn't loaded)
In my case, in Xubuntu, I had to install libcurl3 libcurl3-dev libraries. With this command everything worked:
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
Just adding my answer for the case where there are multiple versions of PHP installed in your system, and you are sure that you have already installed the php-curl package, and yet Apache is still giving you the same error.
curl_init() undefined even if php-curl is enabled in Php 7.
Had this problem but found the answer here: https://askubuntu.com/questions/1116448/cannot-enable-php-curl-on-ubuntu-18-04-php-7-2
Had to:
sudo a2dismod php7.0
And:
sudo a2enmod php7.2
Then:
sudo service apache2 restart
This was after a system upgrade to next version of Ubuntu. All the other answers I found were stale, due to a bad cert apparently on the PPA most of them pointed out, but would probably not have worked anyway. The real issue was disabling the old versions of php, apparently.
Found the solution here:
https://askubuntu.com/questions/1116448/cannot-enable-php-curl-on-ubuntu-18-04-php-7-2
To fix this bug, I did:
In php.ini file, uncomment this line: extension=php_curl.dll
In php.ini file, uncomment this line: extension_dir = "ext"
I restarted NETBEANS, as I was using Built-in server
I got this error using PHP7 / Apache 2.4 on a windows platform. curl_init worked from CLI but not with Apache 2.4. I resolved it by adding LoadFile directives for libeay32.dll and ssleay32.dll:
LoadFile "C:/path/to/Php7/libeay32.dll"
LoadFile "C:/path/to/Php7/ssleay32.dll"
LoadFile "C:/path/to/Php7/php7ts.dll"
LoadModule php7_module "C:/path/to/Php7/php7apache2_4.dll"
This answer is for https request:
Curl doesn't have built-in root certificates (like most modern browser do). You need to explicitly point it to a cacert.pem file:
curl_setopt($ch, CURLOPT_CAINFO, '/path/to/cert/file/cacert.pem');
Without this, curl cannot verify the certificate sent back via ssl. This same root certificate file can be used every time you use SSL in curl.
You can get the cacert.pem file here: http://curl.haxx.se/docs/caextract.html
Reference PHP cURL Not Working with HTTPS
Step 1 :
C:/(path to php folder)/php.ini
enable extension=php_curl.dll
(remove the ; at the end of the line)
Step 2 :
Add this to Apache/conf/httpd.conf (libeay32.dll, ssleay32.dll, libssh2.dll find directly in php7 folder)
# load curl and open ssl libraries
LoadFile "C:/(path to php folder)/libeay32.dll"
LoadFile "C:/(path to php folder)/ssleay32.dll"
LoadFile "C:/(path to php folder)/libssh2.dll"
On newer versions of PHP on Windows, like PHP 7.x, the corresponding configuration lines suggested on previous answers here, have changed. You need to uncomment (remove the ; at the beginning of the line) the following line:
extension_dir = "ext"
extension=curl
(Trying to get Curl working via PHP and Apache on Windows...)
I kept getting an error saying:
Call to undefined function 'curl_init()'
I made sure I had enabled curl with this line in my php.ini file:
extension=php_curl.dll
I made sure the extension_dir variable was being set properly, like this:
extension_dir = "ext"
I was doing everything everyone else said on the forums and curl was not showing up in my call to phpinfo(), and I kept getting that same error from above.
Finally I found out that Apache by default looks for php.ini in the C:\Windows folder. I had been changing php.ini in my PHP installation folder. Once I copied my php.ini into C:\Windows, everything worked.
Took me forever to figure that out, so thought I'd post in case it helps someone else.
For PHP 7 and Windows x64
libeay32.dll, libssh2.dll and ssleay32.dll should not be in apache/bin and should only exist in php directory and add php directory in system environment variable. This work for me.
Obvisouly in php.ini you should have enable php_curl.dll as well.
RusAlex answer is right in that for Apache you have to install and enable curl and restart your apache service:
sudo apt-get install php5-curl
sudo service apache2 restart
On my Ubuntu Server with nginx and php5-fpm I however ran into the following problem. I had to restart nginx and php5-fpm like so:
sudo service nginx restart
sudo service php5-fpm restart
But I had non-working php5-fpm processes hanging around, which apparently is a bug in ubuntu https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1242376
So I had to kill all idle php5-fpm processes to able to restart php5-fpm so that the curl module is actually loaded
sudo kill <Process Id of php5-fpm Process)
function curl_int();
cause server error,install sudo apt-get install php5-curl
restart apache2 server .. it will work like charm
For linux you can install it via
sudo apt-get install php5-curl
For Windows(removing the ;) from php.ini
;extension=php_curl.dll
Restart apache server.
On Ubuntu 18.04 these two commands solve my this problem.
sudo apt-get install php5.6-curl //install curl for php 5.6
sudo service apache2 restart //restart apache
Seems you haven't installed the Curl on your server.
Check the PHP version of your server and run the following command to install the curl.
sudo apt-get install php7.2-curl
Then restart the apache service by using the following command.
sudo service apache2 restart
Replace 7.2 with your PHP version.
I also faced this issue. My Operating system is Ubuntu 18.04 and my PHP version is PHP 7.2.
Here's how I solved it:
Install CURL on Ubuntu Server:
sudo apt-get install curl
Add the PHP CURL repository below to your sources list:
sudo add-apt-repository ppa:ondrej/php
Refresh your package database
sudo apt update
Install PHP-curl 7.2
sudo apt install php7.2-fpm php7.2-gd php7.2-curl php7.2-mysql php7.2-dev php7.2-cli php7.2-common php7.2-mbstring php7.2-intl php7.2-zip php7.2-bcmath
Restart Apache Server
sudo systemctl restart apache2
That's all.
I hope this helps
Yet another answer ...
If you land here in Oct 2020 because PHP on the command line (CLI) has stopped working, guess what ... some upgrades will move you to a different/newer version of PHP silently, without asking!
Run:
php --version and you might be surprised to see what version the CLI is running.
Then run:
ll /usr/bin/php and you might be surprised to see where this is linking to.
It's best to reference the SPECIFIC version of PHP you want when calling the PHP binary directly and not a symbolic link.
Example:
/usr/bin/php7.3 will give you the exact version you want. You can't trust /usr/bin/php or even just typing php because an upgrade might switch versions on you silently.
I have solved this issue in Ubuntu 20.04.1 LTS and PHP Version 7.4.3
Update the package index:
sudo apt-get update
Install php7.4-curl deb package:
sudo apt-get install php7.4-curl
This worked for me with raspian:
sudo apt update && sudo apt upgrade
sudo apt install php-curl
finally:
sudo systemctl restart apache2
or:
sudo systemctl restart nginx
To install the last version of php-curl on Ubuntu, use this:
sudo apt-get install php-curl -y
So I recently change to ubuntu and I am trying to setup my environment again and I manage to install LAMP and phpmyadmin and phpstorm.
But what I can't mange to do is to run the php script from phpStorm when I try to run the program the page gives me a "502 Bad gateway" error and when I go back on phpStorm it tells me that php-cgi was not found.
I have tried to fix the problem but couldn't find any solid answer and I am so confused right now
Also I have successfully added the php interpreter and the xDebug
on linux ubuntu
For PHP5: sudo apt-get install php5-cgi
For PHP7: sudo apt-get install php7.0-cgi
I faced with the same problem. After replacing /usr/bin/php5-cgi with a little shell script I found that error
Host 'localhost' has multiple addresses. You must choose one
explicitly! Couldn't create FastCGI listen socket on port
localhost:56468
After commenting 127.0.0.1 localhost in /etc/hosts the problem seems to be solved.
After commenting IPv6 hosts the problem seems to be solved:
# The following lines are desirable for IPv6 capable hosts
# ::1 localhost ip6-localhost ip6-loopback
# ff02::1 ip6-allnodes
# ff02::2 ip6-allrouters
for mac:
install XAMPP (it's easy and straight forvard) it comes with apache and php interpreter
in phpstorm in settings ->php -> interpreter choose path /Applications/XAMPP/bin/php
phpstorm in settings -> build, ... -> Deployment add in place server, url root localhost
More info can be found on jetbrains web page
This helped me to solve this problem and run php by clicking on web browser icon inside phpstorm.
and don't forget to turn on apache in xampp --> manage servers!)
If it's not already done install Homebrew :
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Now, that we've Homebrew, tap php repositories by entering this on your terminal :
brew tap josegonzalez/php
brew tap homebrew/dupes
Check what options are available for PHP 5.4 :
brew options php54
Now install/build PHP 5.4 with some option (in your case PHP-FPM with CGI) :
brew install php54 --with-fpm --with-debug --with-cgi --with-libmysql --with-homebrew-curl
brew install fastcgi
Note : If you're not going to use Apache add --without-apache, if you need others things, just check the options and add what you need
Now, check if PHP-FPM is enable by typing this in your terminal :
php-fpm -v
If you get this :
PHP 5.4.24 (fpm-fcgi) Copyright (c)
1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013
Zend Technologies
You just installed PHP with FCGI like a boss..
Found it Here
Basically the who page says to do this.
Download the interpreter thing oh php from php.net.
Do make install
Make a file called newpath.txt and add to it
PATH=~/custom/php5/bin:$PATH
export PATH
Type cat newpath.txt >> .profile
I will make a youtube video and upload it.
I also experienced the same problem before, however to have the right PHP version installed for your current version is the first step, then before starting the IDE, ensure that you have the php7.x-cgi version installed
open the terminal and input
sudo apt update && sudo apt install php7.x-cgi
replace the x with the version number, then after that you need to configure your IDE to find the path to your PHP installation directory
In the "PHP-CGI Server" tab in phpStorm you see the error:
/usr/bin/php-cgi -e -b localhost:52109
Host 'localhost' has multiple addresses. You must choose one explicitly!
Couldn't create FastCGI listen socket on port localhost:52109
PHP-CGI Server terminated
There curently seems not to be any fix for this known bug: https://youtrack.jetbrains.com/issue/WI-24373
Commenting out either the IPv4 or the IPv6 address for localhost in /etc/hosts (on Linux) is a workaround.
I also had this problem. It depends on your version of php that you want to use it as interpreter in your PhpStorm.
This error message shows that PhpStorm needs to CGI binary to execute your code.
I'm using Ubuntu 18.04 and PHP version that I have used is 7.2.
You need to install modules based on your application requirements. So you use this following command to search available PHP 7 modules in the package repository:
sudo apt-cache search php7*
Now you can see all of available modules (also for cgi) in repository. Now You must install the required PHP modules on your system as below command. Make sure to install packages for correct PHP version by specifying the version with the package name. Without defining the package version, it will install the latest package. E.g. for me, I need php7.2-cgi :
sudo apt install php7.2-cgi
Now cgi is installed. You must restart PhpStorm and test it again. It works well for me.