Symfony 3 Error on Vagrant Homestead

Just tried to set up Symfony 3 on Vagrant Homestead and got following error :

Screenshot from 2016-04-07 19:55:38

Yupz, the error was No input file specified, just for your information I have another site in this vm that work properly, so I guest the problem was web server configuration.

ok  now let me show you how to fix it :

  1. sudo vi /etc/nginx/sites-available/your_site.app
  2. This is your previous / existing virtual host that generated before :
    • server {
      listen 80;
      listen 443 ssl;
      server_name bagist.app;
      root “/home/vagrant/bagist-shop/web”;

      index index.html index.htm index.php;

      charset utf-8;

      location / {
      try_files $uri $uri/ /index.php?$query_string;
      }

      location = /favicon.ico { access_log off; log_not_found off; }
      location = /robots.txt { access_log off; log_not_found off; }

      access_log off;
      error_log /var/log/nginx/bagist.app-error.log error;

      sendfile off;

      client_max_body_size 100m;

      location ~ \.php$ {
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
      fastcgi_index index.php;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

      fastcgi_intercept_errors off;
      fastcgi_buffer_size 16k;
      fastcgi_buffers 4 16k;
      fastcgi_connect_timeout 300;
      fastcgi_send_timeout 300;
      fastcgi_read_timeout 300;
      }

      location ~ /\.ht {
      deny all;
      }

      ssl_certificate /etc/nginx/ssl/bagist.app.crt;
      ssl_certificate_key /etc/nginx/ssl/bagist.app.key;
      }

  3. edit to be like this :
    • server {
      listen 80;
      listen 443 ssl;
      server_name bagist.app;
      root “/home/vagrant/bagist-shop/web”;

      index index.html index.htm index.php;

      charset utf-8;

      location / {
      try_files $uri /app.php$is_args$args;
      }

      location = /favicon.ico { access_log off; log_not_found off; }
      location = /robots.txt { access_log off; log_not_found off; }

      access_log off;
      error_log /var/log/nginx/bagist.app-error.log error;

      sendfile off;

      client_max_body_size 100m;

      location ~ ^/(app_dev|config)\.php(/|$) {
      fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
      fastcgi_split_path_info ^(.+\.php)(/.*)$;
      fastcgi_index app_dev.php;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
      fastcgi_param DOCUMENT_ROOT $realpath_root;

      fastcgi_intercept_errors off;
      fastcgi_buffer_size 16k;
      fastcgi_buffers 4 16k;
      fastcgi_connect_timeout 300;
      fastcgi_send_timeout 300;
      fastcgi_read_timeout 300;
      }

      location ~ /\.ht {
      deny all;
      }

      ssl_certificate /etc/nginx/ssl/bagist.app.crt;
      ssl_certificate_key /etc/nginx/ssl/bagist.app.key;
      }

  4. restart your nginx service
    • sudo service nginx restart

  5. for another information visit this link

 

Symfony2 QueryBuilder find first and find last record in table

Pelatihan Pemrograman Java Web dengan Spring Boot Gratis klik disini.

Pelatihan Pemrograman Web dengan Java secara gratis dibimbing oleh trainers yang berpengalaman dibidang pengembangan applikasi berbasis Java enterprise.

Peserta per batch dibatasi hanya 15 orang.

WhatsApp Image 2020-03-10 at 08.55.54

Daftar Java web Bootcamp Gratis disini https://www.beanary.tech/ 

 

 

 

Here i how to find first/last record in Symfony 2 using query builder :

Find Last

public function findLast() {
$qb = $this->createQueryBuilder(‘tc’);
$qb->setMaxResults( 1 );
$qb->orderBy(‘tc.id’, ‘DESC’);

return $qb->getQuery()->getSingleResult();
}

 

Find First

public function findFirst() {
$qb = $this->createQueryBuilder(‘tc’);
$qb->setMaxResults( 1 );
$qb->orderBy(‘tc.id’, ‘ASC’);

return $qb->getQuery()->getSingleResult();
}

 

in a Function

