changing server user

kharisma

Joined: 2007-10-03
Posts: 7
Posted: Fri, 2010-11-19 04:55

It seems that gallery2 is heavily dependent on the username on the server, with this being hard-written into the code on setup.

This means that if the user is changed, that we then have to search through multitudes of files to find all instances.

Surely the file path could be found using PHP so that the script can run independently of specific usernames.

Even if the script does require a specific name, surely it can be put into a config file so that there is just one instance that needs amending. The username could be placed into a PHP constant for use throughout the software.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Fri, 2010-11-19 06:30

I am making an assumption here that you're talking about g2data and ownership of files on the file system, see my comments below. Of course if you're not talking about file ownership of g2data, please clarify what you're asking about.

In short, this may help:
http://codex.gallery2.org/Downloads:Cleanup_Script

Possibly, contacting your host to have them change ownership, or searching google on how to use tools like chmod or chown and how to use one or both of those recursively.

Quote:
It seems that gallery2 is heavily dependent on the username on the server, with this being hard-written into the code on setup.

No and no. No it's not dependent on the username of the server in any way, well other than the user the server runs as, is the owner of the files, there is no getting around this at all, well I guess there is, run FAT32..... No, it's not "hard-written" anywhere in the code at any time, ever.

Quote:
This means that if the user is changed, that we then have to search through multitudes of files to find all instances.

Huh?

Quote:
Surely the file path could be found using PHP so that the script can run independently of specific usernames.

