Jump to content

Recommended Posts

Server Info

Linux

 

PHP Version

5+ & 4.4.4 Both on the server

 

Problem -

I have added something into htaccess that forces all files to run in the php 5 parser when going through the browser.  However now when I try running the PHP files through Shell it is telling me I have an improper version of PHP (so basically the script I am using requires PHP 5, and because of that, I can tell it's still trying to read it as PHP 4, is there a way to run it through php 5 parser specifically.

Link to comment
https://forums.phpfreaks.com/topic/51836-solved-2-versions-one-server/
Share on other sites

www.1and1.com

Developer Package

 

I have tried everything.

I tried even temporarily changing the file to .php5 and it didn't run that way either.

I even tried finding commands for shell that will specifically "force" it to parse them AS php5.

I am assuming that $ is basically symbollic for (that is where you put the command), because I see nothing like that, and it works when I don't put it (unless it has a use I am unaware of.)

When I put that in I get the following output

PHP 4.4.4 (cgi - I hate php running as a cgi module) (built: Nov 14 2006 12:40:26)

Copyright © 1997-2006 The PHP Group

Zend Engine v1.3.0, Copyright © 1998-2004 Zend Technologies

I understand it is "by default" running off of PHP 4, but it's the same thing.

When I called the host and spoke with them about it, they had originally told me to add something in htaccess to get php 5 working through the browser, which was.

AddType x-mapp-php5 .php

Now when I called they told me to add this to get it working in command line.

AddHandler x-mapp-php5 .php

I tried that and it didn't work, so I even tried to change the filename to php5.

I have nothing else to try, I even found another tutorial on it, about adding something at the top of the php file in the form of a bash command, but I don't know how to do that.

you know how you type

 

#!/usr/bin/php

 

If this worked on windows it might look like

 

#!C:/usr/bin/php.exe

 

And as you can see with #!C:/usr/bin/php.exe there is really nothing you can do unless you get a copy of php5 cli on the server. Things like this are why I will always hate 3rd party hosts.

 

Not only am I doing this but I am trying to learn from it as much as possible.

 

First

$ ls -l /usr/bin | grep php

Ok, I understand what ls is, (it shows the directory).  What is -l I don't understand that, or anything after that. (Just for learning purposes).

 

Second

The output that the command you gave me outputs is.

-rwxr-xr-x    1 root    root      473352 Mar 20  2002 php3

-rwxr-xr-x    1 root    root        5083 Mar 31  2002 phptar

That is what shows up.

After speaking with the host a few time's, they have mentioned they have support for php 3, 4, and 5.

after htaccess editing I can change them around in there, but they keep saying I can do it through command line on either php3, php4, php5, python, or perl.

So I know there has to be a way, they are just dumb.

They keep telling me htaccess should do that, so they are dumb.

The PHP5 executable resides somewhere on the host.  If you are able to find it, you could just use the direct path to execute your scripts.  For instance, say the executable was in /usr/bin/php5/, you could do:

 

/usr/bin/php5/php my_script.php

Firstly. -l is an option for ls that list the details of the file. eg; permission, owner, fielsize etc etc. The bit after that pipes the output to the grep program. grep is a meens of filtering output based on regex.

 

If you just ran...

 

$ ls -l /usr/bin

 

You would get alot of un wanted output (Every program installed in /usr/bin). Because we only wanted things related to php I piped the command to grep.

 

Next. .htaccess has nothing to do with the command line in php. It is an apache configuration file and is of no use to us.

 

The setup on this system does appear a little strange though. Do us a favour. I now need the output of...

 

$ whereis php

First

So "whereis" is another command.  It's basically whereis filename.ext and it will basically report where the file is located...

 

Second

When I run "whereis" on any filename other than the php that you showed me, all it does it redisplay the name of what I just added.  However this is something I Can find out by google, so in essence just thanks for telling me about this.

 

Third

The output of the command you told me to execute was

 

php: /usr/local/bin/php /usr/local/lib/php3.ini /usr/local/lib/php5.old /usr/local/lib/php /usr/local/lib/php.ini /usr/local/lib/php.ini-nourl

 

Again, thank you so much for walking me through parts of this.  This is something I was doing partially for a personal project, and partially to learn, and I have learnt a lot during this process, so thanks again.

I tried entering it exactly as you mentioned, as well off numerous various.

IN the end I get the same messages about directory not existing, and when I type it "word-for-word" like you said it returns.

bash: /usr/local/lib/php: is a directory

Oh.  I installed a wiki (www.mediawiki.com or google "Media Wiki".)

I have gotten the whole thing installed and running and it requires php5.  Through the browser everything worked out.

However for some reason it didn't create my actual admin account. It created my user, but not my admin, so I saw on the site where it says it sometimes doesn't do this for unknown reasons and provided a manuial fix.

So I took AdminSettings.php and recreate it as they listed in the manual.

Then I went to run

/wiki/maintenance/createAndPromote.php

which requires php5 and it requires being run on the command line as well.

It has an include for something called commandline.inc

Either way that's the reason I was trying to do something.

In the end I have learnt a lot but it's starting to look like I won't accomplish my initial goal.

I don't have admin access to any of the "maintenance" tasks in the wiki because of this.

The reason I know it's a PHP 5 issue is because there is a piece of code within the commandline.inc for that file that reads

<?php
/**
* @todo document
* @addtogroup Maintenance
*/

$wgRequestTime = microtime(true);

/** */
# Abort if called from a web server
if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
print "This script must be run from the command line\n";
exit();
}

