Tuesday, January 25, 2011

Connect Cakephp application to remote database via SSH

Tested on ubuntu 10.4
Edit /etc/ssh/sshd_config on your local machine
Add:
AllowTcpForwarding yes
GatewayPorts yes

restart sshd
sudo /etc/init.d/ssh restart


Edit /etc/mysql/my.cnf on remote machine.
Uncomment the following line.
bind-address           = 127.0.0.1

restart mysql
sudo restart mysql

On you local machine run the following command
ssh -i e-keypair -f remoteuser@remote.com -N -L 4444:localhost:3306
If you are not using ssh key you will be prompt for remote user assword

Edit database.php

var $default = array(
        'driver' => 'mysqli',
        'persistent' => false,
        'host' => '127.0.0.1',
        'port'=>4444,
        'login' => 'user',
        'password' => 'pass',
        'database' => 'schema',
        'prefix' => '',
        );

Tuesday, December 21, 2010

Configure ubuntu server to host CakePHP

The following instructions was tested with ami-480df921 on Amazon web services (Ubuntu Lucid 10.4)


1. Update and upgrade the system

sudo aptitude update && sudo aptitude upgrade



2. Reboot
sudo reboot


3. install Lamp
sudo tasksel install lamp-server


4. Check installation
http://yourserver/
Output:

It works!

This is the default web page for this server.
The web server software is running but no content has been added, yet.



5. Enable mod_rewrite

sudo a2enmod rewrite


6. Edit /etc/apache2/sites-available/

<Directory /var/www/myproject>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
</Directory>

7. Copy your app folder to /var/www and replace "myproject"  from step 6 with your folder name.
Its also possible to copy the project folder to any other directory in your server and create a symlink under /var/www.

cd /var/www
sudo ln -s path/to/my/project/folder myproject

8.Check your site
sudo /etc/init.d/apache2 restart
http://yourserver/myproject

9. Enable writing on tmp folder
cd /myproject/app
chmod -R 777 tmp 

10. Set database connection in myproject/app/config/database.php


Thursday, December 2, 2010

Configure apache to host domain and subdomain - ubuntu

1. Copy default configuration file

cd /etc/apache2/sites-available/
cp default mydomain.co.il [or mysubdomain.mydomain.co.il]

2. Disable default site

sudo a2dissite default
sudo /etc/init.d/apache2 reload
sudo rm /etc/apache2/sites-available/default

3. Edit mysubdomain.mydomain.co.il the to look like this:
<VirtualHost *:80>
ServerAdmin siteadmin@mydomain
ServerName mysubdomain.mydomain.co.il
DocumentRoot /var/www/mysubdomain/
<directory>
   Options Indexes FollowSymLinks MultiViews
   AllowOverride All
   Order allow,deny
   allow from all
</directory>

...
...
</VirtualHost>






4. Create link in site-enabled folder and reload apache configuration file

sudo a2ensite mysubdomain.mydomain.co.il
sudo /etc/init.d/apache2 reload

5. Repeat for every domain/subdomain.

Based on http://phobienbuon.com/archives/202
Tested on Ubuntu 10.4