Skip to content

henvic/vehikel

Repository files navigation

#vehikel Build Status

Presentation

This is built based on the MediaLab project.

Requirements

Unless otherwise referenced to, the versions for the requirements are given by the install script or other way.

PHP and Servers

Please note that the default memcached is insecure by design because it's freely accessible from everywhere. You must restrict access to it yourself.

Extensions

  • memcached
  • GeoIP (you need a MaxMind's database service for that, this library will be changed soon)

ElasticSearch plugins

elasticsearch-action-updatebyquery

PHP Libraries

You will need PHPUnit to test the code.

For performance you want to strip the require_once's from the Zend framework code, see How can I optimize my include_path?

Client-side dependencies

Services

Install

On your CLI (command-line interface):

npm install
cd bin
./install-vendors.sh
./install.php

For development you will want to respond with "development" on the question about the application environment

This will take care of setting application paths, downloading and setting up the dependencies. It will write a application/configs/Environment.php.dist similar to application/configs/Environment.php, with the choosen timezone and directory and file paths.

If a extension is missing you will know it. You can get most of them with PECL or apt-get on a Debian-based system such as Ubuntu.

For example, if mongo were missing you could use:

sudo pecl channel-update pecl.php.net
sudo pecl install mongo
echo extension=mongo.so >> /etc/php.ini

Create the databases structures

MySQL tables have to be built. The DB scheme is at application/configs/db.sql

Points of entry

There are two modules: default and services. And also a simple redirector system.

The services module

There is a CLI based services module. Point of entry: bin/services

Web based points of entry

  • public/index.php for the default
  • public-redirector/index.php for the redirector system

You have to set up your web server configurations with regard to these. Use virtual hosts.

Rewrite rules

If you use Apache as your web server, the following rewrite rules might be used so the system receives the requests sent to it:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ – [NC,L]
RewriteRule ^.*$ index.php [NC,L]

For performance and to avoid the trouble of dealing with .htaccess I recommend not to use it (and disable it), instead put this on a Apache configuration file. Some text that might help you make a wise choice: Remove index.php From URLs

Note /index.php is hard-coded to return a 404 Not Found to make sure you do the proper thing and to avoid duplicates.

Search engine

Set the search entry-point on the configuration file.

Static assets

Set the static/ directory to the entry-point */static/**.

Important: unless the JS template files are processed to be native JS code, it has to be this way otherwise XHR restrictions will affect the system as documented on the XHR restrictions section of the text plugin.

For production you should use a CDN service (such as S3 + CloudFront) to serve them, after processing them to create .js files.

Image system

thumbor is used to abstract the needed processing of the images uploaded by the users.

As of now, it is assumed to be working with a basic installation (as in, the "safe" signing option is not being used).

In a brand new install the placeholder might be set like this:

curl -i -H "Content-Type: image/jpeg" -H "Slug: vehicle-image-placeholder.jpg" -XPOST http://localhost:8888/image --data-binary "@vehicle-image-placeholder.jpg"

On success, the image ID will be returned as a new location and then should be copied to application.ini's services.thumbor.placeholder.

Jcrop is used along with the Thumbor to provide a nice cropping feature to the end-users.

Functional testing

Use casperjs test add.js to create random products pages out of thin air.

Add a settings.json.dist file to use custom configuration, instead of modifying the original on the tests/functional path.

There is a tests/functional/providers submodule with data providers for the functional tests.

Scheduled tasks

Some operations might be expensive. For example: if a user removes his account it is not smart to start a batch delete operation of all his files right away (and let him waiting for it, for instance). A way to solve this and other similar issues is to make use of a scheduled task to run from time to time and do this heavy work.

Gearman is being used to serve tasks.

ElasticSearch (search engine)

The search is built on top of ElasticSearch (using a JSON RESTful API), with the help of Gearman. You should install the elasticsearch-action-updatebyquery plugin with:

./bin/plugin --install elasticsearch-action-updatebyquery

This search currently indexes the account profiles and posts, but only return the search results of the posts.

For effect of simplicity we assume you just installed ES on localhost.

Preparing Elasticsearch

If you want to redo this process, before proceeding do the following to remove your data: curl -XDELETE http://localhost:9200/posts

From the application/search/es-configs/ directory:

  1. Add the typeahead suggestion analyzer with curl -XPOST http://localhost:9200/posts?pretty=1 -d @posts-settings.json

  2. Verify it with curl -XGET http://localhost:9200/posts/_settings?pretty

  3. Ceate the user mapping with curl -XPUT http://localhost:9200/posts/user/_mapping?pretty=1 -d @posts-user-mapping.json

  4. Verify it with curl -XGET http://localhost:9200/posts/user/_mapping?pretty

  5. Create the post mapping with curl -XPUT http://localhost:9200/posts/post/_mapping?pretty=1 -d @posts-post-mapping.json

  6. Verify it with curl -XGET http://localhost:9200/posts/post/_mapping?pretty

Then you are ready to use ES.

The PHP back-end is used to call the ElasticSearch for indexing purpose.

There are two actions currently available via the service module:

  1. For syncing the user profile on the posts: ./services --controller search --action sync-user-profile-on-posts --uid <uid>

  2. For rebuilding the entire posts: ./services --controller search --action rebuild-user --uid <uid>

When the user changes the user profile data a gearman task is created, it is watched by the node.js worker, which calls the PHP syncing process.

A node.js server, serves as a simple "smart proxy" to ElasticSearch, limiting what queries can be made to the engine, by the final users.

Push, open bugs, etc.

Feel free to push code to this repository. Anything you want, go to the issue tracker.

Code style

For PHP, PSR2 shall be used. The code doesn't use it in a proper way as of now.

License

This software is provided "as is", without warranty. The New BSD License and the MIT License are the licenses (case you need something legal).

Third-party content in use

Author

Henrique Vicente de Oliveira Pinto (email, Twitter, Flickr, Linkedin).

About

car ad website project. Project by Henrique Vicente and Rafael Daher.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published