Archive for the ‘Tutorials’Category

Fixing problems in Apache with case-sensitive URLs

Windows or Mac servers treat file names as case-insensitive, so Index.html and index.html are the same file. In Linux/Unix servers this is not the case, these files would be different. So when we create a link that does not match the case of the file name, you get an error. This is a common problem when moving files from Windows/Mac to a Linux production server and your links include incorrect case.

The ideal solution is to go over the entire site and correct these mismatches. But this may take some time and usually one finds out about the problem when the site has been moved and the domain pointed to the new server, so the problem has to be fixed ASAP.

There is a quick solution thanks to Apache’s mod_speling. If you need Apache to check different versions of a file name requested, you can use CheckCaseOnly and CheckSpelling directives. Adding one of these directives in a .htaccess file in the root directory of your site instantly fixes most of these problems. An example of this configuration is:

CheckSpelling on

We need to note that this method delivers a performance hit. Apache will have to double check each request for spelling when it does not find the file right away. So let it be noted that this is a quick fix; long term it is recommended that you backtrack and correct all the links.

24

08 2010

Symfony + Git + Capistrano = Capifony

Introduction

Deploying applications to production/live servers is always a delicate task. The whole process needs to be quick to minimize downtime. Automating the deployment process helps running repetitive tasks minimizing the possibility human error. It is also a good idea to have a proven and easy way to rollback to a previous version if something goes wrong.

Capistrano and more specifically Capifony can help with the automatic deployment of symfony projects.

What is Capistrano?

Capistrano is a time saving command line tool, written in Ruby, that helps you execute automated tasks on remote servers from your local environment. It also allows you to run symfony commands. Capistrano was built to help you administer all your servers from one place, running commands, installing software and keeping everything in sync. Oh… and of course it has a rollback mechanism.

It’s one of those tools Ruby developers have that we often wish we had in symfony, and now we do. Enter Capifony…

Capistrano commands

Capistrano has 2 base commands:

1. `capify …`;
2. `cap …`.

Capify will create 2 files in a specified path (1st argument of `capify`):

1. `Capfile` – capistrano loader. It loads all basic libraries & project config file;
2. `config/deploy.rb` – project config file. Your configs & variables setup for project placed here.

The second command, `cap`, actually runs capistrano tasks on the remote server with config from your `config/deploy.rb`.

A capistrano recipe is a package of tasks, grouped into namespaces. You can use embedded tasks or write your own (place them in your `config/deploy.rb`). Once a task is written you can run it with `cap` command under your project directory:

cap namespace:task

Deployment recipe
—————–

As mentioned above, Capistrano is typically used to deploy Ruby On Rails applications. How does it work? Basically, capistrano must know 4 things:

1. addresses of your web, app & db servers (most often it’s the same address);
2. address of your source code control system repository (if you have one).

Keep in mind, that capistrano uses SSH to run remote tasks so you will need to have shell access to all your remote servers.

During the deploment process, Capistrano will maintain different files & directories on server. It will create a `releases` directory that has dated directories with the actual copy of your code for each release. In addition, Capistrano symlinks your shared folders (common between releases) into release directories, so logs, assets & other files keeps the same between deployments.

What is Capifony?

Capifony is a new RubyGem package, that extends Capistrano functionality so it can work with symfony PHP projects. In essence it’s a package of custom and extended original capistrano recipes.

Demo project

To fully understand how capifony works and what it does we need to create one simple symfony application and deploy it to our test server.

Step 1: Install

I assume that you already have Ruby & RubyGems installed on your local environment (MacOS X has this out of the box – simply update gems with `sudo gem update –system`).

To install capifony and capistrano, simply run:

gem install capifony

This command will install capifony and it’s dependencies (capistrano for example) to your local host. NOTE: Your local host is the only place where you need to install capifony & capistrano.

It’s also good practice to create and copy the SSH key to speed up the connections to your remote repositories.

Generate key with:

ssh-keygen -t rsa

