# Hostname, MySQL and a PHP framework



## drhowarddrfine (Jul 15, 2015)

I've been asked to set up a new server using old PHP code on an old version of CodeIgniter with the latest version of PHP, mySQL and on www/nginx instead of Apache. Great. And I'm doing something wrong on top of that. Was up way too late trying to get the rest of the code to this point so I hope I'm not embarrassing myself.

This is in VirtualBox running FreeBSD10.1. I access it from the same box which is Windows using Chrome.

I think I'm doing something wrong setting up the hostname so I don't think it's a framework, PHP or server issue though you could prove me wrong at this point.

Inside CodeIgniter the $SERVER_NAME thinks the hostname is 'localhost' but it's actually "bob". I have hostname set to bob in /etc/rc.conf. In /etc/hosts I tried both putting "bob" on the same line as localhost and putting it on its own line with the IP address of the server "10.xxx.xxx.xxx bob".


----------



## usdmatt (Jul 15, 2015)

What's server_name set to in the nginx configuration?

Probably unrelated, as I'm 90% sure the SERVER_NAME value comes from the web server, but in /etc/hosts, 127.0.0.1 should be just localhost, and the hostname should be linked to the actual IP address.

Even more unrelated, but it must be extremely old if it's using $SERVER_NAME. It's been a long time since I've seen any PHP code use global variables like that and not $_SERVER/$_REQUEST/etc (Think they started trying to phase register_globals out around PHP 4)


----------



## drhowarddrfine (Jul 15, 2015)

I'm wondering if that might be the case but I won't be back at work for a couple of hours. I just don't remember what I did with that right now.


----------



## drhowarddrfine (Jul 15, 2015)

usdmatt I set it as a comment. Can you believe that? I'm sure that you can. It now echoes the server name as "rob" but it's still not serving up the page.

Now this might be more CodeIgniter specific. In /application/config/config.php, if you're familiar with it, I'm to set the Base Site URL. The original code for this site has it set as: 
	
	



```
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'];
```
. Now, remembering that I'm in VirtualBox on the same machine, and that has a local IP address of 10.xxx.xxx.xxx, I put that in as 
	
	



```
$config['base_url'] = 'http://10.xxx.xxx.xxx';
```
 but, as I said, I still get a blank page.

Are you, or anyone else, able to help with this? I just walked into the office and haven't looked at anything else.


----------



## usdmatt (Jul 15, 2015)

To be honest getting a blank page could be anything, and I'd be surprised if having the wrong base_url would actually cause you to get no output at all.

Have you installed a php.ini file, and if so which one?


----------



## drhowarddrfine (Jul 15, 2015)

There is only the php.ini that came with the site software and it only contains 
	
	



```
allow_url_fopen=1
```


----------



## drhowarddrfine (Jul 15, 2015)

fwiw, I'm able to access php_info and a html file I have in that root directory at http://10.xxx.xxx.xxx


----------



## drhowarddrfine (Jul 15, 2015)

And now for something entirely different. I was getting php errors complaining that some of the mysql function calls were deprecated and going to be removed. That I needed to switch to PDO or use mysqli. So I changed the dbdriver setting in database.php to mysqli and all that went away so I thought that problem was solved.

However, just now, I decided to change it back to mysql to see those errors again. This time I also notice it says "bob-local.bob.local" is not allowed to connect to this MySQL server. I haven't a clue where "bob-local.bob.local" came from.

I know this sounds like it's crumbling down around me but I'm hoping someone recognizes this.


----------



## drhowarddrfine (Jul 15, 2015)

I set it back to mysqli.


----------



## SirDice (Jul 16, 2015)

What version of PHP are you using? If the old code is from PHP 5.2 you probably have more luck using PHP 5.4 or 5.5. The latest 5.6 will give you lots of headaches due to all sorts of deprecated functions. PHP 5.5 should be around for a while and may provide a nice "stepping stone" to work from.


----------



## drhowarddrfine (Jul 16, 2015)

Yes, I was using 5.6 and all the errors I got were about deprecated functions. From around the 'net, it's hard to get answers about my questions, even on the CodeIgniter board, and most of those answers were either "you can't do that" or "you have to upgrade CI" despite my insistence that I can't do that.

I edited some core files to make all that go away and work but now I can't get the server to talk to it properly. The boss is being highly unreasonable over all this, as if it was my fault. I may tell him to shove it.


----------



## SirDice (Jul 16, 2015)

I think the best way forward would be to plan for an update to CodeIgniter. Even if you manage to get all the errors and warnings out you may still be left with some functionality that's not working as it's supposed to. And to make matters worse the next PHP version will dispense with mysqli altogether and only support PDO. And that would probably mean a complete rewrite of all the database functions.


----------



## drhowarddrfine (Jul 16, 2015)

Yes. I've been told that and relayed all that info to the boss days ago. He doesn't understand still why this web site will take more than three weeks to complete (!).


----------



## drhowarddrfine (Jul 16, 2015)

Haven't mentioned this earlier but this new web site, based on old code, is for the boss's mother who's involved in a new charity. This old code is actually from his brother's side business of creating cheap web sites. So he's able to crank them out for a thousand bucks but he's using the same thing on an old Windows server for years. I don't understand why I'm being asked to work on this while the company web site is crumbling and dysfunctional but I've been sitting in my office for over three months doing nothing, literally, so I don't mind.

So we just had a meeting and he had this funny look about him. We're supposed to have another at 3PM and I have a feeling he's going to fire me over this. Great idea! Without my salary it will make up for some of the lost sales cause ordering on the web site doesn't always work. But you're getting an inkling of what it's like around here.

If he doesn't fire me, I might quit, cause I don't need this. I still have my web business.

What is it about small companies? These have about $3 million in sales. I may go into a rant in the off-topic category but this is the third company I've tried to work for, over the past year, that operates in such a bizarre fashion. They bring me in, in a panic, cause their sites are so bad, ask me to fix them up, but then don't give me the information or tools to do the job, and then try to blame me for that. I've never run into that in the 11 years of freelancing.


----------



## MainframeX (Jul 17, 2015)

In all honesty; by the sound of it this it won't be fixed within the three week mark. It seems the site hasn't been looked at for years which is typical for pump 'n dump dev shops, at the speed which PHP evolves and everything depending on it, this creates potentially enormous technical debt. Try to explain as clearly as possible why it needs proper time getting looked at. We dev/ops guys aren't wizards that can make problems go away in the wink of an eye. My guess is that your boss doesn't have the slightest inkling how time consuming this project is.


----------