public function find($what) {

$order =(strtolower($what)==’asc’) ? $what : “desc”;
$qb = $this->createQueryBuilder(‘tc’);
$qb->setMaxResults( 1 );
$qb->orderBy(‘tc.id’,$order);

return $qb->getQuery()->getSingleResult();
}

 

Symfony Bundle System

Membuat dan mengkonfigurasi Bundle di Symfony 2.7

lihat yang saya lakukan di bundle :

yusuf@yusuf-VirtualBox:/var/www/html/learning/learning1$ app/console generate:bundle –namespace=Acme/TestBundle
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 AcmeTestBundle.

Bundle name [AcmeTestBundle]:

The bundle can be generated anywhere. The suggested default directory uses
the standard conventions.

Target directory [/var/www/html/learning/learning1/src]:

Determine the format to use for the generated configuration.

Configuration format (yml, xml, php, or annotation): annotation

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 “Acme\TestBundle\AcmeTestBundle” bundle
in “/var/www/html/learning/learning1/src/” using the “annotation” format.

Do you confirm generation [yes]?
Bundle generation

Generating the bundle code: OK
Checking that the bundle is autoloaded: OK
Confirm automatic update of your Kernel [yes]? yes
Enabling the bundle inside the Kernel: OK
Confirm automatic update of the Routing [yes]?
Importing the bundle routing resource: OK
You can now start using the generated code!

Symfony2 .htaccess to redirect request from /web to /

Symfony2 HTACCESS file to remove 'web' folder from url

