Thursday, January 6, 2011

Zend Framework on Shared Host Easy Simple Fast

1) Zip your project folder "myproject"

2) Start a console window cmd.exe. Go to your mysql/bin folder and dump your database into a file mysqldump -uroot -ppassword myprojectdb > myprojectdb.sql

3) Login to your Hosting company CPanel

4) Open the File Manger and create a folder "projects" in your home directory (/home/mydomain/). You should have /home/mydomain/projects

5) Upload the zip file from step 1 to your projects folder and unzip it there. remove the zip file. You will have /home/mydomain/projects/myproject

6) Open MySQL Databases from CPanel and create DB, User for your project and link the usr to the DB. You will end up having mydomain_myprojectdb as a database mydomain_myuser and grant all privileges ON mydomain_myprojectdb TO mydomain_myuser. You can change this later. All this done in CPanel MySQL Databases tool.

7) Open phpMyAdmin and import the DB from step 2. (myprojectdb.sql)

8) In the CPanel File Manager change the database, username, password in /myproject/application/config/application.ini file .

9) Create a subdomain to access the public folder of your project. In CPanel go to subdomains tool and enter as subdomain mysubdomain as a folder ~/projects/myproject/public/. "~" means my home directory on the system usualy /home/mydomain

10) Point your browser to http://mysubdomain.mydomain.com. If you can see the page - you are done. If you get error "Fail t load Zend/Auto..." that means yout hosting comapny doesn't have Zend Framework in the include path.

11) In the CPanel File Manager create a folder "library" in /home/mydomain/. So you will have /home/mydomain/library

12) Download the Zend Framework library or use yours and zip it for easy transfer. Use the CPanel file manager to uploaded to the folder /home/mydomain/library unzip it there and remove the zip file. So you will have /home/mydomain/libraryZend

13) Make a change in your public/index.php file and add to teh include paths the path to the library we just created. All our applications will share this library. Open public/index.php with the File Manager and add just after the include path section for "// Ensure library/ is on include_path"

...
// Ensure the common library/ is on include_path for my shared host
set_include_path(implode(PATH_SEPARATOR, array(
// realpath(APPLICATION_PATH . '/home/mydomain/library'), // for my shared host
realpath(APPLICATION_PATH . '/../../../library'),
get_include_path(),
)));
...


14) Refresh http://mysubdomain.mydomain.com. It should work now.

15) (Optional) If you want this project to be your main domain application move the content of public folder to your public_html forlder where the document root of Apache is pointing and change 1 line in your index.phtml file to point to the proper application folder.


// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../projects/myproject/application')); // change to point to your project folder


The usual filestructure is:
/home/mydomain/public_html - the folder where the Document Root of Apache points
/home/mydomain/library/Zend
/home/mydomain/projects/myproject

the folder where the subdomain points is
/home/mydomain/projects/myproject/public

For more details look my post "Zend Framework Shared Hosting" It is ready I just have to correct it a bit.

No comments:

Post a Comment