Yes, you need to download dev package of openssl (sources/headers), sources of PHP and configure it with following keys:
You also may want to use other keys like
--with-gd -- check with documentation at PHP Manual > Appendices > Configure options and installation manuals for every module your want to compile it with like GD2 or Curl
NOTE: You will need to download dev-packages of every module you are going to compile - it consumes noticable amount of time, plan accordingly.
NOTE 2: Keep in mind that all modules you are going to compile into your own build of PHP will be accessible through its functions (like image manipulation, https/curl requests etc), so it is highly recommended to use only stable and proven versions of modules not to add a new vulnerability to your web-site.
** UPDATE **
./configure --with-openssl --with-openssl-dir=/usr/bin \ --with-zlib=[DIR] \ --enable-zip \ --enable-opcache \ --with-pdo-mysql=[DIR] \ --with-mysqli=[DIR] \ --with-mysql-sock=/var/lib/mysql/mysql.sock \ --with-mcrypt=[DIR] \ --enable-mbstring \ --enable-intl \ --with-png-dir=[DIR] \ --with-jpeg-dir=[DIR] \ --with-gd=[DIR] \ --with-curl=[DIR] \ --with-bz2=[DIR] \ --enable-bcmath
[DIR]'s can be discovered automatically, but I faced a lot of situations when they are different from what PHP expects.
simplexml are enabled by default starting with PHP 5.1.2
pdo-sqlite are enabled by default starting with PHP 5.3.0
--enable-gd-native-ttf is deprecated starting PHP 5.5.0, removed in PHP 7.2.0.