Posts Tagged ‘PHP’

PHP conferences update

There are some great conferences around the PHP world that are coming up or are being announced. Here is the list (if we missed one, please let us know)

  • Open Source India – September 19-21, 2010 – Chennai, India
  • PHP Matsuri – October 2-3, 2010 – Tokyo, Japan
  • Symfony Day Cologne 2010 – October 8, 2010 – Cologne, Germany
  • ZendCon – November 1-4, 2010, Santa Clara, California
  • Symfony Live San Francisco – February 2011, San Francisco, California
  • Symfony Live Paris – March 3-5, 2011 – Paris, France



As always, if you work around PHP, we encourage you to participate of conferences which are an invaluable tool to enhance your skills and meet with fellow developers and colleagues.

31

08 2010

Zend Framework 1.10.8 released!

Today the Zend Framework development team announced the availability of Zend Framework 1.10.8 which includes around 22 bugfixes. For a complete changelog, go here.

As previously, it is noted that those users that depend on ZF for their twitter connected applications upgrade immediately to 1.10.8 to ensure that you use the OAuth functionality required by Twitter.

This release is already available in all our servers for our customers. For more information about our Zend Framework hosting offering, click here.

25

08 2010

New OS images available for VPS plans

We have some new images available and tested for VPS servers. These are available as an upgrade or you can select the image you want when you order.

  • Ubuntu 10.04
  • CentOS 5.5

On both OSes, you can choose 32 or 64 bit with PHP 5.3 or PHP 5.2 (always the latest version); or you can choose a standard installation with no custom packages.

We have also upgraded numerous packages inside the custom installations and have included MongoDB support for PHP.

If you want to upgrade your existing VPS to one of these images, open a support ticket. Some versions can be upgraded without needing to reinstall the entire VPS, but this is not always the case.

16

08 2010

Zend Framework 1.10.7 released!

Late last week, the Zend Framework development team announced the availability of Zend Framework 1.10.7 which includes around 60 bugfixes. For a complete changelog, go here.

It is noted that those users that depend on ZF for their twitter connected applications upgrade immediately to 1.10.7 to ensure that you use the OAuth functionality required by Twitter.

This release is already available in all our servers for our customers. For more information about our Zend Framework hosting offering, click here.

02

08 2010

PHPSPTestFest

We are sponsoring a mouthful of an event in São Paulo this Saturday; the PHPSPTestFest is a cool one-day event spearheaded by Rafael Dohms.

PHPSPTestFest is an annual event promoted by PHPSP in conjunction with the PHP TestFest Quality Assurance Team. For a few months a year, the PHP team encourages events like these to help write scripts to test the PHP code; a collective effort to improve the quality of the PHP language. At this event, which is organized by PHPSP, the participants will be able to attend an intensive PHP testing workshop and with a lab session writing code alongside some of the best coaches in town who will be there to help.

Needless to say events like this are the heart of the PHP community and we want to support and encourage people to attend these events in any way we can. We salute PHPSP for their initiative! More information at http://phpsp.org.br/2010/05/phpsptestfest-2010-preparativos/

25

05 2010

MongoDB with PHP and symfony

Introduction

There has been a lot of talk about document databases and how applicable they are for Web 2.0 application development. There are a bunch of projects in the “NoSQL” realm that are making a lot of noise, CouchDB, Cassandra, and MongoDB are the ones that are most mentioned. MongoDB is a scalable document database, which is also open source.

Part of our business is to develop internal applications and  support customers, so we dedicate a good amount of time to research, test and learn new technologies. We have been following this whole movement and decided to give MongoDB a try.

What has really taken our attention regarding MongoDB is its simplicity, yet how powerful it is. It lowers the barrier to develop DB-driven applications even more.

In MongoDB there are no tables and rows. You have collections and documents instead. And collections can contain any type of document, it is not limited by the columns or fields like a table. In some scenarios, this is a really big plus. Yet, some people, mostly those born and raised with RDBMS will be scared to death due to the lack of schema and rigid structures. As always, if you plan ahead and do your homework and design your entities properly, you will be fine.

Since collections can have different types of documents, let’s say, an array, you can update the document with more fields in the array. In the RDBM world to do this, you have to change your schema, making application upgrades one of the biggest pains.

Using MongoDB and PHP

To get started with MongoDB and PHP, you need to download and install the server. From the website you can download packages for your preferred OS or you can download the source and compile it. Installation is really simple. Once you have the files in your computer, to start the server all you have to do is run the daemon, ie.:

# /usr/local/mongodb/bin/mongod

MongoDB will start and initialize its DB storage.

Now you can connect with the mongo command line client or other clients like MongoHub, PHPMOAdmin among others.

To connect to MongoDB from PHP, you will need to install the mongo pecl extension. On Mac OS X or Linux, run:

# pecl install mongo

Then add the following line to php.ini and restart your web server:

extension=mongo.so