if( version_compare( PHP_VERSION, '5.0.0' ) < 0 ) {
print "Sorry! This version of MediaWiki requires PHP 5; you are running " .
	PHP_VERSION . ".\n\n" .
	"If you are sure you already have PHP 5 installed, it may be " .
	"installed\n" .
	"in a different path from PHP 4. Check with your system administrator.\n";
die( -1 );
}

(it's an inc file without <?php tags hence the no syntax highlighting)

That check there tests to see if it's command line, then checks the version.

I keep getting returned that error message.

Telling me I am trying to use php version 4.4.4. and it requires 5.

Another thing is they claim I can use

php3, php4, php5, python and perl.

Lately I have been learning python, and I am about to start playing with perl in my spare time.

I tried a line of code they showed as

http://faq.1and1.com/scripting_languages_supported/cgi/1.html

Right there, basically.

So I ended up trying:

#! /usr/bin/php5

and still nothing.  I tried making this a comment, and echoing it both within the createAndPromote.php but it still returns the same error, and just executes that command as text.

I will be trying to get .py and .perl files to work after that, but I cant' do that if I can't even get it to use the php5 files.

They kept telling me to name my files .php5 and it would work through command line, they also told me that bullshit about htaccess.

After wasting hours this morning I realized how stupid they really where.

I know, I meant I am trying to get this thing down so I can get this script installed (hopefully gaining the knowledge on how to switch between php versions for command line), before I start trying to setup where it can run python and perl files on the web.

i want to get where I can easily change between php 3,4, and 5.

I am trying to get this one thing working, then I was going to perform some personal analysis tests on the differences between 3, 4, and 5 (which is why I was hoping I could change through them in the Command line like I could through the browser), but I am starting to wonder that won't happen because of there stupid setup.

Wait, yeah maybe that will help.

WHen I am trying to run the file, I get into the directory and run.

php -f createAndPromote.php

When I do that, I am getting this message.

Sorry! This version of MediaWiki requires PHP 5; you are running 4.4.4.

 

If you are sure you already have PHP 5 installed, it may be installed

in a different path from PHP 4. Check with your system administrator.

Does that mean there is someway for me to change the path.

I could call them again, but it sounds like I know more about what I am doing now than they do.

They have non-technical people in tech support.

So I ended up trying:

#! /usr/bin/php5

 

/usr/bin/php5 does not exist, we allready checked that.

 

I'll explain some stuff. This line...

 

#!/usr/bin/php

 

Is what is known as a shebang. Remember how I said Linux does not use file extensions? Scripts need a shebang line to let the shell know which program to use to execute them. Hence, bash programs always start with...

 

#!/bin/bash

 

If we could find where the php5 executable resides, you could point your shabang at it. Lets try one more thing, whats the output of...

 

$ which php

 

PS: On Linux, most commands have a man page. For instance, earlier you asked about the -l option to the ls command. You can find out infomation like this yourself by typing...

 

$ man ls

First

I really want to thank you for filling me in on this man command.  This seems very helpful, I also learnt that q backs out of something (like when your in the man command).

Another thing I was wondering, when I try to do something like man -f which "-f" being what I used to try to run the file in the first place, it doesn't work. It works with ls though, which was VERY informational, thanks again.

 

Second

Based on what you said, I ran a little test.

I was told there server supports php 3, 4, and 5.  I also know 6 doesn't exist.

So I ran the following commands (in code) and got there output (in quotes)

PHP

which php

/usr/local/bin/php


PHP3

which php3

/usr/local/bin/php3


php4

which php4

/usr/local/bin/php4


php5

which php5

/usr/local/bin/php5


php6 (testing to see if it would come up with an error if something didn't exist)

which php6

Nothing, returns blank (because it can't be there since they don't have it on the server);

 

This tells me for a fact they have the php3, 4, and 5.

So what can I do "with" this information to get it to do what I need.

I now understand that the top part is a shebang as "thorpe" told me.

But I don't understand how to use it.

I also understand the hello world (I guess to test it).

Make executable I have no idea. I know chmod but never saw +x

The way you showed me to execute doesn't execute.

Do I run these through command line, I was able to follow so far, but now I am complete lost, and I saw that same thing to within the 1and1.com faq but it made no sense to me.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.