[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2790
  • Last Modified:

How to enable CLI version of PHP on CentOS

I have a dedicated server running CentOs with Plesk.  It has PHP version 4.3.9.

I need to enable the CLI version of PHP to support one of my clients websites.  According to the PHP docs, this version of PHP should have CLI support enabled by default, unless it is disabled in the configure settings when built.  I have checked my configure output in phpinfo and it is not disabled, however the script to test for the CLI fails.

Could it be disabled somewhere else?  Do I need to install another PHP somewhere else to act as PHP CLI, separate from my existing PHP web server?

Doing a full download and compile is not an option - apparently it could break the Plesk install.

I have tried installing another PHP (4.4.9) in a separate dir (usr/bin/php_cli) but when I do php -v I get a load of errors, followed by:

PHP 4.4.9 (cgi) (built: Feb 16 2009 20:17:55)

However phpinfo in a browser still says 4.3.9.

I am worried about screwing this up completely, which is bad as the box is in use by many clients websites.  Any advice appreciated.
0
Ross Edwards
Asked:
Ross Edwards
  • 7
  • 6
1 Solution
 
Maciej SsysadminCommented:
Try running (with that 'old' version of php - 4.3.9):
php -r "phpinfo();"
What is the effect?
If this doesn't work - run the same command with your new php - 4.4.9 and write what was the effect.
0
 
Ross EdwardsTechnical DirectorAuthor Commented:
PHP Notice:  Constant MYSQL_ASSOC already defined in Unknown on line 0
PHP Notice:  Constant MYSQL_NUM already defined in Unknown on line 0
PHP Notice:  Constant MYSQL_BOTH already defined in Unknown on line 0
PHP Notice:  Constant MYSQL_CLIENT_COMPRESS already defined in Unknown on line 0
PHP Notice:  Constant MYSQL_CLIENT_INTERACTIVE already defined in Unknown on line 0
PHP Notice:  Constant MYSQL_CLIENT_IGNORE_SPACE already defined in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_connect in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_pconnect in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_close in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_select_db in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_query in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_unbuffered_query in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_db_query in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_list_dbs in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_list_tables in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_list_fields in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_list_processes in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_error in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_errno in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_affected_rows in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_insert_id in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_result in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_num_rows in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_num_fields in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_fetch_row in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_fetch_array in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_fetch_assoc in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_fetch_object in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_data_seek in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_fetch_lengths in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_fetch_field in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_field_seek in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_free_result in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_field_name in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_field_table in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_field_len in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_field_type in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_field_flags in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_escape_string in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_real_escape_string in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_stat in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_thread_id in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_client_encoding in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_ping in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_get_client_info in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_get_host_info in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_get_proto_info in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_get_server_info in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_info in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_fieldname in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_fieldtable in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_fieldlen in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_fieldtype in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_fieldflags in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_selectdb in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_freeresult in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_numfields in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_numrows in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_listdbs in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_listtables in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_listfields in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_db_name in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_dbname in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_tablename in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - mysql_table_name in Unknown on line 0
PHP Warning:  mysql:  Unable to register functions, unable to load in Unknown on line 0
Error in argument 1, char 2: option not found r
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
       php <file> [args...]
  -a               Run interactively
  -C               Do not chdir to the script's directory
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -f <file>        Parse <file>.  Implies `-q'
  -h               This help
  -i               PHP information
  -l               Syntax check only (lint)
  -m               Show compiled in modules
  -q               Quiet-mode.  Suppress HTTP Header output.
  -s               Display colour syntax highlighted source.
  -v               Version number
  -w               Display source with stripped comments and whitespace.
  -z <file>        Load Zend extension <file>.
0
 
ai_ja_naiCommented:
maybe it would be better put it inside a file and then run php file.php
<%
 phpinfo(); 
%>

Open in new window

0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
Ross EdwardsTechnical DirectorAuthor Commented:
If I do this - I get the same errors as above, followed by the output of phpinfo in html code.  This suggest that PHPCLI is working does it not?

However if I browse to a pho page containing this code:
echo $server['php_cli'];

Nothing is returned.  This is the test done by the software my client is trying to install, to determine if PHP CLI is enabled.

0
 
ai_ja_naiCommented:
By the way, has the php present on Plesk been compiled with --with-cli option?
0
 
Ross EdwardsTechnical DirectorAuthor Commented:
According to the docs, I believe CLI is included in the build since 4.3.0, unless specified in the configure options.
0
 
ai_ja_naiCommented:
Not by default. Install scripts can decide to include it automatically, but it's not a predefined decision, especially in a hand compiled case.

Returning to the problem
>If I do this - I get the same errors as above, followed by the output of phpinfo in html code.  
you just have to run

php file.php >file.html

and watch it in a browser (of course)

>This suggest that PHPCLI is working does it not?
Infact, you have successfully run php by command line, which proves you have the right executable
0
 
Ross EdwardsTechnical DirectorAuthor Commented:
OK - so why does echo $server['php_cli']; not return anything?
0
 
ai_ja_naiCommented:
Because variable $server does not exist. You mean $_SERVER (yes, php is case sensitive when you refer to global variables); plus, field 'php_cli' in $_SERVER does not exists. Check by yourself http://it.php.net/manual/sl/reserved.variables.php
0
 
Ross EdwardsTechnical DirectorAuthor Commented:
Ok looks like $ server is a custom array which checks for the version of PHP like this:
 $server['php_cli'] = LocateExecutable('php-cli', '-v', '(cli)', $open_basedir, 'SCRIPT_FILENAME=/dev/null');

This is what is saying we do not have PHP CLI support.            
0
 
Ross EdwardsTechnical DirectorAuthor Commented:
OK - thanks for pointers but now I have screwed it up completely by trying to install another PHP.  I have opened another question to help me get it working again.!
0
 
ai_ja_naiCommented:
You've got a retrocompatibility issue:  the Windows packages between PHP 4.2.0 and PHP 4.2.3 distributed the CLI as php-cli.exe, living in the same folder as the CGI php.exe. Starting with PHP 4.3.0 the Windows package distributes the CLI as php.exe in a separate folder named cli, so cli/php.exe . Starting with PHP 5, the CLI is distributed in the main folder, named php.exe. The CGI version is distributed as php-cgi.exe.
As of PHP 5, a new php-win.exe file is distributed. This is equal to the CLI version, except that php-win doesn't output anything and thus provides no console (no "dos box" appears on the screen). This behavior is similar to php-gtk. You should configure with --enable-cli-win32.

So, that variable looks for php-cli executable, which is no more :)

What is the other question you opened to repair your environment?
0
 
Ross EdwardsTechnical DirectorAuthor Commented:
We are not using windoes - this in on CentOS, and we are on PHP 4 not 5.

My other Q is
http://www.experts-exchange.com/Software/Server_Software/Web_Servers/Apache/Q_24152349.html
0
 
ai_ja_naiCommented:
>We are not using windoes - this in on CentOS,

Sure, but it could be that the names are the same on linux :)

>and we are on PHP 4 not 5.

Doesn't matter: the change has been made from php 4.3 and we are on 4.3.9. The php 5 part was put only for your interest
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now