Next, copy your public key to remote server that you want to connect to (I am going to assume your SSH user is called `demoUser`):

cat .ssh/id_rsa.pub | ssh demoUser@your.domain.com "cat >> .ssh/authorized_keys2"

Then just try to connect with:

ssh demoUser@your.domain.com

If all goes well the remote server will just let you in without password prompt.

We then need to create the project repository on server, so let’s create one:

ssh demoUser@your.domain.com
sudo mkdir /var/repos
sudo chown demoUser !$
cd !$
mkdir demo.git
cd !$
git --bare init

Step 2: Symfony project setup

Lets create empty git repository for our new demo site (we will use git as SCM, but you can use subversion or any other source code manager that’s supported by capistrano):

cd /var/www
mkdir demo
cd !$
git init
touch .gitignore

Now add these lines to your `.gitignore` to exclude asset symlinks, databases config, cache, backups, uploads & log folders from our git repository:

web/sf*
web/uploads/*
cache/*
plugins/.*
log/*
config/databases.yml
mkmf.log
.rsync*
backups/*

It’s time to add `.gitignore` to stage and make our initial commit:

git add .gitignore
git commit -m 'initial commit'

Finally we can generate skeleton for our demo project and commit it:

symfony generate:project demo
git add .
git commit -m 'symfony project created'

Now lets add the database schema to `config/doctrine/schema.yml`:

	---
	Topic:
	  actAs:
	    Timestampable:    ~
	  columns:
	    id:
	      type:           integer(4)
	      primary:        true
	      autoincrement:  true
	    title:
	      type:           string(256)
	      notnull:        true
	    content:
	      type:           clob
	      notnull:        true

And add some fixtures into `data/fixtures/fixtures.yml`:

	Topic:
	  topic1:
	    title:    First topic
	    content:  first topic content
	  topic2:
	    title:    Second topic
	    content:  second topic content
	  topic3:
	    title:    Third topic
	    content:  third topic content

Build database and model files:

symfony doctrine:build --all --and-load --no-confirmation

And you need to generate the `frontend` application and put `main` module in it:

symfony generate:app frontend
symfony generate:module !$ main

To make this more interesting let’s put some logic for our application. Go to `apps/frontend/modules/main/actions/actions.class.php` and replace the `executeIndex` function code with this:

/**
* Executes index action
*
* @param sfRequest $request A request object
*/
public function executeIndex(sfWebRequest $request)
{
   $this->topics = Doctrine::getTable('Topic')->findAll();
}

And the view. Go to `apps/frontend/modules/main/templates/indexSuccess.php` and add:

<dl>
  <?php foreach ($topics as $topic): ?>
    <dt><?php echo $topic->getTitle() ?></dt>
    <dd>
        <?php echo $topic->getContent() ?>
    </dd>
  <?php endforeach; ?>
</dl>

Now if you open http://your.local.demo.host/frontend_dev.php/main in browser you will se definition list with our 3 topics.

Add changes to git:

git add .
git commit -m 'finished project'

Stage 3: symfony library with project

It’s good practice to include the dependent version of symfony in your project repository. You can do this in two ways:

1. Simply copy symfony library under `lib/vendor/symfony` directory & commit it;

or

2. Submodule symfony library from another repository.

I like second way. To do this, we will submodule Vincent Jousse’s symfony 1.4 git mirror:

git submodule add http://github.com/vjousse/symfony-1.4.git lib/vendor/symfony

Don’t forget to fix symfony path in `config/ProjectConfiguration.class.php` (after both ways) from:

require_once '/opt/local/lib/php/symfony14/lib/autoload/sfCoreAutoload.class.php';

to

require_once dirname(__FILE__) . '/../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php';

And commit this:

git add .
git commit -m 'bundled symfony'

Step 4: Push local project to remote git repository

Remember our `demo.git` repository on `demoUser@your.domain.com` that we’ve created earlier? It’s time to push our project to it:

git remote add origin 	ssh://demoUser@your.domain.com/var/repos/demo.git
git push origin master:refs/heads/master

