Setup VPS with a Symfony2 project from git repository - symfony

I have a:
- VPS with LAMP stack
- local symfony2 project (git)
- bitbucket repository
What do I need to do to properly setup my project in the production evironment?
Folder structure/permissions?
Can I simply clone the repository in the public folder? (I don't think so)
P.s. I've already read the deployment guide on the symfony2 website, but I didn't find it very useful

Here are my deployment steps:
git clone project
go to project directory
php composer.phar install (and if composer is not in the project
directory curl -sS https://getcomposer.org/installer | php)
app/console doctrine:database:create
app/console schema:update --force
app/console assets:install web --symlink
chmod 777 -R app/cache app/logs web/media/cache (I often use liip
imagine, it resizes photo in web/media/cache)
point the virtual host of apache to the web directory of my project.
And you are done.
you might want to enable mode rewrite in apach (a2enmod rewrite) I think this covers everything.

Related

How to upload my Symfony project to shared hosting?

I have a Symfony 3 app that I need to deploy to a shared hosting server - hostgator. I have copied all of the contents from the web folder into the public_html folder. I also copied all the other folders on the root of my directory. However, I does not run.
Did you check the proper permissions in particular the var/ folder, this is described on this page.
Also, if they use apache, you will have to set the owner:group of the web folder properly.
In Linux that is done easily by this command (from the root folder):
$ chown -R apache:apache web/
Try that out (you might need sudo access to run chown).

cron Symfony2 to delete a file

I would like to create a cron that remove a file every 24hrs but it doesn't work for me !
emptyCache.php permission 755
rm -rf app/cache/*
I use for that a cron from OVH to do the job, I follow the process but the folder wasn't removed! My question is: is it the right command?
Here is an example of script which should work on a OVH hosting (Pro 2014), you don't need to use any PHP or Symfony2 file or command:
File: /homez.807/[my_login]/symfony2/launch_commands.php
#!/bin/bash
rm -rf /homez.807/[my_login]/symfony2/app/cache/*
It's simpler to put the full path of the directory you want to erase, but you can also use the cd command to change the directory then delete the sub-directory.
And here is the configuration in the OVH manager (see the Cron tab):
So the ./ is the root of you web hosting, corresponding to /homez.807/[my_login]/. Here are the two important options :
Script: we have to put the relative path (from the root of the web hosting) of the script: symfony2/launch_commands.sh
Language: Other because the script should be executed by the shell, not the PHP interpreter
Logs: you should enable logs in order to send the result of the cron task by email
Description: choose an explicit name

symfony2 assets in changed web folder

I'm using Symfony2 in my project and I changed web root ditectory. I followed instructions on this page http://symfony.com/doc/current/cookbook/configuration/override_dir_structure.html. Now my project structure looks like this:
/frontend - the new web root dir
/myproject - the project dir
Then i'm installed and dumped assets
php app/console assets:dump
php app/console assetic:install ../frontend --symlink
Most things works fine. But the problem is that I can't acces to any asset in /bundles directory, Symfony returns error
No route found for "GET /bundles/..."
But I can see my assets in this directory in explorer (symlinks created correctly).
Is your web server configured to follow symlinks? Without knowing which web server you are using, as an example in apache you need to set the FollowSymLinks option. Alternatively, remove the symlink option when doing assets:install.
Also, it's probably just a typo, but you've got the commands for installing assets and dumping assetic a bit muddled in your question - should be something like this:
php app/console assets:install --symlink ../frontend
php app/console assetic:dump -e dev

Checking that the bundle is autoloaded: FAILED

I cannot create a bundle. I'm getting "Checking that the bundle is autoloaded: FAILED" which never used to happen before until now. Steps below always worked until today.
Any solutions?
To setup Symfony2:
I downloaded: Symfony_Standard_Vendors_2.4.5.zip
I unzipped under: /var/www/html/local/three. three is the main folder.
I set the permissions:
desktop#ubuntu:/var/www/html/local/three$ sudo chown desktop -R app/logs
desktop#ubuntu:/var/www/html/local/three$ sudo chown desktop -R app/cache
desktop#ubuntu:/var/www/html/local/three$ sudo chmod 777 -R app/cache
desktop#ubuntu:/var/www/html/local/three$ sudo chmod 777 -R app/logs
This URL works fine: http://localhost/local/three/web/app_dev.php
To create my bundle:
desktop#ubuntu:/var/www/html/local/three$ php app/console generate:bundle --namespace=Myblog/PublicBundle
Welcome to the Symfony2 bundle generator
In your code, a bundle is often referenced by its name. It can be the
concatenation of all namespace parts but it's really up to you to come
up with a unique name (a good practice is to start with the vendor name).
Based on the namespace, we suggest MyblogPublicBundle.
Bundle name [MyblogPublicBundle]:
The bundle can be generated anywhere. The suggested default directory uses
the standard conventions.
Target directory [/var/www/html/local/three/app/cache/dev/../src]:
Determine the format to use for the generated configuration.
Configuration format (yml, xml, php, or annotation): yml
To help you get started faster, the command can generate some
code snippets for you.
Do you want to generate the whole directory structure [no]? yes
Summary before generation
You are going to generate a "Myblog\PublicBundle\MyblogPublicBundle" bundle
in "/var/www/html/local/three/app/cache/dev/../src/" using the "yml" format.
Do you confirm generation [yes]? yes
Bundle generation
Generating the bundle code: OK
Checking that the bundle is autoloaded: FAILED
Confirm automatic update of your Kernel [yes]? yes
Enabling the bundle inside the Kernel: OK
Confirm automatic update of the Routing [yes]? yes
Importing the bundle routing resource: OK
The command was not able to configure everything automatically.
You must do the following changes manually.
- Edit the composer.json file and register the bundle
namespace in the "autoload" section:
Solved:
Problem is to do with line:
Target directory [/var/www/html/local/three/app/cache/dev/../src]:
I don't understand why it is suggesting cache path. Old days it was always automatically suggesting src directory instead. I've checked my logs that's why I know. Anyway change it to:
/var/www/html/local/three/src
Done!
This is a known issue now, I guess it will be fixed on the next version
https://github.com/symfony/symfony/issues/10972
https://github.com/symfony/symfony/pull/10999
https://github.com/symfony/symfony-standard/issues/659
for now when the generate:bundle displays this:
The bundle can be generated anywhere. The suggested default directory
uses the standard conventions.
Target directory:
-- /type/your/directory/src here

Symfony 2.2 Deployment Questions

Because of an other problem on my server, I tried to setup a real new project and did this (localhost with xampp on windows):
installed curl
loader composer like told in docs
loader vendors like told in docs
merged app/config-folder
copied src-folder
copied web/bundles/myBundle-folder
After that, I tried the deployment-steps documentation. I skipped uploading the files and editing parameter.yml (it's already configured for localhost).
Than I am running into trouble doing 'B) Update your vendors':
php composer.phar install --optimize-autoloader
This steps remove all my files from the web\bundles\myBundle-folder.
Do I have to tell composer about my bundle? I first thought, that I have to store them somewhere else, but this thread tells me, that I am right?!
The thread you are mentioning is from symfony 1, but you are installing a symfony 2 application.
In web/bundles are your assets installed (css, javascript and images).
Your bundles which will be installed via composer are in your vendors folder.
And your own bundles should be in the src folder.
I think this is a good start to have a look at where to store your files.
Your css, js and images should be stored in a bundle, e.g.:
src/AcmeDemoBundle/Resources/public/css
src/AcmeDemoBundle/Resources/public/js
src/AcmeDemoBundle/Resources/public/images
And then you can install your assets with php app/console assets:install web and they will be pushed into the web/bundles folder.

Resources