The PHP.net site has a very good tutorial on how to get started with MongoDB and PHP. Basically, to store something in MongoDB you follow these simple steps:

// connect to the default DB server, localhost
$connection = new Mongo(); 

// select a DB
$db = $connection->dbname;

// get a collection, if it does not exist, it will get created
$collection = $db->users;

// insert a document
$collection->insert( $doc );

That’s it! No table creation, nice! For more information on how to retrieve data, go to the PHP.net tutorial.
MongoDB stores data in a binary JSON format. If you are familiar with JavaScript, you will know JSON. When you store a PHP object, when it is time to get the data from the DB, you will get an array instead. For many uses, this is OK, but some times, for more complex solutions, objects are necessary. Fortunately there is a solution already!

Enter ODM (Object Document Mapper)

ODM is a new project created by Jon Wage, a core developer of the popular Doctrine ORM. The Doctrine\ODM namespace will be the home to PHP 5.3 object mappers for Document based storage systems like MongoDB. Currently only the Doctrine\ODM\MongoDB code has been implemented and it will map PHP objects with MongoDB documents. So when you store PHP objects in MongoDB and you need to retrieve them, you will get back PHP objects. Not only that, but it also helps with relations between objects. The project home page includes a basic usage manual and a full working example.

What’s really nice about this solution is how unintrusive it is. Your classes are pure PHP classes without having to extend other classes. The only requirement is that you map your properties using one of the support metadata drivers. In this example we use the AnnotationDriver:

namespace Entities;

/** @Entity */
class User
{
    /** @Field */
    private $id;

    /** @Field */
    private $username;

    /** @Field */
    private $password;

    /** @Field(embedded="true", targetEntity="Entities\Phonenumber", type="many", cascadeDelete="true") */
    private $phonenumbers = array();

    /** @Field(embedded="true", targetEntity="Entities\Address", type="many") */
    private $addresses = array();

    /** @Field(reference="true", targetEntity="Entities\Profile", type="one") */
    private $profile;

    /** @Field(reference="true", targetEntity="Entities\Account", cascadeDelete="true") */
    private $account;

    public function getId()
    {
        return $this->id;
    }

    public function getUsername()
    {
        return $this->username;
    }

    public function setUsername($username)
    {
        $this->username = $username;
    }

    public function getPassword()
    {
        return $this->password;
    }

    public function setPassword($password)
    {
        $this->password = md5($password);
    }

    public function getAddresses()
    {
        return $this->addresses;
    }

    public function addAddress(Address $address)
    {
        $this->addresses[] = $address;
    }

    public function setProfile(Profile $profile)
    {
        $this->profile = $profile;
    }

    public function getProfile()
    {
        return $this->profile;
    }

    public function setAccount(Account $account)
    {
        $this->account = $account;
    }

    public function getAccount()
    {
        return $this->account;
    }

    public function getPhonenumbers()
    {
        return $this->phonenumbers;
    }

    public function addPhonenumber(Phonenumber $phonenumber)
    {
        $this->phonenumbers[] = $phonenumber;
    }
}

Take a look at the DocBlocks and how we map the properties to the document.

Once you defined your entities, the usage is super simple:

require '/path/to/doctrine/lib/Doctrine/Common/ClassLoader.php';

use Doctrine\Common\ClassLoader,
      Doctrine\Common\Annotations\AnnotationReader,
      Doctrine\ODM\MongoDB\Mongo,
      Doctrine\ODM\MongoDB\Configuration,
      Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver,
      Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver,
      Doctrine\ODM\MongoDB\EntityManager;

$classLoader = new ClassLoader('Doctrine\ODM', __DIR__ . '/../lib');
$classLoader->register();

$classLoader = new ClassLoader('Doctrine', '/path/to/doctrine/lib');
$classLoader->register();

$classLoader = new ClassLoader('Entities', __DIR__);
$classLoader->register();

$config = new Configuration();

$reader = new AnnotationReader();
$reader->setDefaultAnnotationNamespace('Doctrine\ODM\MongoDB\Mapping\Driver\\');
$config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Entities'));

$em = EntityManager::create(new Mongo(), $config);

$user = new User();
$user->username = 'jwage';
$user->password = 'changeme';

$user->profile = new Profile();
$user->profile->firstName = 'Jonathan';
$user->profile->lastName = 'Wage';

$user->account = new Account();
$user->account->name = 'Test Account';

$em->persist($user);
$em->flush();

For more information, visit the project home page. Please note that this project is in very early stages of development, so things may change.

MongoDB, ODM and symfony

We will demonstrate how to use MongoDB with ODM and symfony. Symfony 2 is still in alpha stage, so even though it would be a perfect fit with ODM, we will stick with symfony 1.4 for now. For this part of the article, you will need to know a little bit of symfony.

1. If you don’t have a symfony project, go ahead and create it with ./symfony generate:project myproject

2. Download Doctrine2 (you will need the new class autoloader) and ODM into myproject/lib/vendor

3. Add the class auotoloader to the config/ProjectConfiguration.class.php file:

require_once __DIR__.'/../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php';
sfCoreAutoload::register();

require __DIR__.'/../lib/vendor/doctrine2/lib/Doctrine/Common/ClassLoader.php';

use Doctrine\Common\ClassLoader, Doctrine\ODM\MongoDB\EntityManager;

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    $classLoader = new ClassLoader('Doctrine\ODM', __DIR__ . '/../lib/vendor/odm/lib');
    $classLoader->register();

    $classLoader = new ClassLoader('Doctrine\ODM', __DIR__ . '/../lib/vendor/doctrine2/lib');
    $classLoader->register();

    $classLoader = new ClassLoader('Entities', __DIR__.'/../lib');
    $classLoader->register();

  }
}

4. Create your classes in lib/Entities, ie. lib/Entities/Server.php:

namespace Entities;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;

class Server
{
  private $id;
  private $hostname;
  private $ipAddress;
  private $status = 0;

    public function getId()
    {
        return $this->id;
    }

    public function getHostname()
    {
        return $this->hostname;
    }
    public function setHostname($hostname)
    {
        $this->hostname = $hostname;
    }
   public function getIpAddress()
    {
        return $this->ipAddress;
    }
    public function setIpAddress($ip)
    {
        $this->ipAddress = $ip;
    }

  public function  __toString()
  {
    return $this->hostname;
  }

}

5. Now you can perform your operations, just to keep it simple, we will add the code to the actions.inc.php:

use Doctrine\ODM\MongoDB\EntityManager, Doctrine\ODM\MongoDB\Mongo, Entities\Server;
class defaultActions extends sfActions
{
 public function executeInex(sfWebRequest $request)
  {
    $em = EntityManager::create(new Mongo());

    $s = new Server();
    $s->setIpAddress('192.168.0.1');
    $s->setHostname('abc.example.com');
    $em->persist($s);
    $em->flush();
    $query = $em->createQuery('Entities\Server');
    $servers = $query->execute();
    $this->servers = $servers;
  }

And your indexSuccess.php has nothing special about ODM:

Servers:
<ul>
<?php foreach( $servers as $s): ?>
 <li><?php echo esc_entities($s);?></li>
<?php endforeach; ?>
</ul>

Hopefully with this preview, you can see the power of MongoDB when joined by ODM and symfony.

Special thanks to Jon Wage for leading the development of this project and his contribution to this article.

28

04 2010

Zend Framework 1.10.4 released!

The Zend Framework development team announced the availability of Zend Framework 1.10.4 which includes about 50 bugfixes, many of them from the last bug hunt days. For a complete changelog, go here. The most notable improvement in this release is the performance gain of up to 300% when using Zend_Amf which connects Flex applications with PHP/Zend Framework.

This release is already available in all our servers for our customers. For more information about our Zend Framework hosting offering, click here.

28

04 2010

Interesting symfony plugins: sfPropelMigrationsLightPlugin

You probably have read about all the buzz surrounding Doctrine these days. Its support for migrations (the ability to upgrade/downgrade the database schema) is pretty awesome. However, migrating to Doctrine from Propel 1.4 can be challenging on a large scale project. Don’t fret, it turns out that there is a cool little plugin that provides migrations for those that are locked in the Propel world. As described in the plugin page, the sfPropelMigrationsLightPlugin allows to “Easily change the database structure without losing any data.”

The main difference between Doctrine’s migrations and sfPropelMigrationsLightPlugin is that you have to write the code to alter your tables, where as Doctrine can generate these by looking at the differences in the local schema file and the DB. The plugin page describes the use which is fairly simple: create the migration class, add the code to the up() and down() methods and finally run the migrate task (ie. symfony migrate frontend 42)

Automating the deployment process is an important part of delivering software and avoiding problems. This plugin surely helps in this regard and we recommend its use if you are using Propel. And remember to always backup before you migrate anything!

06

04 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

Using the autoupdate for WordPress when you have STFP

The WordPress autoupdate feature allows WordPress to automatically download and install updates on your WordPress.  It’s one of the best features in WordPress and usually performs a clean update in a matter of seconds without you having to mess around with your files. One of the downsides of autoupdate is that it does not support SFTP out of the box. There are several tutorials explaining how to recompile PHP to enable SFTP in WordPress, but the best way to get around this is to bypass using SFTP, FTPS and FTP altogether and assigning the correct permissions to your files so the web server can have write permissions.
Log into your account using SSH and type:


chown apache /var/www/blog -R

Note: Some Linux distros use other users for Apache, like httpd, wwwuser, or wwwdata. Check the User directive in your Apache configuration to make sure you assign the right user to your files.

Be sure to replace the /var/www/blog with the path to your WordPress installation. And that’s it.  WordPress should take care of the rest.

Tags: ,

02

03 2010