Now your project is pushed to remote repository, where anyone who has SSH access can push/pull it. Also, we will use this repository to deploy new versions with capistrano.

Step 5: Config

Now is the time to play with capifony itself. First of all, lets “capifony” our project:

capifony .

Capifony created `Capfile` and `config/deploy.rb`. Go into `config/deploy.rb` and edit it’s variables. To set capistrano config variables, you need to call `set :var_name, “var_value”` instruction inside `deploy.rb`. Below is the list of main variables:

* `:application` – set your application name here (“demo” in our case);

* `:domain` – domain of our remote server. This variable will be auto-populated with `#{application}.com` (demo.com in our case). Place your server address here if it’s not `demo.com`. I set it to `#{application}.everzet.com`, because my test host is http://demo.everzet.com;

* `:deploy_to` – path, where we will deploy our application (in most cases `/var/www/#{domain}`);

* `:repository` – path to repository (`#{domain}:/var/repos/#{application}.git` in our case);

* `:scm` – source code management tool. In our case set it to `:git`, but it can be any of `accurev`, `bzr`, `cvs`, `darcs`, `subversion`, `mercurial`, `perforce`, `subversion` or even `none`;

* `:use_sudo` – set to `false`, because we doesn’t need sudo during our deployment process;

* `:deploy_via` – set it to `:remote_cache`, so deployments will last less time;

* `:git_enable_submodules` – set it to `1` if you have submodules in project (if you staged symfony as submodule for example);

Also add this line to `config/deploy.rb`:

ssh_options[:forward_agent] = true

if you want to use your local SSH key instead of remote one for git checkout.

Your resulting `config/deploy.rb` is must be something like this:

set  :application,            "demo"
set  :domain,                 "#{application}.everzet.com"
set  :deploy_to,              "/var/www/#{domain}"

set  :scm,                    :git
set  :git_enable_submodules,  1
set  :repository,             "#{domain}:/var/repos/#{application}.git"
set  :deploy_via,             :remote_cache

role :web,                    domain
role :app,                    domain
role :db,                     domain, :primary => true

set  :use_sudo,               false
set  :keep_releases,          3
ssh_options[:forward_agent] = true

Step 6: Deployment

To start, we need to know 3 basic capistrano commands:

1. `cap deploy:setup` – create directories on server;
2. `cap deploy:cold` – copy code, build database, make symlinks;
3. `cap deploy` – copy code, make symlinks.

Now run:

cap deploy:setup

This command will create the following folder structure on your server:

	`-- /var/www/demo.everzet.com
	  |-- releases
	  `-- shared
	    |-- log
	    `-- web
	      `-- uploads

After few deployments, folder structure will eventually become something like this:

	`-- /var/www/demo.everzet.com
	  |-- current (symlink)
	  |-- releases
	    |-- 20100512131539
	    |-- 20100509150741
	    `-- 20100509145325
	  `-- shared
	    |-- log
	    |-- config
	      `-- databases.yml
	    `-- web
	      `-- uploads

What does all this mean?

1. `releases` is folder, where all your releases sits. Every release is a timestamped folder under `releases` directory.

2. Every release has symlink to shared files and folders, placed in `shared` directory. This files & folders stays same between deploys;

3. capistrano creates symlink to latest release, called `current`. This is your current project folder to work with (where to point web servers, crontabs etc.).

Now lets deploy our application for the first time:

cap deploy:cold

If you’ve configured your remote server hosts right, you now can open http://your.remote.host/main & see you symfony application there.

Step 7: Deploy & Rollback

Now what if we change something, deployed it and it’s broke our site? Lets break something!

Open `apps/frontend/modules/main/actions/actions.class.php` and change

$this->topics = Doctrine::getTable('Topic')->findAll();

to

$this->topics = Doctrine::getTable('TopicS')->findAll();

Save it, commit it and push to remote repository:

git add .
git commit -m 'buggy change'
git push origin master

