dongtang8678 2015-12-07 17:44
浏览 118

获取当前运行版本的PHP版本

I have just built 3 different versions of PHP from source on an Ubuntu server (alongside NGINX and MySQL 5.7). I am looking for a way to run php --ini for the currently running version. I know I have to add the location to the file PATH in .bashrc so I don't have to add the full path.

I have added this to my .bashrc which allows me to get the currently running PHP version, which then allows me to run the command:

# parallels@ubuntu:~$ ps aux | grep php
# root      6948  0.0  0.2 153724  4620 ?        Ss   16:48   0:00 php-fpm: master process (/opt/php-7.0.0/etc/php-fpm.conf)

PHP_VERSION=$(ps aux | grep -o php-[[:digit:]].[[:digit:]].[[:digit:]])
export PATH="/bin:/usr/bin:/opt/$PHP_VERSION/bin:/sbin"

It works, but I am a bash novice and I'm thinking their might be a different way to do it. Would I be correct?

  • 写回答

3条回答 默认 最新

  • douye1876 2016-12-10 00:12
    关注
    PHP_VERSION=$(php -v | tail -r | tail -n 1 | cut -d " " -f 2 | cut -c 1-3)
    cd /usr/local/etc/php/$PHP_VERSION/
    # cd /usr/local/etc/php/7.1/
    
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错