tony spencer
Setting up cURL my linux server it was no problem at all, but I had a heck of a time getting cURL to work properly on my Windows test box with PHP and Apache. There are a lot of tricks scattered around on the web so here is my list of notes:
1. Only install PHP with the zip’d binaries. Don’t use the installer. I recommend deleting your current PHP installation and reinstalling with the binaries. Downloading the latest PHP has the added benefit of ensuring its compatible with the version of cURL you’ll download later. (I installed to D:\apps\php and will use that path for the rest of this example)
— set extensions_dir to d:\apps\php\extensions
— set register_globals to On
— set sessions.save_path to d:\apps\php\temp (you need to create that directory first)
3. Copy php4ts.dll (located in d:\apps\php\) to your Apache bin folder
4. Copy libeay32.dll and ssleay32.dll (located in d:\apps\php\dlls\) to c:\windows\system32
5. Download cURL for Windows at: http://curl.haxx.se/download.html. I chose the Win32 – Generic by J?Hartroth. I recommend getting the SSL version in case you ever need SSL. I unzipped cURL to d:\apps\curl and will use that path for the rest of this example
6. [SSL INSTALL ONLY] Download OpenSSL for Windows from http://curl.haxx.se/download.html. (Its near the bottom of the page). Extract libssl32.dll to d:\apps\curl
7. [Windows XP Install Only] Check to see if you have the following file: c:\windows\system32\msvcr70.dll. If not, search for it in Google and download it to system32. You may get error messages without it.
8. Uncomment the curl line in your php.ini file to enable curl: extension=php_curl.dll
9. Finally edit your Apache httpd.conf file to enable php:
— Uncomment: LoadModule php4_module d:/apps/php/sapi/php4apache2.dll
— Add Line: AddType application/x-httpd-php .php
Test with the following PHP code:
$url = “http://www.thinkgeek.com”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$returned = curl_exec($ch);
curl_close ($ch);
echo $returned;
SSL NOTE: I kept getting no response when I tried using curl with SSL urls. I found that adding the following solved the problem:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
I have read that the proper solution is to use the ca-bundle.crt file for curl to be able to verify certificates but I haven’t tried this yet:
curl_setopt($ch, CURLOPT_CAINFO, ‘drive:\pathto\ca-bundle.crt’);
Установка php with curl
To use PHP’s cURL support you must also compile PHP —with-curl[=DIR] where DIR is the location of the directory containing the lib and include directories. In the include directory there should be a folder named curl which should contain the easy.h and curl.h files. There should be a file named libcurl.a located in the lib directory.
Note: Note to Win32 Users
In order to enable this module on a Windows environment, libeay32.dll and ssleay32.dll , or, as of OpenSSL 1.1 libcrypto-*.dll and libssl-*.dll , must be present in your PATH . Also libssh2.dll must be present in your PATH . You don’t need libcurl.dll from the cURL site.
User Contributed Notes 21 notes
I already had Apache and PHP5 setup, but simply adding php5-curl and curl did *not* work. I also had to get libcurl3 and libcurl3-dev. The full command:
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
You’ll know if it works because phpinfo() will get a new section with Curl info.
Upgrading to php 5.6.9 on Windows 7 x64 curl no longer is recognised. No errors on server start package just not available and didn’t show in phpinfo.php. deplister.exe was ok
I fixed coping the following list files from php folder (in my case D:\xampp\php)
libeay32.dll
libssh2.dll
ssleay32.dll
to c:\xampp\apache\bin (or your apache\bin path), restart apache and works fine, apache’s libraries were outdated
Beginning with version 1.1.0 OpenSSL did change their libary names!
libeay32.dll is now libcrypto-*.dll (e.g. libcrypto-1_1-x64.dll for OpenSSL 1.1.x on 64bit windows)
ssleay32.dll is now libssl-*.dll (e.g. libssl-1_1-x64.dll for OpenSSL 1.1.x on 64bit windows)
You may be confused, as I was, by the instructions for installing cURL in php. The instruction «To use PHP’s cURL support you must also compile PHP —with-curl[=DIR]. » was murky to me, since I didn’t compile php when I installed it. I just copied all of the necessary files to the correct folders as described very clearly in the php manual.
I am using Windows XP and Apache with php 5.1.6. In this situation, and it may apply to php versions of 5.0 and later, all one needs to do is remove the «;» from the front of the directive extension=php_curl.dll. You should also check to make certain that libeay32.dll and ssleay32.dll are in your php directory with the other dll’s. This directory should already be in you path, so the instruction to put them in you path is not critical.
You can then run phpinfo() and you should see a heading for curl in the listing.
Succinctly, my installation of cURL consisted of removing the semi-colon in front of the ;extension=php_curl.dll line in php.ini, saving php.ini and restarting Apache. You may wish to try this if you are using php 5.0 and later and are having difficulty understanding the instructions on the cURL installation page at php.net
You dont need to copy files to use PHP CURL with Apache 2.4 — use the LoadFile directive in your apache config file instead:
LoadFile «C:/php7/libssh2.dll»
(that was all it took for me to get it work)
If you’re dense like I am, spare yourself the trouble on an Ubuntu system (probably Debian too) and.
$ sudo apt-get install php5-curl
Then feel dumb, but not as dumb as me.
If you are running on Windows with a Wampserver or alike preconfigured PHP, if you did everything that was advised (path is correct, dlls are in the System32 or the Wow64 folder, php_curl extension uncommented in the php.ini, rebooted your machine and restarted your services), and you still receive messages saying that curl is not installed :
— maybe you are running a command line script (and not a curl instruction within a web application). If yes, remember that there are 2 distinct php.ini configuration files : one for the php-cli commands (run php at command line) and one for the php instructions (run from a page in your www folder).
Wampserver’s menuitem «php.ini» only opens the webserver’s php.ini, not the php-cli one.
So it will be great to check your php-cli’s php.ini configuration file ! (you’ll find it in the php.exe’s installation folder)
You need to uncomment the extension php_curl in this php.ini file for the command lines to work with curl.
Also uncomment the php_openssl extention by the way (often used with curl).
I hope this fixed issue will help someone else 🙂
It is not necessary to always (re)compile PHP. For me it was sufficient to install php5-curl and restart Apache:
$ sudo apt-get install php5-curl
$ sudo /etc/init.d/apache2 restart
Установка php with curl
Раздел содержит информацию и подсказки, относящиеся к установке PHP на » Debian GNU/Linux.
Неофициальные сборки от третьих лиц не поддерживаются. О любых ошибках следует сообщать разработчикам Debian, но перед этим стоит проверить, возможно они уже исправлены в новых релизах, которые можно скачать на » странице загрузки.
Хотя и существует универсальная инструкция по установке PHP на Unix/Linux, в этом разделе мы рассмотрим особенности специфичные для Debian, такие как использование команд apt или aptitude . В рамках этого руководства обе эти команды рассматриваются как взаимозаменяемые.
Использование APT
Во первых, обратите внимание на то, что некоторые пакеты связаны: libapache-mod-php нужен для интеграции с Apache 2, и php-pear с PEAR.
Во-вторых, перед установкой убедитесь, что список пакетов находится в актуальном состоянии. Как правило, это делается с помощью команды apt update.
Пример #1 Пример установки Apache 2 на Debian
# apt install php-common libapache2-mod-php php-cli
APT автоматически установит модуль PHP для Apache 2 и все их зависимости и, затем, активирует их. Apache должен быть перезапущен для того, чтобы изменения вступили в силу. Например:
Пример #2 Остановка и запуск Apache после установки PHP
# /etc/init.d/apache2 stop # /etc/init.d/apache2 start
Контроль конфигурации
Изначально, PHP устанавливается только с основными модулями ядра. Если вы хотите установить дополнительные модули, такие как MySQL, cURL, GD и т.д., это также можно сделать с помощью команды apt .
Пример #3 Способы получить список дополнительных пакетов PHP
# apt-cache search php # apt search php | grep -i mysql # aptitude search php
Будет выведен список большого числа пакетов, включая несколько специфичных, таких как php-cgi, php-cli and php-dev. Определите, какие вам нужны и установите с помощью apt-get или aptitude . И, так как Debian производит проверку зависимостей, вам будет выведен запрос на их установку.
Пример #4 Установка PHP с MySQL и cURL
# apt install php-mysql php-curl
APT автоматически добавит необходимые строки в соответствующие php.ini , /etc/php/7.4/php.ini , /etc/php/7.4/conf.d/*.ini , и т.д. В зависимости от модуля, будут внесены записи типа extension=foo.so . В любом случае, чтобы эти изменения вступили в силу, необходимо будет перезапустить сервер веб-сервер.
Стандартные проблемы
- Если скрипты PHP не разбираются веб-сервером, то скорее всего это означает, что PHP не был добавлен в конфигурацию веб-сервера. На Debian это обычно /etc/apache2/apache2.conf или похожий. Смотрите документацию Debian для выяснения подробностей.
- Модуль, по-видимому, установлен, а его функции всё равно не распознаются. В таком случае убедитесь, что соответствующий ini-файл был загружен и/или веб-сервер был перезагружен после установки модуля.
- Для установки пакетов в Debian существуют две основных команды (не считая стандартных вариантов Linux): apt и aptitude . Объяснения их синтаксиса, особенностей и отличий друг от друга выходит за рамки данного руководства.
User Contributed Notes 6 notes
To refresh this document, perhaps it would be worth mentioning more modern methods to serve php content under apache httpd.
Specifically, the preferred method is now fastcgi, using either of those recipes:
While the legacy mod_php approach is still applicable for some older installations, the fastcgi method is much faster, and require much less RAM to operate, based on similar traffic patterns.
Compiling PHP on Ubuntu boxes.
If you would like to compile PHP from source as opposed to relying on package maintainers, here’s a list of packages, and commands you can run
STEP 1:
sudo apt-get install autoconf build-essential curl libtool \
libssl-dev libcurl4-openssl-dev libxml2-dev libreadline7 \
libreadline-dev libzip-dev libzip4 nginx openssl \
pkg-config zlib1g-dev
So you don’t overwrite any existing PHP installs on your system, install PHP in your home directory. Create a directory for the PHP binaries to live
STEP 2:
# download the latest PHP tarball, decompress it, then cd to the new directory.
STEP 3:
Configure PHP. Remove any options you don’t need (like MySQL or Postgres (—with-pdo-pgsql))
./configure —prefix=$HOME/bin/php-latest \
—enable-mysqlnd \
—with-pdo-mysql \
—with-pdo-mysql=mysqlnd \
—with-pdo-pgsql=/usr/bin/pg_config \
—enable-bcmath \
—enable-fpm \
—with-fpm-user=www-data \
—with-fpm-group=www-data \
—enable-mbstring \
—enable-phpdbg \
—enable-shmop \
—enable-sockets \
—enable-sysvmsg \
—enable-sysvsem \
—enable-sysvshm \
—enable-zip \
—with-libzip=/usr/lib/x86_64-linux-gnu \
—with-zlib \
—with-curl \
—with-pear \
—with-openssl \
—enable-pcntl \
—with-readline
STEP 4:
compile the binaries by typing: make
If no errors, install by typing: make install
STEP 5:
Copy the PHP.ini file to the install directory
cp php.ini-development ~/bin/php-latest/lib/
cd ~/bin/php-latest/etc;
mv php-fpm.conf.default php-fpm.conf
mv php-fpm.d/www.conf.default php-fpm.d/www.conf
STEP 7:
create symbolic links for your for your binary files
cd ~/bin
ln -s php-latest/bin/php php
ln -s php-latest/bin/php-cgi php-cgi
ln -s php-latest/bin/php-config php-config
ln -s php-latest/bin/phpize phpize
ln -s php-latest/bin/phar.phar phar
ln -s php-latest/bin/pear pear
ln -s php-latest/bin/phpdbg phpdbg
ln -s php-latest/sbin/php-fpm php-fpm
STEP 8: link your local PHP to the php command. You will need to logout then log back in for php to switch to the local version instead of the installed version
# add this to .bashrc
if [ -d «$HOME/bin» ] ; then
PATH=»$HOME/bin:$PATH»
fi