Now deploy this bug:

cap deploy

and try to open http://your.remote.host/main. Oh, no! Something broke. What to do? Simple! Run:

cap deploy:rollback

and capistrano will roll your server back to previous working version of project and you will be able to find, fix, push and deploy the bugfix later, without problems.

Conclusion

Capistrano is mighty tool that has served RoR developers for many years. Now the symfony world can use these best practices in their development workflow. It’s as simple as installing capifony gem.

If you want to add/request something or read further manuals – please, visit project repository on github.


About the Author

Konstantin Kudryashov (aka everzet) is a web developer from Minsk, Belarus. Most of the time, he builds symfony applications. When he’s not – he maintains symfony bundles for TextMate, writes symfony plugins & php libraries.

12

07 2010

Installing Redmine on VPS

Redmine is a web based application for project management built on Ruby on Rails. It has become quite popular these days; even with those of us that did not drink that Ruby on Rails Kool Aid. While our VPS hosting packages are fine tuned for running PHP applications, RoR runs really smoothly on our machines and you can readily install a Rails app on your VPS without interfering with your PHP side of things. While this tutorial was tested on our VPS hosting packages, it’s generic enough that it should work on any other VPS or dedicated server out there.

Installing Redmine in a VPS that has no Rails is still quite easy. Here is a quick guide:

Install Ruby and Rails

This is done in a few simple steps, first download the Ruby source code, uncompress it and compile it:

  1. Download the source code.
  2. uncompress by running the command:
    tar zxvf ruby-1.8.7-p174.tar.gz
  3. go into the new directory and run:
    ./configure
    make install

Download RubyGems package manager. RubyGems is the Ruby standard for publishing and managing third party libraries.

  1. Download the package
  2. uncompress it with: tar zxvf rubygems-1.3.6.tgz
  3. go into the new directory and run:
    ruby setup.rb
  4. Install Rails by running:
    gem install rails

Install Passenger

Passenger in an Apache module to serve Rails applications.

Installation steps:

  • run:
    gem install passenger
  • run:
    passenger-install-apache2-module
  • Configure Passenger by creating a file /etc/httpd/conf.d/rails.conf and putting this inside:
    LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/ext/apache2/mod_passenger.so
    PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11
    PassengerRuby /usr/local/bin/ruby
  • Add a virtual host section for your application by adding a file /etc/httpd/conf.d/redmine.conf and putting inside:
    <VirtualHost *:80>
      ServerName redmine.example.com
      DocumentRoot /usr/local/redmine/public
      <Directory /usr/local/redmine/public>
        AllowOverride all
        Options -MultiViews
      </Directory>
    </VirtualHost>

And finally, Install Redmine

  1. Checkout the SVN repository:
    cd /usr/local/
    svn co http://redmine.rubyforge.org/svn/trunk redmine
  2. Configure MySQL, create the database and DB user:
    create database redmine character set utf8;
    create user 'redmine'@'localhost' identified by 'my_password';
    grant all privileges on redmine.* to 'redmine'@'localhost';
  3. Copy config/database.yml.example to config/database.yml and edit this file in order to configure your database settings for “production” environment. Example for a MySQL database:
    production:
      adapter: mysql
      database: redmine
      host: localhost
      username: redmine
      password: my_password
  4. Go into the redmine directory and generate the session store secret by running:
    rake generate_session_store
  5. Generate the DB structure by running:
    RAILS_ENV=production rake db:migrate
  6. Insert the DB default data by running:
    RAILS_ENV=production rake redmine:load_default_data
  7. Go into public and run:
    cp dispatch.rb.example dispatch.rb
    chmod a+x dispatch.rb
    mv .htaccess .htaccessbak

Testing your installation

When all these is complete, test your Apache configuration by running:

/etc/init.d/httpd configtest

If no errors were found, restart Apache:

/etc/init.d/httpd restart

Load your redmine installation and login with admin / admin.

Tags: , ,

29

03 2010

