Archive for the ‘Tutorials’Category

Write a Tutorial

Write an article or a tutorial about symfony, zend framework, php, wordpress or and other technology offered and supported by ServerGrove and we will pay up to $200 for accepted articles. To get involved read our guidelines and pitch your idea. If you have an idea for an article you think should appear in our blog, submit it to the comments area, perhaps someone will pick it up.

Maestro Screencast

Some of you have asked for a screencast. Here it is. Send us feedback and feature requests, we are interested to know what you think.

Get Adobe Flash player

26

03 2009

Introducing Maestro for managing symfony applications on shared hosting

We have two big symfony related announcements to make today!

1) We have four new shared hosting environments configured and performance tuned exclusively for running symfony applications. Cheaper and better, view plan details here.

2) We also launched Maestro, an exclusive extension to our control panel to facilitate deployment, debugging and management of symfony applications on shared hosting accounts.

What is Maestro?

Maestro is an extension to our hosting control panel that will allow our shared hosting users to easily deploy and manage multiple symfony applications. Some of its key features are:

  • Install, configure and deploy your project with our Apache Web Servers easily and quickly.
  • Manage the Apache configuration changes that need your Symfony-based sites, including the document root, .htaccess and mod_rewrite configuration.
  • Includes an Ajax based log viewer so you can monitor symfony generated logs and PHP error log all from your browser.
  • Run symfony commands like clear cache and fix permissions from your browser.
  • Enhanced shared hosting security by running each website under its own user, preventing other users in shared server to access your files, cache and session data.  Additionally since your site runs with your FTP user, there are no permissions conflicts between the files you upload using FTP and the files generated by your site.

How do I use Maestro to setup my symfony project?

1. Upload your symfony project directory using your favorite FTP client

File Structure

File Structure

2. Configure your symfony project to use the server-based symfony installation

<?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'));
}}

3. Launch Maestro, click on the “Setup Web Server” button, and hit OK

Steps to launch a symfony application

Steps to launch a symfony application

4. Open your site in the browser, that’s it!

View your site using the preview link or your URL

View your site using the preview link or your URL

Features in detail

  • Manage symfony projects Maestro lets you manage all your symfony projects within each domain. When you launch Maestro, after selecting the domain in the control panel, you get the list of projects under the directory symfony_projects. It shows the symfony version, and URL/web root if it is active. You can have multiple projects and activate them as needed.
Select applications you want to manage from the projects list

Select applications you want to manage from the projects list

  • Know everything about your project Maestro features a check list of things that need to be configured in order for your project to run successfully. Checks permissions, paths and configurations and suggests fixes to get your application running painlessly.
Know everything about your project at a glance

Know everything about your project at a glance

  • Run commands from your browser
    symfony tools

    symfony tools

  • Ajax-based log viewer Maestro provides a log viewer so you can monitor log messages generated by your symfony application. You can also view the PHP error log.

Ajax based log viewer

Ajax based log viewer

  • Run symfony tasks from your browser Maestro lets you run symfony tasks like “clear cache” and “fix permissions” and view the output right from your browser, no need to get a SSH account and login, change directories, etc.  Additionally, fix-permissions is done a bit differently: Key files and directories are set to 700 so only your user can access them, providing extra security for cache and log files.
ajax based clear cache

ajax based clear cache

  • Easy Web Server Setup How many times you uploaded your project to a web host and had to fight countless hours to get your site running? Fight no more! Maestro manages all Apache configuration for you, including .htaccess and mod_rewrite. Just go to “Setup Web Server” and hit OK. The rest is done for you.
Configure your webserver from your browser

Configure your webserver from your browser

  • Enhanced security Symfony developers often discussed about the drawbacks and security concerns regarding hosting symfony application in shared hosting servers. We listened.At ServerGrove, your site runs under your userid, not the Apache user. This means that all files generated by your site will be owned by you. Other users in the server are not going to be able to access them. Your cache and log files are safe. Additionally, if you run “fix-permissions” from Maestro, we set the cache, log and web/uploads permissions to 700 instead of 777 where every user in the server can access them, providing extra security. That’s not all! Every domain has its own sessions directory where all PHP session files are placed and owned by your user. Traditionally, PHP uses a centralized directory for session storage, on shared hosting this is not a very good idea. We still recommend our customers who are very concerned about security to purchase a VPS hosting account where you don’t share Apache or the file system with other hosting customers.
  • Save all your session files in your personal directory. When we configure your domain, PHP is configured to save all session files in your personal directory and since your site runs with your userid, the session files are not readable by other users.

  • No more file permissions conflicts Since your site runs using the same user as your FTP account, you won’t have any more conflicts of permissions between files uploaded through FTP and those created by your site.