Defaul url http://mydomain.com/web/action
Wanted url  http://mydomain.com/action

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Explicitly disable rewriting for front controllers
    RewriteRule ^/web/app_dev.php - [L]
    RewriteRule ^/web/app.php - [L]

    # Fix the bundles folder
    RewriteRule ^bundles/(.*)$ /web/bundles/$1  [QSA,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    # Change below before deploying to production
    #RewriteRule ^(.*)$ /web/app.php [QSA,L]
    RewriteRule ^(.*)$ /web/app_dev.php [QSA,L]
</IfModule>

save configuration above to .htaccess and save it to your project root folder 

Symfony2 Jquery Twitter Bootstrap and Font awesome as public resource

under web project create public folder then put all resource there, here is mine as an example for you :

/var/www/html/mysymproject/web

var/www/html/mysymproject/web/public

var/www/html/mysymproject/web/public/bootstrap-3.2.0

var/www/html/mysymproject/web/public/font-awesome-4.2.0

var/www/html/mysymproject/web/public/js/jquery-1.11.1.min.js

ok, now here is how to add them (css and js) to the layout :

{% block stylesheets %}
{% stylesheets
‘public/bootstrap-3.2.0/css/bootstrap.min.css’
‘public/bootstrap-3.2.0/css/bootstrap-theme.min.css’
‘public/font-awesome-4.2.0/css/font-awesome.min.css’
filter=’cssrewrite’
%}
<link rel=”stylesheet” href=”{{ asset_url }}” />
{% endstylesheets %}
{% endblock %}

{% block javascripts %}
{% javascripts filter=”” output=”js/core.js” debug=true
‘public/js/jquery-1.11.1.min.js’
‘public/bootstrap-3.2.0/js/bootstrap.min.js’
%}
<script type=”text/javascript” src='{{ asset_url }}’></script>
{% endjavascripts %}
{% endblock %}

 

 

Symfony2, First Installation Warning message

Whoops, looks like something went wrong.

ErrorException: Warning: date_default_timezone_get(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone ‘UTC’ for now, but please set date.timezone to select your timezone. in /var/www/html/symfony2/vendor/monolog/monolog/src/Monolog/Logger.php line 112

lets check the config.php to make sure that what is going on.  mine is http://test.lab/config.php  (I’m currently using virtual host to runs  Symfony on my Fedora 17) .

okay now from http://symfony2.lab/config.php give me more information about the warning, mine result PHP warning messages like this :

Warning: date_default_timezone_get(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone ‘UTC’ for now, but please set date.timezone to select your timezone. in /var/www/html/symfony2/app/SymfonyRequirements.php on line 434

PHP warns that the timezone is not set yet, let fix it…

gedit /etc/php.ini

then define the specific timezone using date.timezone = “Asia/Jakarta”

restart the web server using service httpd restart

refresh the browser and the warning messages become disappear.

for addition configuration, Symfony2 also recommend user to set app/cache and app/logs folder readable

chmod -R 777 app/cache/ app/logs/

Ok, now we have already done, go back to check the configuration  at  http://test.lab/config.php,

is everything ok right now?

Menyiapkan Virtual Host Untuk Symfony2 di Ubuntu

Menyiapkan Virtual Host Untuk Symfony2 di Ubuntu

  1. Extract file Symfony2 di mana saja (cari letak yang terbaik bagi anda).
  2. /etc$ sudo gedit hosts (buka /etc/hosts).
  3. Pada /etc/hosts tambahkan 127.0.1.32 http://www.namavhostanda.xom (nama vhost dan IP sesuaikan saja).
  4. restart apache dengan:
    • #service apache2 restart
  5. coba buka di browser http://www.namavhostanda.xom (sesuaikan dengan milik anda bila beda), pastikan sama dengan kita menggunakan 127.0.1.32
  6. lalu masuk ke /etc/apache2/sites-available
    • buat file dengan perintah #gedit http://www.namavhostanda.xom (atau terserah anda).
    • ketikkan :
    • <VirtualHost 127.0.1.32:80>
          ServerName http://www.namavhostanda.xom
          ServerAlias http://www.namavhostanda.xom
          ServerAdmin admin@namavhostanda.xom
          DocumentRoot /path/kefolder/symfony/anda/web
          <Directory /path/kefolder/symfony/anda/web>
              Options Indexes FollowSymLinks MultiViews
              AllowOverride All
              Order allow,deny
              allow from all
          </Directory>
      </VirtualHost>
  7. lalu masuk ke /etc/apache2/sites-enabled (sama dengan yang diatas)
    • buat file dengan perintah gedit http://www.namavhostanda.xom (atau terserah anda).
    • ketikkan :
    • <VirtualHost 127.0.1.32:80>
          ServerName http://www.namavhostanda.xom
          ServerAlias http://www.namavhostanda.xom
          ServerAdmin admin@namavhostanda.xom
          DocumentRoot /path/kefolder/symfony/anda/web
          <Directory /path/kefolder/symfony/anda/web>
              Options Indexes FollowSymLinks MultiViews
              AllowOverride All
              Order allow,deny
              allow from all
          </Directory>
      </VirtualHost>
  8. restart apache dengan:
    • #service apache2 restart
  9. Di browser buka http://www.namavhostanda.xom/app_dev.php/
  10. Selamat mencoba.

tags : symfony,symfony2,virtual host,ubuntu,vhost,konfigurasi

Fixing Error after Deleting Bundles and Entities on Symfony2

I just deleted several Bundles on my project, the Bundles are AcmeDemoBundle and my own bundle BlogUserBundle, and of course it will cause several errors in the project the error message is “Unknown Entity namespace alias bla2…“, so I have to change and adjust several modifications in the several files to make it work again, let start with the easier way :

  1. Go to the app/cache delete all folders and file inside this folder.
  2. Go to app/AppKerner.php then look for bundles name that you have been deleted to unregister them.
  3. Go to app/config/routing_dev.yml delete all configuration that contain bundles name that you have been deleted to unregister them.
  4. Go to app/config/routing.yml delete all configuration that contain bundles name that you have been deleted to unregister them.
  5. Go to app/config/security.yml delete all configuration that contain bundles name that you have been deleted to unregister them.
  6. Go to  app/logs delete all folders and file inside this folder.

Let check, still error ?

go to console and find the bundle name using :

grep -R -i “YourBundle” /yourProjectFolder

find the paths/files that still contain deleted bundle name, open the files and delete the lines that still contain the deleted Bundle Names.

then try to :

./console cache:clear

./console cache:warmup

 

 

Security, Authentication dan Access Controll pada Symfony2 bag-2

Security, Authentication dan Access Controll pada Symfony2 bag-2

Artikle Sebelumnya

Tags : Symfony Login, Login Symfony, Symfony2 Login, Login Symfony2, User Authentication Symfony, User Authentication Symfony2, User Authorization Symfony2, Login dengan Symfony2,Tutorial Symfony,Symfony Tutorial, Belajar Symfony, Tutorial Symfony2,Symfony Tutorial2, Belajar Symfony2, Symfony Framework, Symfony Framework, Symfony PHP Framework, Belajar PHP Framework, PHP Symfony, Symfony PHP, PHP Symfony2, Symfony2 PHP,Indonesian Symfony, Symfony Indonesia, Symfony Bahasa, bahasa Symfony, Indonesian Symfony2, Symfony2 Indonesia, Symfony2 Bahasa, bahasa Symfony, Symfony2 Bahasa Indonesia, bahasa Indonesia, Symfony, Symfony Bandung, php symfony bandung,Symfony dan Symfony2,Login di symfony2.

Bagaimanakah Authentication dan Authorization pada Symfony2 Bekerja ?

Security pada Simfony / Symfony2 bekerja dengan cara mengenali siapa User yang masuk dengan menggunakan Authentication (misal : login dengan Username dan Password) lalu melakukan pengecekan tentan Resource dan/atau URL apa saja yang dapat diakses oleh User tersebut atauAuthorization.

Firewalls (Authentication) pada Symfony2

Ketika User Website mengunjungi Sebuah URL / Melakukan request pada sebuah URL yang terproteksi Oleh Firewall maka Security System akan aktif. Tugas dari Firewall adalah menetukan apakah si User  memiliki akses ke URL yang dia minta dan kalau ternyata tidak punya maka User akan diarahkan ke URL / page untuk melakukan Login terlebih dahulu.

Gambar gambar  dibawah ini yang mencerikan tentang akses via URL ke applikasi di Server

Pada gambar diatas di jelaskan mengenai security anonymous user access dimana Url yang diakses oleh user tidak membutuhkan authentikasi sehingga server langsung membalas dengan memberikan respond pada client.

Gambar dibawah ini yang mencerikan tentang akses ke URL yang di proteksi Firewal menggunakan Access Controls (Authorization)

Pada gambar diatas dijelaskan tentang applikasi pada server yang meminta user untuk melakukan authentikasi ketika User melakukan akses pada ^/admin yang dilindungi oleh firewall.

Pada gambar diatas dijelaskan tentang user yang Sudah login sebagai User biasa mencoba akses ke URL admin akan di tolak untuk mengakses system.

Gambar diatas menerangkan tentang Admin yang Login, setelah berhasil Login Applikasi Mengirim Halaman Admin yang direquest oleh user admin tersebut.

Login Form

Selanjutnya untuk belajar secara perlahan  kita akan membuat User login menggunakan form dimana User yang akan digunakan adalah user yang hardcode terdapat pada /app/config/security.yml, tutorial selanjutnya Bersambung ke :

Security, Authentication dan Access Controll pada Symfony2 bag-3

Artikel Sebelumnya  Artikel Selanjutnya

 

 

Tags : Symfony Login, Login Symfony, Symfony2 Login, Login Symfony2, User Authentication Symfony, User Authentication Symfony2, User Authorization Symfony2, Login dengan Symfony2,Tutorial Symfony,Symfony Tutorial, Belajar Symfony, Tutorial Symfony2,Symfony Tutorial2, Belajar Symfony2, Symfony Framework, Symfony Framework, Symfony PHP Framework, Belajar PHP Framework, PHP Symfony, Symfony PHP, PHP Symfony2, Symfony2 PHP,Indonesian Symfony, Symfony Indonesia, Symfony Bahasa, bahasa Symfony, Indonesian Symfony2, Symfony2 Indonesia, Symfony2 Bahasa, bahasa Symfony, Symfony2 Bahasa Indonesia, bahasa Indonesia, Symfony, Symfony Bandung, php symfony bandung,Symfony dan Symfony2,Login di symfony2.


Artikel Selanjutnya