Installing Apostrophe CMS on shared hosting

Here is a quick guide to get Apostrophe CMS, up and running on our Shared hosting servers.

We are going to assume that you either have Apostrophe running on your local development environment, or that you will install the sandbox version that you can download from the site.

Installing the Apostrophe Sandbox

First of all, login to your Control Panel account and make sure you have SSH enabled for your domain. This can be done in the Setup section of the domain.

Enabling SSH

Enabling SSH

Next, in the Control Panel, go ahead and create your database and database user. Go to Databases under your domain and add a new database and then a new username.

Next, connect with your SSH client go to /symfony_projects directory and execute:

svn co http://svn.apostrophenow.org/sandboxes/asandbox/branches/1.3 asandbox

Once it finished executing all the SVN checkouts, you will have a complete Apostrophe installation in asandbox. Go into asandbox directory and create copies of the needed configuration files:

cd asandbox
cp config/databases.yml.sample config/databases.yml
cp config/properties.ini.sample config/properties.ini

Edit config/databases.yml and configure the database connection with the database/username created in the previous step. Make sure to change dbname, host, username and password to match your account.

all:
  doctrine:
    class:        sfDoctrineDatabase
    param:
       dsn:        mysql:dbname=ademo;host=sg108.servergrove.com
       username: ademo
       password: yourpassword

Run the following symfony tasks:

./symfony cc
./symfony plugin:publish-assets
./symfony doctrine:build --all
./symfony doctrine:data-load

This will create the default database and load the default configuration. You can also setup a default demo by running:

./symfony apostrophe:demo-fixtures

And finally run:

./symfony project:permissions

Before you are done there is a very important step. You need to configure the web server to use your Apostrophe installation. Go into the control panel and into the Maestro section. Select the asandbox project and go to Setup WebServer and click OK.

Setting up Apostrophe with Maestro

Setting up Apostrophe with Maestro

At this point, your Apostrophe installation has to be working, so go ahead and load your site

Apostrophe demo running

Installing Apostrophe from your development environment

If you have Apostrophe running in your development environment there are many common steps with the sandbox installation. First, enable SSH and create the database and database user in the Control Panel as described above. Then import a SQL dump of your database and import it using the DB WebAdmin in the Control Panel.

Next, upload your Apostrophe project into symfony_projects. You can upload the files using a FTP client or you can checkout your SVN repository or clone your GIT repository using the SSH client. Edit databases.yml so the connection information matches the shared hosting server settings as done in the sandbox installation above.

Next, run the following commands

./symfony cc
./symfony plugin:publish-assets
./symfony project:permissions

And finally, use Maestro as described in the sandbox installation to setup the web server to use Apostrophe project. It is that simple!

24

03 2010

Setting up sftp in Dreamweaver using a specific sftp port

SFTP stands for SSH File Transfer Protocol and it uses the SSH protocol to reliably and securely transfer files. While using sftp on Dreamweaver is not too complicated, setting it up to use a specific port is not well documented. SFTP uses the same port as SSH, the default port is 22 but it is not uncommon that you will be assigned a custom port as this is a standard practice to avoid brute force SSH scanning.

Setting up SFTP on Dreamweaver

Open up the sites manager and choose to setup a new site.

sftp dreamweaver 1

Proceed to setup the site as you normally would any other site on Dreamweaver. Once you get to the “remote setup” you will need to define the port number. The default port for sftp in Dreamweaver is port 22. If you select you want to use sftp and do not define the port number, Dreamweaver will automatically try to use port 22. To use an alternate port you must define it in the FTP Host field like this ” hostname:portnumber “. So if I want to access files on example.com using port 21324 I would put in the FTP host field example.com:21324

Setting up sftp using dreamweaver

Once you are done, click on test connection to verify if everything is working correctly.

29

11 2009

Using CKEditor in symfony 1.2 admin generator

The symfony admin generator is a BIG time saver. It’s almost like magic, it generates an administration interface based on your database models. If you spend countless hours creating lists and forms to manage data in tables, you are crazy not to use it.

