148 votes

How to get only the version number of PHP using shell commands?

Extending Jeff Schaller's answer, skip the pipeline altogether and just ask for the internal constant representation: $ php -r 'echo PHP_VERSION;' 7.1.15 You can extend this pattern to get more, or ...
bishop's user avatar
  • 3,209
52 votes
Accepted

Unix system(“unzip archive.zip”) Extracting Zip Files Silently

man unzip: -q perform operations quietly (-qq = even quieter). Ordinarily unzip prints the names of the files it's extracting or testing, the extraction methods, any ...
Ipor Sircer's user avatar
  • 14.6k
45 votes

Locating PHP extension folder using bash

Maybe you should do this: php-config --extension-dir If php-config doesn't exist, then apt-get install php-config if Ubuntu/Debian or yum install php-config if CentOS/Red Hat) That command will ...
thecinefiction's user avatar
34 votes

Locating PHP extension folder using bash

You can use this php -i | grep extension_dir
Maximiliano Gastón Ledesma's user avatar
24 votes

Print something in console in the same place of the previous echo, with a sort of negative echo

The typical way of doing this is not to erase a single character, but to go back to the start of the line using a carriage return (\r): printf "89%%"; sleep 1; printf "\r90%%\n" Note that this doesn’...
Stephen Kitt's user avatar
21 votes

How to get only the version number of PHP using shell commands?

If you've installed php via the package manager (e.g. RPM or yum), then you can query the version from there: rpm -q --queryformat="%{VERSION}" php Alternatively, you can ask php to tell you its ...
Jeff Schaller's user avatar
  • 67.3k
15 votes
Accepted

How to get only the version number of PHP using shell commands?

On my system: $> php -v | grep ^PHP | cut -d' ' -f2 7.0.32-0ubuntu0.16.04.1 as grep PHP matches every PHP string it encounters. The ^PHP means "match only the string 'PHP' when it is at the ...
Daniele Santi's user avatar
12 votes

Is there any command to enable/disable a php extension from command line?

On Lubuntu I needed pdo_sqlite. Enable manually: $ sudo php5enmod pdo_sqlite If doesn't work check: $ ls /etc/php5/mods-available The result list was missing pdo_sqlite.ini. We have to install it....
Vladimir Vukanac's user avatar
10 votes
Accepted

How to extract under linux some capturing groups using command line in a php/preg fashion?

pcregrep -io1 'something="(\w+)"' myfile.txt (-i for case insensitive matching, -o1 to print the first capture group). GNU grep supports a -P (if built with perl compatible regex support) and -o. ...
Stéphane Chazelas's user avatar
10 votes

SELinux is preventing NGINX from writing via PHP-FPM

setsebool -P httpd_can_network_connect on will permanently enable the flag which should solve your problem.
13dimitar's user avatar
  • 1,529
10 votes

Unix system(“unzip archive.zip”) Extracting Zip Files Silently

From the unzip man page: -q perform operations quietly (-qq = even quieter). Ordinarily unzip prints the names of the files it's extracting or testing, the extraction methods, any file or zipfile ...
Artemis's user avatar
  • 231
9 votes

SSMTP not sending mails "Cannot open mailhub:25" (tldr : file permissions when user is www-data)

SSMTP was NOT giving any hint or nothing except Cannot open mailhub:25. After HOURS reading SSMTP source code, trying every possible steps to reproduce what SSMTP was doing, I finally found it... ...
Charaf's user avatar
  • 321
8 votes

Failed to connect to MySQL: No such file or directory

I believe the issue here is that localhost is not your database host. If that PHP script is running in the "www" docker container, localhost most likely does not have a listening MySQL server. IIRC, ...
GracefulRestart's user avatar
8 votes
Accepted

apt: What's the difference between "apt install php" and "apt install php-defaults"?

The difference is that apt install php-defaults doesn’t work, because php-defaults is a source package, not a binary package. A source package contains the source code and packaging descriptors ...
Stephen Kitt's user avatar
8 votes
Accepted

How to remove cron task that deletes PHP sessions

The phpsessionclean scripts as delivered by upstream Debian will either use cron if there is no systemd present, or will use systemd for scheduling if it is available. This is apparent in the cronjob ...
GracefulRestart's user avatar
7 votes

Locating PHP extension folder using bash

You can search for the xdebug file extension: find $(php -r 'echo ini_get("extension_dir");') -type f -name 'xdebug.so' Or just get the value: php -r 'echo ini_get("extension_dir");...
William Desportes's user avatar
7 votes

Is there any command to enable/disable a php extension from command line?

You have to use -n and then to append each needed extension using -dextension Example: php -n -dextension=json.so -dextension=phar.so composer.phar update
Cobuz Alexandru's user avatar
7 votes
Accepted

accessing path from outside the root with symlink

The basic idea is that you can't access files outside the document root. That's the point of the document root. There are several protections that prevent Apache from following symlinks outside the ...
Gilles 'SO- stop being evil''s user avatar
7 votes
Accepted

Php extensions on centos7 php7.x

Solved by doing yum --enablerepo=epel install php-pecl-zip
what's user avatar
  • 193
7 votes

How to install Composer with Ansible?

Do ansible-galaxy install geerlingguy.composer This will add geerlingguy.composer to your roles, which you can then add to your playbook.
the's user avatar
  • 900
7 votes
Accepted

Who is eating data? Xargs?

To see whether xargs makes a difference, run the command lines that it runs. Here are a couple of ways to see exactly what it runs, while not risking changing what it runs: Write a script called php ...
Gilles 'SO- stop being evil''s user avatar
7 votes
Accepted

PHP security updates in Debian after PHP version EOL

The PHP packages are covered as part of Debian Stretch LTS, until June 2022, on the LTS architectures (i386, amd64, arm64, armel and armhf). Ondřej Surý backports security fixes from later releases, ...
Stephen Kitt's user avatar
6 votes

Remove injected code from all php files in directory on Ubuntu

As someone who's had their PHP-based front end breached, code injected into it, and took a stab at trying to clean up the injected code themselves (after restoring the site from a clean tarball of the ...
Thomas Ward's user avatar
  • 2,718
6 votes
Accepted

cat filename | cut -f2 | head -1 > newfile contains more characters than expected

Indeed, that's your \n, that is counted by strlen In PHP, you have rtrim (http://php.net/manual/fr/function.rtrim.php) to remove all \n, \t, \r, \0 & \x0B from the right end of your string.
SYN's user avatar
  • 2,873
6 votes

Installing PHP 5.3 on Debian Stretch (9)

I've stumbled across a similar problem and managed to make it work. I had to install a server with debian 9/nginx/php5.4, so while it does not exactly match your prerequisites, I assume the solution ...
Arza's user avatar
  • 61
6 votes
Accepted

Installing PHP 5.3 on Debian Stretch (9)

One week later I managed to get it working but in a different way. I stopped messing with the host and started to learn how Docker can save my life. This post gave me the key: Docker - Run Apache on ...
raguchi's user avatar
  • 159
6 votes

How to get only the version number of PHP using shell commands?

There are different ways, I like to use look behind: php -v | grep -Po '(?<=^PHP )[^ ]+' or php -v | grep -Po '(?<=PHP )([0-9.]+)'
Ravexina's user avatar
  • 2,648
6 votes

Changing PHP's post_max_size and upload_max_filesize with Ansible

Instead of regex use https://docs.ansible.com/ansible/latest/modules/ini_file_module.html - name: set PHP memory limit become: yes ini_file: path: /etc/php.ini section: PHP option: ...
Devin Zuczek's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible