Yii Framework Forum: Moving Site to New Server ~ Error - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Moving Site to New Server ~ Error

#1 User is offline   ZEDG 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 20-December 16

Posted 20 December 2016 - 08:35 PM

Hi,
All i need to do is move a site - that I did not build, but worked out uses the YII framework - to a new server.
I have downloaded all files, uploaded them to the new server.
DB has been downloaded, a new one created in cPanel/MySQL, old one imported.

I have opened the files in protected/config (main.php, console.php) and edited them with the new db/user/pass.

I downloaded/uploaded the Requirements folder and everything has passed.
I have checked php.ini and PDO support is enabled (sqlite, mysql)
PHP Version 5.4.45

When i visit h ttp://serverip/~username/index.php I get:

The {serverip} page isn’t working
{serverip} is currently unable to handle this request.
HTTP ERROR 500


I tried editing my hosts file (thinking maybe it is the 'temp' url causing the problem)..
{serverip}/~username website.com
{serverip} website.com

but that makes no change/difference.

I deleted everything in .htaccess but that makes no difference.

Can someone PLEASE help me understand what else I need to do? ANY help is appreciated.
0

#2 User is offline   Patrick Jones 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 495
  • Joined: 14-July 12
  • Location:Berlin

Posted 21 December 2016 - 11:53 AM

Have you checked the server's error log? It should say something about the error 500.
Freelance developer for hire - send me a message!
0

#3 User is offline   ZEDG 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 20-December 16

Posted 21 December 2016 - 06:39 PM

View PostPatrick Jones, on 21 December 2016 - 11:53 AM, said:

Have you checked the server's error log? It should say something about the error 500.


Thanks for the response.
The only thing appearing is:

/home/username/public_html/.htaccess: Invalid command 'sudo', perhaps misspelled or defined by a module not included in the server configuration, referer: h ttp://ipaddress/~username/index.php

Searched the entire site for 'sudo' but found nothing of note.
?
0

#4 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,824
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 21 December 2016 - 06:56 PM

According to the message it should be in "/home/username/public_html/.htaccess"
It's strange though that the message say "referer: h ttp://ipaddress/~username/index.php"
What's in /home/username/public_html/index.php?


(In linuxes "sudo" is a prefix used for running a command with "su" privileges.)
Don't forget to read The Definitive Guide to Yii (1.1 en) (1.1 sv) (2.0 en) | The class reference (1.1) (2.0) has the details
0

#5 User is offline   ZEDG 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 20-December 16

Posted 21 December 2016 - 08:10 PM

View Posttri, on 21 December 2016 - 06:56 PM, said:

According to the message it should be in "/home/username/public_html/.htaccess"
It's strange though that the message say "referer: h ttp://ipaddress/~username/index.php"
What's in /home/username/public_html/index.php?


(In linuxes "sudo" is a prefix used for running a command with "su" privileges.)


Not sure what you mean by what's in /home/username/public_html/index.php?
I'm just trying to access the index page in the root.

(I don't know if that error appeared after i deleted everything in the .htaccess file as a test.)
0

#6 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,824
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 22 December 2016 - 05:57 AM

View PostZEDG, on 21 December 2016 - 08:10 PM, said:

Not sure what you mean by what's in /home/username/public_html/index.php?
I'm just trying to access the index page in the root.

(I don't know if that error appeared after i deleted everything in the .htaccess file as a test.)


Yes, that would be the index.php in the webroot. What's in it? If I understand correctly you don't know any details of this app, neither does this forum. The start script content can give a clue about Yii major version (1.1 or 2.0) as well as some of the possibly non-standard directory structure. Or better, show us the complete dir structure.

Did you install the app directly under the webroot and was it previously installed the same way?

One thing you should do is to empty the <app webroot>/assets and (e.g.) protected/runtime dirs (also check that web users have write access).

Did the .htaccess file look similar to this? The the app would be configured for "path format" url and to hide the start script. Without the rewrite in .htaccess, you should still be able to access the app (e.g. server/username/index.php/controller/action where possibly site/view is the default controller/action)

(Not sure about this but you might need Option FollowSymlinks or SymlinksIfSameOwner in .htaccess)
Don't forget to read The Definitive Guide to Yii (1.1 en) (1.1 sv) (2.0 en) | The class reference (1.1) (2.0) has the details
0

#7 User is offline   ZEDG 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 20-December 16

Posted 22 December 2016 - 10:31 PM

Thanks for the reply, it is very much appreciated.

Site has to be Ver 1 (older site, found 'copyright 2008-2013' reference).

Below is the index.php code:

<?php
error_reporting( error_reporting() & ~E_NOTICE );
$yii = dirname(__FILE__) . '/protected/framework/yii.php';

if ($_SERVER['HTTP_HOST'] == 'localhost') {
    $env = 'local';
} elseif ($_SERVER['HTTP_HOST'] == 'mywebsite.org' || $_SERVER['HTTP_HOST'] == 'www.mywebsite.org') {
    $env = 'production';
}

define('YII_ENVIRONMENT', $env);
$configLocal = include dirname(__FILE__) . '/protected/config/main.php';
$configServer = $env=='local' ? array() : include dirname(__FILE__) . '/protected/config/'.$env.'.main.php';


// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG', $env == 'local' ? 1 : 0);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);

if (file_exists(dirname(__FILE__) . '/maintenance.flag')) {
    echo "<h1 style='font-family: Helvetica; arial;'>Site is in maintenance mode. Check back after sometime.</h1>";
    exit;
}
require_once($yii);
$config = CMap::mergeArray($configLocal, $configServer);
Yii::createWebApplication($config)->run();



Here is the directory structure:
https://i.imgsafe.org/c9067c574a.png

I haven't installed the app. From what I read all I needed to do was upload all the files from the existing to the new server (both under public_html). Import the db, then update the db references in the protected folder.

Should I be 'installing' yii on the server?
Assume this would make sense if i was to delete everything in the /assets folder and /protected/runtime folders?

Should both these main folders have 777 permission?

Below is the .htaccess code

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

# Set up caching on static resources for 1 year based on Google recommendations
<IfModule mod_expires.c>
ExpiresActive On
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|js|css|gif|jpg|jpeg|png|swf)$">
ExpiresDefault A29030400
</FilesMatch>
</IfModule>


RewriteEngine on
<Limit GET POST PUT DELETE>
order deny,allow
allow from all
</Limit>

RewriteCond %{HTTP_HOST} ^([a-z.]+)?mysite\.org$ [NC]

RewriteCond %{HTTP_HOST} !^www\. [NC]

RewriteRule .? http://www.%mysite.org%{REQUEST_URI} [R=301,L]


# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php




There is no /controller or /site folder.

However there is a /protected/controllers folder (not containing an action/ folder) and a /protected/views/site folder.
0

#8 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,824
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 23 December 2016 - 05:04 AM

View PostZEDG, on 22 December 2016 - 10:31 PM, said:

$yii = dirname(__FILE__) . '/protected/framework/yii.php';

In this case the Yii framework has been placed under the /protected/framework dir

Quote

if ($_SERVER['HTTP_HOST'] == 'localhost') {
$env = 'local';
} elseif ($_SERVER['HTTP_HOST'] == 'mywebsite.org' || $_SERVER['HTTP_HOST'] == 'www.mywebsite.org') {
$env = 'production';
}

The server config will be dependent on the actual domain. It will never kick in in the temp domain case.

Quote

$configLocal = include dirname(__FILE__) . '/protected/config/main.php';
$configServer = $env=='local' ? array() : include dirname(__FILE__) . '/protected/config/'.$env.'.main.php';

The local config is in the normal config dir. The server config is in subdir /protected/config/production.

Quote

defined('YII_DEBUG') or define('YII_DEBUG', $env == 'local' ? 1 : 0);

Debug enabled in local mode only. (You may want to enable debug temporarily)

Quote

$config = CMap::mergeArray($configLocal, $configServer);

Effective config will be the local config merged with server config ("mywebsite.org" only)

The Yii app normally consists of index.php, assets dir and protected dir (minus the framework dir). Some more dirs under webroot may be Yii app (config) related.

Yii seems to be already included (in /protected/framework).

/assets folder can be safely emptied. Normally /protected/runtime too. (Keep a copy of original content)

Quote

Should both these main folders have 777 permission?

Or perhaps 775 with web user group?

Quote

RewriteEngine on
RewriteCond %{HTTP_HOST} ^([a-z.]+)?mysite\.org$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .? http://www.%mysite.org%{REQUEST_URI} [R=301,L]

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php


I'm not a .htaccess expert.
The first part obviously is dependent on actual domain.

/protected/controller for controllers (actions are methods in the controller)
/protected/views/<controller>/<action> for views

Have a look at the app template dir structure (scroll down)
Example entry script.
Don't forget to read The Definitive Guide to Yii (1.1 en) (1.1 sv) (2.0 en) | The class reference (1.1) (2.0) has the details
0

#9 User is offline   ZEDG 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 20-December 16

Posted 16 January 2017 - 05:57 AM

Once again thanks for your time.

I'm not sure what you have asked me to check.
I have changed permissions, deleted the .htaccess code..

I am absolutely clueless as to what i am meant to do.

Is the index file in the root the page i am meant to be accessing?
ie http://ipaddress/~username/index.php

--
The {ipaddress} page isn’t working
{ipaddress} is currently unable to handle this request.
HTTP ERROR 500
--
I have changed the hosts file so it points to the actual site address, but no idea if that makes a difference.

What am i meant to change or check exactly?
0

#10 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,824
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 16 January 2017 - 07:14 AM

For a start I think I would temporary replace index.php (http://ipaddress/~username/index.php) with the standard script I linked to. Change the $yii and $config paths to actual values. Use a standard config for testing or try pointing $config to the local config. Without .htaccess you should be able to reach the default route (start page) using http://ipaddress/~username/index.php.

Even if you don't have a local lab server environment available, you may want to download Yii 1.1 just to gain some experience from reading the code. E. g. check out the blog demo <framework dir>/demos/blog. And for trying it out, it's possible to upload the Yii 1.1 content to a subdir on the server. IIRC it will use a file based DB out of the box.

Have a look at the urlmanager settings in config.

With 'urlFormat'=>'get' the route will be <webroot>/<optional subdir>/index.php?r=<controller>/<action> (default use to be site/index)

With 'urlFormat'=>'path', 'showScriptName' => false, (and working .htaccess) the route will be <webroot>/<optional subdir>/<controller>/<action>. Without .htaccess, at least you should be able to see the default start page (site/index) using the route <webroot>/<optional subdir>/index.php.

You may also want to read better explanations in the guide, e.g. the section User friendly URL's

I hope this will help you solving this.
Don't forget to read The Definitive Guide to Yii (1.1 en) (1.1 sv) (2.0 en) | The class reference (1.1) (2.0) has the details
0

#11 User is offline   ZEDG 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 20-December 16

Posted 16 January 2017 - 07:43 AM

Quote

Only once I un-comment the last line do i receive the 500 error.
Yii::createWebApplication($config)->run();


Yes, that's expected. Note that you must have path to a valid config so it's meaningless to comment out all assignments to $config in the start script.

I'm not sure about the exact path to the framework and demo dir in the Yii 1.1 download (I used to move some dirs). I'm sure you'll find the blog demo and figure out how to call the start script in the blog subdir.

I definitely recommend you try the blog demo (you already mentioned that the requirements script passed ok). Probably a good idea to check with the latest requirements.php (from the downloaded Yii 1.1).

No success with blog demo? If possible you may also want to temporarily enable "show php errors" in the server.
0

#12 User is offline   ZEDG 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 20-December 16

Posted 24 January 2017 - 12:57 AM

I uploaded and tried accessing demos/blog/index.php but I receive the same 500 error.
The two file references are correct.

$yii=dirname(__FILE__).'/../../protected/framework/yii.php';
$config=dirname(__FILE__).'protected/config/main.php';



No errors appear in cPanel > Errors.

Error Reporting and Display Errors are both 'on' in the php.ini that is in the root.




I don't get any 'fails' in the Requirements but i do get some warnings. Assume these shouldn't matter though?

PDO PostgreSQL extension Warning All DB-related classes Required for PostgreSQL database.
PDO Oracle extension Warning All DB-related classes Required for Oracle database.
PDO MSSQL extension (pdo_mssql) Warning All DB-related classes Required for MSSQL database from MS Windows
PDO MSSQL extension (pdo_dblib) Warning All DB-related classes Required for MSSQL database from GNU/Linux or other UNIX.
PDO MSSQL extension (pdo_sqlsrv) Warning All DB-related classes Required for MSSQL database with the driver provided by Microsoft.
PDO ODBC extension Warning All DB-related classes Required in case database interaction will be through ODBC layer.
Memcache extension Warning CMemCache
APC extension Warning CApcCache



Below i have posted the details that appear at the right side of phpmyadmin of the server with the 'current live site'

Database server

Server: Localhost via UNIX socket
Server type: MySQL
Server version: 5.5.53-0ubuntu0.14.04.1 - (Ubuntu)
Protocol version: 10
User: user@localhost
Server charset: UTF-8 Unicode (utf8)

Web server

Apache/2.4.7 (Ubuntu)
Database client version: libmysql - 5.5.53
PHP extension: mysqli Documentation


Below is the details that appear on the server I am moving the site to.


Database server

Server: Localhost via UNIX socket
Server type: MySQL
Server version: 5.5.52-cll - MySQL Community Server (GPL)
Protocol version: 10
User: user@localhost
Server charset: UTF-8 Unicode (utf8)

Web server

cpsrvd 11.60.0.35
Database client version: libmysql - 5.1.73
PHP extension: mysqli Documentation


Does anything here make a difference?
0

#13 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,824
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 24 January 2017 - 04:14 AM

Just to be sure:
Did you upload the complete Yii 1.1 package content to a subdir on your server (e.g. yii1117)?
You tried to access the blog demo at <your tmp domain>/yii1117/demos/blog and you didn't see the start page. Instead you got a 500 error.

Edit: I actually just tried the same thing. The start page should show up with a text like this:

Quote

Error 500
Application runtime path "/srv/www/htdocs/Yii1/yii-1117/demos/blog/protected/runtime" is not valid. Please make sure it is a directory writable by the Web server process.


Next step is to make the runtime (and assets) directories writable (777 to keep it simple).

Did it work? Ok, now you should know what a basic start script (index.php) and config file (protected/config/main.php) looks like.
Don't forget to read The Definitive Guide to Yii (1.1 en) (1.1 sv) (2.0 en) | The class reference (1.1) (2.0) has the details
0

#14 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,824
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 24 January 2017 - 05:06 AM

Next step will be to modify the site you're trying to install.

Somebody told you it's just to copy the files to the new server. That might be true if the same domain (mywebsite.org) is pointed to the new server. But what if it doesn't work. Not a good idea.

I mentioned that the start script has dependencies on the domain (mywebsite.org). If it don't match you will fall back to a "local" config. (There may also be domain dependencies in the config file or elsewhere.) E.g you could add a config/main.php and use a basic start script.

By now you should know enough about the basic start script and config to make the neccessary changes for at least bringing up the start page.
Don't forget to read The Definitive Guide to Yii (1.1 en) (1.1 sv) (2.0 en) | The class reference (1.1) (2.0) has the details
0

#15 User is offline   ZEDG 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 20-December 16

Posted 24 January 2017 - 06:55 AM

I uploaded the Demos folder to my root, but as mentioned I cannot access demos/blog/index.php as I receive the same 500 error.

I downloaded yii-1.1.17.467ff50.zip, and uploaded 'framework' and 'demos' to a new folder i created in the root 'testing.
When I try accessing the demos/blog/index.php in that i get the proper page.


The files being accessed/referenced in both instances are identical though. ?!

This Works:
h ttp://{ipaddress}/~usrname/testing/demos/blog/index.php

$yii=dirname(__FILE__).'/../../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';



This doesn't
h ttp://{ipaddress}/~usrname/demos/blog/index.php

$yii=dirname(__FILE__).'http://{ipaddress}/~usrname/testing/framework/yii.php';
$config=dirname(__FILE__).'protected/config/main.php';
0

#16 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,824
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 24 January 2017 - 07:48 AM

This is a path in the servers filesystem, relative to the directory of the script.
dirname(__FILE__).'/../../framework/yii.php'


This is the scripts dir with a web url appended. Will not work.
dirname(__FILE__).'http://{ipaddress}/~usrname/testing/framework/yii.php'

Don't forget to read The Definitive Guide to Yii (1.1 en) (1.1 sv) (2.0 en) | The class reference (1.1) (2.0) has the details
0

#17 User is offline   ZEDG 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 20-December 16

Posted 24 January 2017 - 08:11 AM

Yes, although i have tried ANY type of reference. I was attempting to reference the yii file in the testing/framework just to see.


In the testing folder I upload BOTH the demos and framework folders.
The demos/blog/index.php works.


However i uploaded JUST the demos folder into the root, and placed the reference to the yii file 'as it is/where it appears' in the existing website/root, like so

$yii=dirname(__FILE__).'../../protected/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';


500 error.



I had a comrade see if he could get it to work locally and the site (and blog) works (identical to the current live site on existing server).
0

#18 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,824
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 24 January 2017 - 08:37 AM

Did you remove the .htaccess in root?
Also the ./protected/framework instance of Yii may have some problem/version diff/dependence of domain. Normally the framework code should not be tampered with, but who knows.
Don't forget to read The Definitive Guide to Yii (1.1 en) (1.1 sv) (2.0 en) | The class reference (1.1) (2.0) has the details
0

#19 User is offline   ZEDG 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 20-December 16

Posted 24 January 2017 - 09:13 AM

Renmoving everything in htaccess was the very first thing i ever tried.

The demos/blog references two files:
config/main.php
framework/yii.php

BOTH the:
root /protected/framework/yii.php AND
root /testing/protected/framework/yii.php

are identical. But only the testing/demos/blog index works.


The yii.php references /YiiBase.php

I have compared both of the copies of this file - the original/existing and the new one downloaded.

Line 83:

Original: return '1.1.14';
New: return '1.1.17';

Different versions (plus some other slight code changes), but that should have nothing to do with why the demos/blog doesn't work.?


I replaced the original protected/framework folder with the newly downloaded framework folder (1.1.17).

No change, 500 error.
0

#20 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,824
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 24 January 2017 - 10:52 AM

If I understand your situation
You have <webroot>/demos/blog/index.php (not working)
and <webroot>/testing/demos/blog/index.php (working)

Same framework in two places
<webroot>/protected/framework/yii.php
and
<webroot>/testing/framework/yii.php

Then the $yii and $config variable in index.php should be assigned
$yii=dirname(__FILE__).'../../protected/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

and
$yii=dirname(__FILE__).'../../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

respectively

What about the 500 error. What exactly do you see. I assume you made the runtime and assets directories writable for the web server process.

At least the two blog instances should work. Very strange.

For some debug info you can uncomment this line in index.php
// defined('YII_DEBUG') or define('YII_DEBUG',true);
Don't forget to read The Definitive Guide to Yii (1.1 en) (1.1 sv) (2.0 en) | The class reference (1.1) (2.0) has the details
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users