When you have HTML content in a table, the ideal is to show a WYSIWYG editor instead of the TEXTAREA where the HTML will be displayed. In older versions of symfony, TinyMCE was integrated. With the release of symfony 1.2 the approach was to decouple some of the functionality so you could use different libraries. This is a good thing, but the admin generator suffered a bit. Some things that were very easy to accomplish, became a bit too hard, one of these things is the ability to display a WYSIWYG editor.

CKEditor is the successor of FCKeditor, probably because some people to name it a “bit” differently (you figure it out) due to some difficulties when using it. What’s important is that CKEditor is an amazing piece of software. A very powerful and feature rich HTML editor that runs inside a browser.

In order to use CKEditor in a symfony 1.2 generator admin interface, follow these steps:

a) download CKEditor, and place the files in your web directory.

b) add CKEditor javascript to your apps/[yourapp]/config/view.yml


javascripts:    [/js/ckeditor/ckeditor.js]

c) edit apps/[yourapp]/modules/[yourmodule]/config/generator.yml and add the class ‘ckeditor’ to the field that will be your editor. Make sure the field is displayed as a TEXTAREA in your form (TEXT and LONGVARCHAR database types work)

config:
actions: ~
fields:  ~
list:    ~
filter:  ~
form:
  fields:
    content:      { attributes: { class: ckeditor }}
edit:      ~
new:     ~

# make sure you keep the proper indentation in your yaml code.

content is the field that contains HTML code in our example.

And that’s it! Since you are loading the javascript for CKEditor in your view configuration, it will look for any TEXTAREA with a class “ckeditor” and will replace it with a CKEditor instance.

Tags: ,

07

10 2009

WordPress: The uploaded file could not be moved

One of the most common errors after installing WordPress on your hosting account is the “The uploaded file could not be moved” error when trying to upload a file. Typically the error message looks like this:

The uploaded file could not be moved to /var/www/vhosts/domain.com/httpdocs/wp-content/uploads.

This is a common error due to permissions. I got this error fixing a WordPress instalation on another host which, will remain unnamed, for a treasonist family member who does not use ServerGrove, who will also remain unnamed. I did some research and while reading the solutions out there I was amazed to see the amount of posts asking people to chmod 777 their entire wp-content and wp-content/upload directory. Let me say this once: it’s never a good solution to chmod 777 an entire directory.

Let’s analyze the problem to better understand what’s going on. When you create directories either via FTP or via some other method, the directory is owned by the user that created that directory. So when you upload your WordPress via FTP the directories are owned by your user. Then when we try to upload images via the WordPress admin we are uploading via a web page we are actually uploading via http, and items uploaded through http are owned by the Apache user, master of http. So when the Apache user tried to put a file in the folder owned by your user, Linux steps in and notes there is a permission problem. You cannot put content into a directory owned by another user and spits back the error:

The uploaded file could not be moved to /var/www/vhosts/domain.com/httpdocs/wp-content/uploads.

So, the question rises, why does this happen on some hosts and does not happen on other hosting companies like ServerGrove? Well for one, we are wise, and know that permissions errors are very common and easily avoidable (kind of like acne). The solution lies in the way your shared hosting server is setup, some hosting companies slap the default installations and other wiser ones spend their waking hours fine tuning the servers and making them perform faster and work better for their clients.  Our servers are configured so Apache runs as the same user as your user (a different one for each website), this means that your user and Apache are the same which makes everyone’s life easier. This simple permission error would never happen on our servers and had my weasel family member setup on ServerGrove he would not have had to ask for my help.

Tags: ,

22

09 2009

Flash uploader does not work in password protected directories

I was working with SlideshowPro and could not get the images to upload. There was no error in the log files, nothing. All I got was an error message from ssp asking me to edit the .htaccess file. I did that and still no success. I checked the access log and:

[...]“POST /photoadmin/index.php?/uploads/image/3/4/1 HTTP/1.1″ 401 1516 “-” “Adobe Flash Player 10″

