Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Try Open Swoole with Docker" tutorial docker build fails: "fatal error: curl/curl.h: No such file or directory" #61

Open
life5ign opened this issue Oct 19, 2023 · 3 comments

Comments

@life5ign
Copy link

I copied the Dockerfile and built it as instructed on https://openswoole.com/docs/get-started/try-docker

Upon build, I got the error:

#0 21.41  g++ -I. -I/tmp/ext-openswoole -I/tmp/ext-openswoole/include -I/tmp/ext-openswoole/main -I/tmp/ext-openswoole -I/usr/local/include/php -I/usr/local/include/php/main
 -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/tmp/ext-openswoole -I/tmp/ext-openswoole/i
nclude -I/tmp/ext-openswoole/ext-src -I/tmp/ext-openswoole/thirdparty/hiredis -DHAVE_CONFIG_H -g -O2 -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations 
-std=c++11 -DENABLE_PHP_SWOOLE -DZEND_COMPILE_DL_EXT=1 -c /tmp/ext-openswoole/ext-src/swoole_curl.cc -MMD -MF ext-src/swoole_curl.dep -MT ext-src/swoole_curl.lo  -fPIC -DPIC
 -o ext-src/.libs/swoole_curl.o                                                                                                                                              
#0 21.53 In file included from /tmp/ext-openswoole/ext-src/swoole_curl.cc:17:                                                                                                
#0 21.53 /tmp/ext-openswoole/ext-src/php_swoole_curl.h:25:10: fatal error: curl/curl.h: No such file or directory
#0 21.53    25 | #include <curl/curl.h>                                                                                                                                      
#0 21.53       |          ^~~~~~~~~~~~~                                                                                                                                      
#0 21.53 compilation terminated.                                                                                                                                             
#0 21.53 make: *** [Makefile:248: ext-src/swoole_curl.lo] Error 1                                                                                                            
------                                                                                                                                                                       
Dockerfile:11                                                                                                                                                                
--------------------                                                                                                                                                         
  10 |                                                                                                                                                                       
  11 | >>> RUN cd /tmp && git clone https://github.com/openswoole/ext-openswoole.git && \                                                                                    
  12 | >>>     cd ext-openswoole && \                                                 
  13 | >>>     git checkout v22.0.0 && \                                                                                                                                     
  14 | >>>     phpize  && \                                                                                                                                                  
  15 | >>>     ./configure --enable-openssl --enable-hook-curl --enable-http2 --enable-mysqlnd && \                                                                          
  16 | >>>     make && make install                                                                                                                                          
  17 |                                                                                
--------------------                                                                                                                                                         
ERROR: failed to solve: process "/bin/sh -c cd /tmp && git clone https://github.com/openswoole/ext-openswoole.git &&     cd ext-openswoole &&     git checkout v22.0.0 &&    
 phpize  &&     ./configure --enable-openssl --enable-hook-curl --enable-http2 --enable-mysqlnd &&     make && make install" did not complete successfully: exit code: 2
@pistej
Copy link

pistej commented Oct 20, 2023

d u have php-curl ext installed?

maybe try use pear/pecl installation https://openswoole.com/docs/get-started/installation#pecl-configuration-options-for-open-swoole

@KelseySheely
Copy link

It doesn't look like php-curl is the solution, but rather libcurl4-openssl-dev.

According to https://openswoole.com/docs/get-started/common-install-errors#missing-libcurl-errors, that library is required if openswoole is to be compiled with --enable-hook-curl. Adding that to the Dockerfile allowed it to build for me.

After getting the build to work, I've noticed that running the example server.php does not end up allowing the host to connect at 127.0.0.1. I replaced 127.0.0.1 with 0.0.0.0 in the server.php and it solved that issue.

In summary, my working Dockerfile:

FROM php:8.2.0-cli

RUN apt-get update && apt-get install vim -y && \
    apt-get install openssl -y && \
    apt-get install libssl-dev -y && \
    apt-get install libcurl4-openssl-dev -y && \
    apt-get install wget -y && \
    apt-get install git -y && \
    apt-get install procps -y && \
    apt-get install htop -y

RUN cd /tmp && git clone https://github.com/openswoole/ext-openswoole.git && \
    cd ext-openswoole && \
    git checkout v22.0.0 && \
    phpize  && \
    ./configure --enable-openssl --enable-hook-curl --enable-http2 --enable-mysqlnd && \
    make && make install

RUN touch /usr/local/etc/php/conf.d/openswoole.ini && \
    echo 'extension=openswoole.so' > /usr/local/etc/php/conf.d/zzz_openswoole.ini

RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64
RUN chmod +x /usr/local/bin/dumb-init

RUN apt-get autoremove -y && rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["/usr/local/bin/dumb-init", "--", "php"]

And my server.php

<?php

use OpenSwoole\Http\Server;
use OpenSwoole\Http\Request;
use OpenSwoole\Http\Response;

$server = new OpenSwoole\HTTP\Server("0.0.0.0", 9501);

$server->on("Start", function(Server $server)
{
    echo "OpenSwoole http server is started at http://127.0.0.1:9501\n";
});

$server->on("Request", function(Request $request, Response $response)
{
    $response->header("Content-Type", "text/plain");
    $response->end("Hello World\n");
});

$server->start();

@life5ign
Copy link
Author

@KelseySheely , thank you, that worked for me; much appreciated. I'm going to leave this open so that the openswoole team can update their documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants