云服务器 ECS 产品 PHP 环境开启 openssl

  • A+
所属分类:Linux
高性能企业级服务器首台5折

下载 PHP 源码

需要下载和使用的 php 同版本的 php 源码,下载到 /var/www/php5(根据实际情况调整具体目录)目录下。

  1. 1
    <span class="pln"><span class="hljs-built_in">cd</span> </span><span class="pun">/</span><span class="pln">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">php5</span>
  2. 1
    <span class="pln">wget http</span><span class="pun">://</span><span class="pln">mirrors</span><span class="pun">.</span><span class="pln">sohu</span><span class="pun">.</span><span class="pln">com</span><span class="pun">/</span><span class="pln">php</span><span class="pun">/</span><span class="pln">php</span><span class="pun">-</span><span class="lit">5.5</span><span class="pun">.</span><span class="lit">7.tar</span><span class="pun">.</span><span class="pln">gz</span>

解压并进入 PHP 的 openssl 扩展模块目录

  1. 1
    <span class="pln">tar zxvf php</span><span class="pun">-</span><span class="lit">5.5</span><span class="pun">.</span><span class="lit">7.tar</span><span class="pun">.</span><span class="pln">gz</span>
  2. 1
    <span class="pln"><span class="hljs-built_in">cd</span> php</span><span class="pun">-</span><span class="lit">5.5</span><span class="pun">.</span><span class="lit">7</span><span class="pun">/</span><span class="pln">ext</span><span class="pun">/</span><span class="pln">openssl</span><span class="pun">/</span>

编译 openssl 扩展

  1. 1
    <span class="pun">/</span><span class="pln">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">php5</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">phpize </span><span class="com"><span class="hljs-comment"># 这里为自己的phpize路径,如果找不到,使用whereis phpize查找。</span></span>
  2. 1
    <span class="com"><span class="hljs-comment"># 执行后,发现错误 无法找到config.m4 ,config0.m4就是config.m4。直接重命名</span></span>
  3. 1
    <span class="pln">mv config0</span><span class="pun">.</span><span class="pln">m4 config</span><span class="pun">.</span><span class="pln">m4</span>
  4. 1
    <span class="pun">/</span><span class="pln">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">php5</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">phpize </span>
  5. 1
    <span class="pun">./</span><span class="pln">configure </span><span class="pun">--</span><span class="pln">with</span><span class="pun">-</span><span class="pln">openssl </span><span class="pun">--</span><span class="pln">with</span><span class="pun">-</span><span class="pln">php</span><span class="pun">-</span><span class="pln">config</span><span class="pun">=/</span><span class="pln">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">php5</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">php</span><span class="pun">-</span><span class="pln">config </span>
  6. 1
    <span class="pln">make</span>
  7. 1
    <span class="pln">make install</span>

安装完成后,会返回一个.so文件(openssl.so)的目录。在此目录下把 openssl.so 文件拷贝到你在 php.ini 中指定的 extension_dir 下(在 php.ini 文件中查找:extension_dir =),这里的目录是 var/www/php5/lib/php/extensions 。

修改 php.ini 文件并重启 Apache

编辑php.ini文件,在文件最后添加

  1. 1
    <span class="pln">extension</span><span class="pun">=</span><span class="pln">openssl</span><span class="pun">.</span><span class="pln">so</span>

重启 Apache

  1. 1
    <span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd"><span class="hljs-built_in">local</span></span><span class="pun">/</span><span class="pln">apache2</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">apachectl restart</span>

 

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: