0
votes

I have a cakephp project under folder name FC which contains app folder, index.php etc. which i uploaded on ubuntu instance on ec2. When I uploaded the folder, it was showing index folder so I uploaded the contents directly under FC into www folder so it could get index.php file automatically. Now the website started displaying but plain, without css or images or js. I looked at error log, and it's displaying this:

[Wed Aug 28 14:15:56 2013] [error] [client xxxxxxxxxxxxxxxxx] File does not exist: /var/www/js, referer: http://xxxxxxxxxxxxxxxxxxxxxxxx.compute.amazonaws.com/

[Wed Aug 28 14:15:56 2013] [error] [client xxxxxxxxxxxxxxxxx] File does not exist: /var/www/js, referer: http://xxxxxxxxxxxxxxxxxxxxxxxx.compute.amazonaws.com/

Clearly this shows that the paths are being set incorrectly. Now the path I've given for my js and images is in webroot folder, so I have my images in img folder and js in js folder under webroot so as path i just provide "filename.whatever" and that worked fine on localhost. How do I need to set my paths so they will point to the correct place? When I inspect element on a botched image, it shows path /img/xxxx.jpg. Which means cake automatcally goes into image/js/css folder which is how my code was working on local machine. Now when I manually give path, like /www/app/webroot/img/xxx.jpg, it attaches itlike this: img/www/app/...etc. Please help! Is there documentation available on this or if someone has done this before?

EDITED: webroot/index.php:

if (!defined('DS')) {
    define('DS', DIRECTORY_SEPARATOR);
} 

define('ROOT', '/var/www/FC');   

define('APP_DIR', 'app');

define('CAKE_CORE_INCLUDE_PATH', DS . 'var' . DS . 'www' . DS . 'FC' . DS . 'lib');

BELOW THIS IS STANDARD CONTENT OF INDEX.PHP WHICH IT WRITTEN NOT TO CHANGE

sites-available/Default:

  <VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/FC/app/webroot
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride All
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

By the way, my Index.ctp redirects to multiple links which are located in LocationsController including index.ctp, whereas cake is trying to find FCController. Do i need to rename locationscont to FCcont to match conventions maybe?

*I just found out, the urls inside the view and controller etc. all start like this '/FC/locations/...etc.' Do I need to give urls from base path, ie '/var/www/FC...' ?? *

2

2 Answers

0
votes

If you're using apache your publicly accessible folder by default is /var/www/

The following instructions will change the documentroot and setup cake in the simplest way to get you started.

First stop your apache server for security reasons while you prepare everything.

sudo service apache2 stop

Then copy your project in /var/www/myproject. That means that you will be able to find the webroot in /var/www/myproject/app/webroot. Of course myproject can be any folder you wish, just stick to the same in all commands if you change it.

You will need to tell the app where to find cakePHP:

nano /var/www/myproject/app/webroot/index.php

Go to the line starting with define('CAKE_CORE_INCLUDE_PATH' and make it define('CAKE_CORE_INCLUDE_PATH', DS . 'var' . DS . 'www' . DS . myproject . DS . cakephp . DS . lib') - assuming cakephp/lib is to be found in /var/www/myproject/cakephp/lib or else amend as necessary.

Then tell apache what the new document root is:

sudo nano /etc/apache2/sites-available/default

and wherever you see /var/www change it to /var/www/myproject/app/webroot.

Just to be certain that the web service (apache) can access your files and write to cache, execute the following commands:

sudo chown www-data:www-data /var/www/myproject -R
sudo chmod 777 /var/www/myproject/tmp -R

Finally start your apache again:

sudo service apache2 start

If you now go to http://xxx.compute.amazonaws.com/ all should work.

If you don't see CSS applied, you need to enable the rewrite module:

sudo a2enmod rewrite && sudo service apache2 restart
0
votes

i sorted the issue out. It was because in my code, the previous user had made a controller file Locationscontroller.php and specified urls like this:

<form id ="0" action="/FC/locations/confirm_final">

This was for localhost in my local machine where the base folder was htdocs I had to type localhost/FC/ to access index.php. So naturally Since on EC2 I had made FC itself my base folder, it was trying to access another FC inside it which didn't exist. The /XXX/locations/ means it searches for "XXX" controller and then locations inside it. Since my controller was Locations, it kept giving an error.

As soon as I changed it to this:

<form id ="0" action="/locations/confirm_final">

It pointed to the right controller which was locations. It was all because I didn't check which controller was called by which View! I'm an idiot, that'll be all :D