Nope, not possible for any PHP script ever written (or perl or python or c or <insert name of programming language here>. If the webserver is running as the user "nobody" then any process it runs or executes runs as that user without some custom setups. Well it's possible, if the user the server or script is running as, has permission to change ownership, but usually that's not the case and certainly shouldn't be the case for any user of a shared server.

Quote:
Even if the script does require a specific name, surely it can be put into a config file so that there is just one instance that needs amending. The username could be placed into a PHP constant for use throughout the software.

How? PHP by default runs as the user the web server is ran as. Every host is setup completely differently for this. Some run Apache as "nobody", others as "99", others as "www-data", others run a chrooted-jailed type environment where Apache runs as your user account. Then there is php-cgiwrap setups where php can be run as a cgi and as your user account, but Apache runs as a different user. Then there are suexec environments where cgi and ssi stuff is run as your user account instead of the default user your host has Apache running as.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
kharisma

Joined: 2007-10-03
Posts: 7
Posted: Fri, 2010-11-19 22:40

The username is written into the code on setup. When I migrated the website to a different user I then had to do a search to find all the places within the code that the username had been written into the path.

It was in main.php, config.php, index.php, and a few other files as well. File paths were specifically coded as "home/oldusername/domain.com/gallery-user/filename.php".

In my.domain.com/someone/index.php the code was:
define('GALLERY_CONFIG_DIR', dirname(__FILE__));
require('/home/old-user-name/my.domain.com/index.php');

So the path *was* hard-written into the code.

The error I was getting was:

Warning: require(/home/old-user-name/my.domain.com/index.php) [function.require]: failed to open stream: Permission denied in /home/new-user-name/my.domain.com/someone/index.php on line 3

Fatal error: require() [function.require]: Failed opening required '/home/old-user-name/my.domain.com/index.php' (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/new-user-name/my.domain.com/someone/index.php on line 3

I have no idea why you are talking about username 'nobody'. I always get to define my own user names that the website will be housed in. Of course, for the majority of people this may not be the case, because they are using CPanel. I am hosted on Dreamhost, so I can choose my own user names.

When gallery is installed, it would be better to have a query, perhaps in the config file, e.g. define( 'PATH_BASE', dir(__FILE__) ); Then for all references that require a path, use PATH_BASE . "relative/path";

Wordpress uses the following code in their config file:

/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');

/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

Easy-peasy - then I can migrate my website without everything breaking.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Fri, 2010-11-19 23:06

O0000000000000H, well you never said what you were trying to do. Editing config.php should be all you need to do. Make sure you followed these instructions:
FAQ: How can I move my gallery installation from one server to another?

There's like 1 or 2 things to edit. G3 makes it even easier, there's nothing that needs to be edited.

There is a reason we have the text you deleted inserted into new posts asking for information...
FAQ: What information is required when I ask for help in the forums?
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
kharisma

Joined: 2007-10-03
Posts: 7
Posted: Sat, 2010-11-20 14:08
Quote:
FAQ: How can I move my gallery installation from one server to another?

Wasn't migrating in the sense meant by that article. The website is still on the same server. All I did was change it to a different username.

Question: What do I need to do if I change the username a Wordpress website is installed on?
Answer: nothing at all. The website continues to function as though nothing had happened.

Quote:
Surely the file path could be found using PHP so that the script can run independently of specific usernames.

Quote:
Nope, not possible for any PHP script ever written

Wordpress uses dirname(__FILE__) to find the path, no matter where the website is.

Quote:
There's like 1 or 2 things to edit.

Actually, there are 6 files altogether:
config.php
embed.php
index.php
main.php
/lib/support/index.php
/upgrade/index.php

Whatever...

I wasn't asking for help. I only wrote this for feedback to the people who maintain the code.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Sat, 2010-11-20 16:01

Actually, there is only one file you need to change, config.php

G2 is no long in development, so these changes are not going to happen.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
Dayo

Joined: 2005-11-04
Posts: 1642
Posted: Sat, 2010-11-20 19:59

Gallery DOES NOT care what the server username is and besides, I can not find one single place where the server path, username included or not, is hard coded anywhere on my G2.3.1 installation (apart from path to g2data). As you have failed to provide the necessary information about your installation, it is not clear whether you are using a current version or an outdated one.

My index.php does not contain any "require('/server/path/index.php');" ... Why would index.php require itself?

Sorry, but there is nothing wrong with the way the application has been configured in this instance and there are no changes required.

--
dakanji.com

 
kharisma

Joined: 2007-10-03
Posts: 7
Posted: Sun, 2010-11-21 22:03

Gallery 2.3.1

For each sub-installation for different gallery-users

www.domain.com/gallery-userID/config.php

define('GALLERY_CONFIG_DIR', dirname(__FILE__));
require('/home/username/website/config.php');

www.domain.com/gallery-userID/embed.php

define('GALLERY_CONFIG_DIR', dirname(__FILE__));
require('/home/username/website/embed.php');

www.domain.com/gallery-userID/index.php

define('GALLERY_CONFIG_DIR', dirname(__FILE__));
require('/home/username/website/index.php');

www.domain.com/gallery-userID/main.php

define('GALLERY_CONFIG_DIR', dirname(__FILE__));
require('/home/username/website/main.php');

www.domain.com/gallery-userID/lib/support/index.php

define('GALLERY_CONFIG_DIR', dirname(__FILE__));
require('/home/username/website/lib/support/index.php');

www.domain.com/gallery-userID/upgrade/index.php

define('GALLERY_CONFIG_DIR', dirname(__FILE__));
require('/home/username/website/upgrade/index.php');

6 files all with the path hard-coded.
4 users to change - 24 files altogether.

 
kharisma

Joined: 2007-10-03
Posts: 7
Posted: Sun, 2010-11-21 22:01

Anyhow, since you are no longer maintaining the code, I guess it doesn't matter. Unless, Gallery3 installs new gallery-user areas in the same way ...

 
Dayo

Joined: 2005-11-04
Posts: 1642
Posted: Mon, 2010-11-22 04:11

Nothing needs changing here as you are talking about a multisite installation where the individual sub installations can be located anywhere on the server and need to know the server path to the main installation.

As for the G2 code, I am sure glaring errors will get fixed (ultimately) if pointed out. This, however, does not count as any sort of error and is just an unavoidable consequence of:

  • You setting up your server to include the username in the path to the webroot. You set up your server so that web sites are served out of "/home/server_username/domain".
  • You taking advantage of a feature that needs to know the server path to the main installation. You have the main site in "/home/server_username1/domain1" and sub installations in /home/server_username?/domain? need to have the path to /home/server_username1/domain1 in order to find the G2 code.
  • and finally, you deciding, knowing fully well the two points above, to change server_username1 to server_username2.

Why don't you set up your websites so that they are served out of a location that does not include the username in the server path if you want to go about changing the server username after installing things? There is nothing stopping you from setting up your server to use any other server path you want, "/var/html/sites/domain?" if you often get the urge to go changing the server username.

As an exercise for you, try installing a similar multisite configuration (one main code base with sub installations sharing this) in WP or any other application, change a component of the server path to the main installation (in your case, username will always do) and see what happens.

I know I shouldn't have responded to this but we all have our weaknesses.

--
dakanji.com