Finally it came down to disabling the password protection for the site. Since my site was still in development, I decided to password protect it. Disabling the password protection allowed the flash image uploader to work fine. The downside is that now my site is unprotected.

Tags:

01

09 2009

How to install an SSL certificate on Apache

In order to install a SSL certificate on a CentOS Virtual Server, make sure your plan includes a dedicated IP address. If it does not, contact us so we can assist you with adding one to your account.

To install the SSL certificate follow these steps:

  1. Create a file /etc/httpd/conf.d/cert.key and place the content of the certificate key in it. It will look like (with more lines):

    —–BEGIN RSA PRIVATE KEY—–
    MIICXgIBAAKBgQDsvYWqOtJBR+j15pCITwyM48Cp3rBArdJOsOjoFrU2CXiDpYAb
    4ZiA3CD+wTQtod+3aeRTAkEAuXfD0NSgcTYsqHS+HHUyDZifrjZBPhBNL4ONAvof
    ReXZzngKgFTGhfUm0Ypu6QVTRHit+Miv+AyY72KCUsN4/A==
    —–END RSA PRIVATE KEY—–

  2. Create a file /etc/httpd/conf.d/cert.crt and place the content of the certificate in it. It will look like (with more lines):

    —–BEGIN CERTIFICATE—–
    MIIDODCCAqGgAwIBAgIDC+KlMA0GCSqGSIb3DQEBBQUAME4xCzAJBgNVBAYTAlVT
    MRAwDgYDVQQKEwdFcXVpZmF4MS0wKwYDVQQLEyRFcXVpZmF4IFNlY3VyZSBDZXJ0
    UeHR9A2VwXvIbcrxYoLLFZraqI56CNwRCNIsUB9Z9k+6Y0J+A2iRo75Ws2cHPAMc
    97keASGvyDZy1w9W
    —–END CERTIFICATE—–

  3. Edit /etc/httpd/conf.d/ssl.conf and change SSLCertificateKeyFile and SSLCertificateFile directives so they point to the files listed in 1 and 2.

    SSLCertificateFile /etc/httpd/conf.d/cert.crt
    SSLCertificateKeyFile /etc/httpd/conf.d/cert.key

  4. Restart apache by running service httpd restart

15

07 2009

Setup guide for installing a symfony project to ServerGrove shared hosting accounts

One of the things we spend lots of time on, is trying to make application deployment as simple as possible so developers can focus on development. We are developers as well, so when we finish a project, we want to upload it, test it and start on the next project. Keep it simple, move on. Like you, we don’t like to fight with configuration, permissions and whatever other issues may delay our deployment. Most of our in-house projects are developed in symfony, so we have gotten particularly good at fine tuning our servers for this framework (not to mention it’s the best framework in the world).

As a policy, we help all our clients with migration and installation issues. A great majority of our support time is dedicated to this type of service, so the easier it is for people to install their apps, the less time we spend answering tickets. We like to call this: motivation.

While most people seem to be figuring out how to use Maestro and get their apps up and running on our servers without much difficulty, we decided to write this setup guide for setting up symfony applications quickly on ServerGrove shared hosting accounts.

1) Preparation

There are a few steps you can take to make the installation of your application a breeze, and while we try to configure our servers to be as transparent as possible for developers, it is impossible to match everybody’s environment and/or preferences. Here are a few things to keep an eye out for:

a) Make sure all paths are unix-based. Developers running on windows will have their paths with C:\symfony or similar structures. Our servers run on Linux, so you need to use unix-based paths like /usr/local/php/symfony12

b) The Linux filesystem is case-sensitive, so Symfony and symfony will be different names. Make sure your code paths and file names match the names of the files and directories.

c) On shared hosting accounts, your home directory will be in /var/www/vhosts/example.com . Your symfony project files will reside in /var/www/vhosts/example.com/symfony_projects/PROJECT_NAME (replace example.com and PROJECT_NAME with your names, remember, domain names are lowercase and the project names are case-sensitive). Keep these paths and names in mind as you will need to use them in different places to properly configure your project and applications.

