Pages

Saturday, June 7, 2014

Turbo Start : Symfony + Nginx + CentOS

Hel...
[vagrant@centos65 ~]$ cat /etc/centos-release
CentOS release 6.5 (Final)
Install nginx :
[vagrant@centos65 ~]$ sudo yum install nginx
[vagrant@centos65 ~]$ sudo chkconfig nginx on
[vagrant@centos65 ~]$ sudo service nginx start
Install php-fpm :
[vagrant@centos65 ~]$ sudo yum install php-fpm
[vagrant@centos65 ~]$ sudo chkconfig php-fpm on
[vagrant@centos65 ~]$ sudo service php-fpm start
Install PHP :
[vagrant@centos65 ~]$ sudo yum install php
[vagrant@centos65 ~]$ sudo yum install php-pdo
[vagrant@centos65 ~]$ sudo yum install php-xml
[vagrant@centos65 ~]$ echo i like postgresql
[vagrant@centos65 ~]$ sudo yum install php-pgsql
Set PHP timezone :
[vagrant@centos65 ~]$ sudo vim /etc/php.ini
...

[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = "Europe/Paris"
...
Install Symfony :
[vagrant@centos65 ~]$ mkdir work
[vagrant@centos65 ~]$ cd work
[vagrant@centos65 work]$ curl -sS https://getcomposer.org/installer | php
[vagrant@centos65 work]$ php composer.phar create-project symfony/framework-standard-edition my_website
Would you like to use Symfony 3 directory structure? [y/N]
Would you like to install Acme demo bundle? [y/N]
database_driver (pdo_mysql): pdo_pgsql
database_host (127.0.0.1):
database_port (null):
database_name (symfony): my_website
database_user (root): my_website
database_password (null):
mailer_transport (smtp):
mailer_host (127.0.0.1):
mailer_user (null):
mailer_password (null):
locale (en):
secret (ThisTokenIsNotSoSecretChangeIt): CouldYouBeSoKindAsToLetMeStartWorkingPlease
debug_toolbar (true):
debug_redirects (false):
use_assetic_controller (true):
[vagrant@centos65 work]$ cd my_website
[vagrant@centos65 my_website]$ php app/check.php
[vagrant@centos65 my_website]$ php app/console --version
Configure nginx for my_website :
[vagrant@centos65 ~]$ sudo vim /etc/nginx/conf.d/my_website.conf
server {
    server_name centos65;
    root /home/vagrant/work/my_website/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }

    location ~ ^/(app|app_dev|config)\.php(/|$) {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}
[vagrant@centos65 ~]$ sudo service nginx restart
[vagrant@centos65 ~]$ chmod o+x /home/vagrant
[vagrant@centos65 my_website]$ vim web/app_dev.php
Allow your IP address, for example, 10.0.2.2 :
...

// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1', '10.0.2.2')) || php_sapi_name() === 'cli-server')
) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

...
[vagrant@centos65 my_website]$ sudo chmod -R 777 app/cache app/logs
Oh no ! There's no route :

[vagrant@centos65 my_website]$ php app/console generate:bundle
Bundle namespace: ACME/MyWebsiteBundle
Bundle name [ACMEMyWebsiteBundle]:
Target directory [/home/vagrant/work/my_website/src]:
Configuration format (yml, xml, php, or annotation): yml
Do you want to generate the whole directory structure [no]? yes
Do you confirm generation [yes]?
Confirm automatic update of your Kernel [yes]?
Confirm automatic update of the Routing [yes]?
[vagrant@centos65 my_website]$ vim src/ACME/MyWebsiteBundle/Resources/config/routing.yml
#acme_my_website_homepage: # path: /hello/{name} # defaults: { _controller: ACMEMyWebsiteBundle:Default:index }
acme_my_website_homepage: path: / defaults: { _controller: ACMEMyWebsiteBundle:Default:index }
[vagrant@centos65 my_website]$ vim src/ACME/MyWebsiteBundle/Controller/DefaultController.php
<?php

namespace ACME\MyWebsiteBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
#public function indexAction($name)
public function indexAction()
{
#return $this->render('ACMEMyWebsiteBundle:Default:index.html.twig', array('name' => $name));
return $this->render('ACMEMyWebsiteBundle:Default:index.html.twig');
} }
[vagrant@centos65 my_website]$ vim src/ACME/MyWebsiteBundle/Resources/views/Default/index.html.twig
Hello world!

Now, there's a route :

Test in production environment :


[vagrant@centos65 work]$ tar czf i_sell_this_website_9999_euros.tar.gz my_website


PS : ...lo

No comments:

Post a Comment