Learn more about our hosting products preconfigured to run your symfony applications here

24

03 2009

Symfony plugin sfJabberJaxl released to the public

As promised a few weeks ago, we are releasing to the public a Symfony plugin that let’s your Symfony based applications interact with Jabber accounts. This means that your application can communicate with IM users of Google Talk and other Jabber (XMPP based) servers.

The possibilities are endless, here are just a few ideas:

  • send and receive messages
  • monitor contact online status
  • execute server/application side operations controlled by IM users

The plugin offers:

  • a daemon that is in charge of keeping the “bot” like user online, receives and sends messages, changes online status.
  • a set of CLI tasks to send messages, and change status
  • a set of API methods to use from your existing applications
  • a set of callbacks that are executed from events within the daemon (ie. calls a method in your application when a message is received)

We are using this plugin in some of our applications. For example, our Live Chat system keeps track of the operators availability by monitoring the IM users online status. It also notifies the operators of incoming chats by sending messages to the IM accounts. By using this method, we are not require to use any special clients or open special websites to signup to our Live Chat system.

We are also developing other exciting applications that will interface with IM using this plugin, so stay tuned for future announcements!

This is our way of giving back to the Symfony community and we hope new and cool applications get created. If you do, we want to hear from you!

You can find the full documentation for the plugin at the plugin official home page.

If you have suggestions, improvements or any comments regarding this plugin, please let us know!

20

03 2009

20 Useful PHP Components & Tutorials for Everyday Projects

A very nice collection of php tutorials and tools showed up this morning. It was worth sharing.

02

03 2009

Send emails with PHP and Swift

Swift is a powerful PHP library to send email messages, much better than using the mail() native function. It offers a very nice set of features, some of these are:

  • Better performance
  • Multiple connection types (basic mail() function, SMTP)
  • Full Mime 1.0, attachments and embed images
  • HTML support
  • Multiple authentication mechanisms
  • many more

It is very popuplar among symfony users.

At ServerGrove we have added this library to all our servers, so now you can use it without having to upload it to the server. Here are the steps to use it:

The library is located in /usr/local/php/Swift and it will kept up to date with new releases.


<?php

require_once "Swift/lib/Swift.php";
require_once "Swift/lib/Swift/Connection/NativeMail.php";

$swift = new Swift(new Swift_Connection_NativeMail("-fyou@example.com"));

if ($swift->send($message, "recipient@example.com", "you@example.com"))
{
echo "Message sent";
}
else
{
echo "Message failed to send";
}

?>

For more information check out the Swift documentation which is pretty good.

12

02 2009

The RSpec Book

The long anticipated RSpec book by David Chelimsky is out, well sort of… It is available as a PDF Beta version. Still, I am excited to finally have access to it. I saw a presentation by David at Rails Summit Latin America, and if his talk is any indication of the quality of the book, it should be well worth the read. His introduction to TDD (Test Driven Development) and BDD (Behavior Driven Development) and discussion of related tools in his talk at Rails Summit was first rate, and I’m looking forward to reading more about the subject in greater detail and depth.

The RSpec Book: http://www.pragprog.com/titles/achbd/the-rspec-book

09

02 2009

Sharing templates with WordPress and Symfony

In this post we will explain how we were able to use Symfony templates in WordPress, allowing us to avoid duplication of files and code, and still carry the same look and feel of our main website (which runs in Symfony) into our Blog.

When making changes in the templates of our symfony-based site, those changes are immediately available in the Blog which runs on WordPress without having to copy code or files.

In our case, we wanted to have the top section of our website (header and top navigation) and the footer in both the corporate website and Blog.

The way we had built our site proved to be very useful and time saving, this is how we defined it in symfony:

  • The top header and navigation of the site was placed in a global partial named _topnav.php, which is located in the templates directory of the application (apps/site/templates).
  • The footer of the site was placed in another global partial named _footer.php, and it is located in the same directory.
  • Then, we included these partials in layout.php also located in this directory. It looks like this:
include_partial('global/topnav');
echo $sf_content;
include_partial('global/footer');

WordPress themes include several files that need to be customized to change the way it looks by default.  These files can be modified by going into “Appearance” and “Editor”.

We did not use the main layout.php template from Symfony, because we moved the common elements of the HTML into the partials. So on WordPress we only modified header.php and footer.php

In header.php we included the _topnav.php file from symfony. So after the <body> tag we inserted the following line:

<?php include('/path_to_symfony_project/apps/site/templates/_topnav.php'); ?>

This inserts the top area (including the navigation) of our site into every page and post of the Blog. if you have an external CSS in your main site, which you probably do, you need to make sure to add it to the header.php in WordPress.

Then to properly add the footer section of the site to the Blog, we edited footer.php and inserted the following line before the </body> tag

<?php include( '/path_to_symfony_project/apps/site/templates/_footer.php' ); ?>

The same could be done in the inverse way. If you have your main elements of your site design in WordPress, you could include those in the Symfony templates.

If you have any other ideas on how to accomplish this, or other tips on Symfony and WordPress integration, leave a comment, we would love to hear form you.

08

02 2009

Combining Symfony and Zend Framework

During the creation of a web application, on many occasions it is necessary to do something that requires the use of an external library.

If you happen to be building your web application using symfony, it is possible to use parts of the Zend Framework (and other frameworks and libraries) independently. This enables a whole new world of features with no preset limits.

At ServerGrove we use symfony for many of our projects, and also use Zend Framework since it provides many great components. This is why, we are always up to date on both frameworks and you will get excellent technical support when hosting your framework based sites with us.

So, as an example, you can use Zend_Mail to send emails from symfony. Some other components that are very useful in the symfony world are:

- Zend_Currency
- Zend_Mime
- Zend_Ldap
- Zend_Http
- Zend_OpenId
- Zend_Pdf

And the list goes on.

But going back to the Zend_Mail example, first, we need to tell symfony where to find the Zend Framework library.

All our servers here at ServerGrove come with not only symfony pre-installed but also we have all latests Zend Framework releases. It will be located at /usr/local/php/Zend. This will always be the latest stable version. If you need to use a specific version of the framework (to avoid possible future compatibility issues) you can also link to a specific version, for example /usr/local/php/ZendFramework-1.7.0/library

So, we need to modify the file config/ProjectConfiguration.class.php so we can use the autoloader provided by ZF, it should look like this:


// config/ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
static protected $zendLoaded = false;

static public function registerZend()
{
if (self::$zendLoaded)
{
return;
}

$zflib = '/usr/local/php/Zend';

set_include_path($zflib.PATH_SEPARATOR.get_include_path());
require_once $zflib.'/Loader.php';
Zend_Loader::registerAutoload();
self::$zendLoaded = true;
}

// ...
}

Then when we need to send the email, usually in an action, this is what we do:


ProjectConfigation::registerZend();
$mail = new Zend_Mail();
$mail->setBodyText('Message body');
$mail->setFrom('me@example.com', 'My name');
$mail->addTo($recipientEmail);
$mail->setSubject('Subject');
$mail->send();

That’s it. Could not be simpler! As we said, this opens many possibilites by using external libraries and avoids reinventing the wheel. By using the set of libraries and frameworks we provide on ServerGrove, it has never been easier to develop and run powerful and professional websites.

25

01 2009

Reset (or recover) the Mysql root password

It is not possible to recover a lost Mysql password since they are encrypted. But it can always be changed or reset.

To change the root Mysql password, follow these steps (they are primarily listed to use in our VPS servers but they may be used in others as well):

1) Stop mysql by executing as root in the command line: service mysql stop

2) Start mysql without the privileges system, execute: mysqld_safe –skip-grant-tables &

3) Open the mysql console by executing: mysql

4) Run the following queries (replace the root password with your desired password)

UPDATE mysql.user SET Password=PASSWORD(‘yourpassword’) WHERE User=’root’;
FLUSH PRIVILEGES;

5) exit the mysql console and stop mysql: service mysql stop

6) Start mysql by executing: service mysql start

Now the new password is in place.

14

01 2009