2) Paths Configuration

Before you upload your symfony project, you need to configure your project to find the symfony library. All our servers have symfony libraries pre-installed, so you can use the server-wide installation.

a) Use server-wide symfony installation (recommended)
The server-wide libraries are in /usr/local/php/. Here are the paths for the different versions of symfony:
symfony 1.0.x : /usr/local/php/symfony10/lib
symfony 1.1.x : /usr/local/php/symfony11/lib
symfony 1.2.x : /usr/local/php/symfony12/lib

To configure a Symfony 1.0.x project, edit config/config.php and setup the proper paths for the symfony library:

<?php

// symfony directories
$sf_symfony_lib_dir  = '/usr/local/php/symfony10/lib';
$sf_symfony_data_dir = '/usr/local/php/symfony10/data';

To configure a symfony 1.1.x, edit the config/ProjectConfiguration.class.php file:

<?php

require_once '/usr/local/php/symfony11/lib/autoload/sfCoreAutoload.class.php';
sfCoreAutoload::register();

class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
// for compatibility / remove and enable only the plugins you want
$this->enableAllPluginsExcept(array('sfDoctrinePlugin', 'sfCompat10Plugin'));
}
}

To configure a symfony 1.2.x project, edit the config/ProjectConfiguration.class.php file:

<?php

require_once '/usr/local/php/symfony12/lib/autoload/sfCoreAutoload.class.php';
sfCoreAutoload::register();

class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
// for compatibility / remove and enable only the plugins you want
$this->enableAllPluginsExcept(array('sfDoctrinePlugin', 'sfCompat10Plugin'));
}
}

b) Alternatively, you can upload your symfony library. If you do so, make sure you configure your project to have the correct unix paths described in bullet 1.C

3) Database configuration

Your symfony applications will probably use Mysql to load and save data. The Mysql database will be running in localhost. We recommend that you create the database and tables, and load the data before uploading the site. In order to do so:

a) login into the Control Panel with your username and password which you can find in the email with subject “New account information”.

b) once in the control panel, select the domain and go to the Databases section.

c) create the database and then create the user to access the database.

db

db2

d) click on the phpMyAdmin icon, this will open a popup with the admin interface.

e) select the database. Now you can import a SQL file with all the statements to create tables and insert data

db3

Refer to the phpMyAdmin manual for more information on how to use this powerful tool.

4) Transfer files

You already configured your paths, created the database and imported the data. Now you are ready to upload the project files. You will need to use a FTP client to connect to the server. You can find the FTP login information in the email with subject “New account information”.

Once you have connected to the server, go into the symfony_projects directory. Upload your project so all the project files end up in the contained in a directory residing in symfony_projects (ie. symfony_projects/myproject)

5) Configure Apache to use your symfony project web root.

Once you finished upload the files, it is time to configure the Apache web server to use the project web directory as the document root. For this, we recommend that you use our Control Panel extension, Maestro. To learn more about Maestro, go to the release announcement and watch the screencast

maestro

6) Something is wrong…

If something did not go right, we recommend that you look at the different log files that may contain critical information to fix the problem:

a) the Apache error log may contain warnings about Apache configuration error, the file is located in statistics/logs/error_log

b) in our servers, each website has its php error log. This file may contain warnings and fatal errors, you can find this file in statistics/logs/php.log or you can see it online through Maestro’s ajax-based log viewer.

c) if your symfony application is configured to log errors and messages, you can find those in symfony_projects/PROJECT_NAME/log

logviewer

If you are unable to find any errors or locate the problem, feel free to contact us and we will assist you to get your site running as fast as possible.

7) Done!

If you followed these steps, your symfony-based site should be up and running.

We would like to hear from you: Please take some time to tell us how was your installation and setup experience, and specially, if there are any steps that need improvement.

22

06 2009