NGINX and dynamic virtual hosts for Symfony

Standard

Consider that you have 3 virtual hosts running on your dev host. Add one more means that you have to configure, again, a virtual host. That happens to me!

Working with symfony3 I just created a virtualhost to group all by symfony projects.
My first rule is: Every host will follow the expression *.symfony.dev
Second rule: each project has a directory under folder /share

And finaly my nginx config file is like:

server {
listen 80;
server_name ~^(?<sname>.+?).symfony.dev$;
root /share/$sname/web;

charset utf-8;

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

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

# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don’t want to be accessible.
location ~ \.php$ {
return 404;
}

error_log /var/log/nginx/$sname_error.log;
access_log /var/log/nginx/symfony_access.log;
}

After add this config file, do not forget to create the symLink to sites-enabled and restart nginx service

Hope it Helps!

Advertisements

2015 in review

Standard

The WordPress.com stats helper monkeys prepared a 2015 annual report for this blog.

Here’s an excerpt:

A San Francisco cable car holds 60 people. This blog was viewed about 2,300 times in 2015. If it were a cable car, it would take about 38 trips to carry that many people.

Click here to see the complete report.

Combining Symfony Console and Linux Alias

Standard

One more day exploring Symfony.
This time diving around console commands I got tired to write always “php app/console …”.

So, why just not create an alias? As i’m using a vagrant box with ubuntu, just:

vagrant@vagrant-ubuntu-trusty-64/:$ sudo nano ~/.bashrc

At the end of the file, just add your alias like “alias <name> = ‘command’ ”

alias symf-console=’php app/console ‘

after that, save and exit
Now reload that file using:

vagrant@vagrant-ubuntu-trusty-64:/$ source ~/.bashrc

And thats it!

Notice that you have to change to your symfony directory for command success.
Try than:

vagrant@vagrant-ubuntu-trusty-64:/vagrant/vhosts/symf_project$ symf-console list

Hope it helps!

Good Terminal for windows

Standard

CMDER terminal emulator for windowsLAMP with Vagrant with a windows system can be frustrating. I’m talking about terminal usage.
The built-in CMD of windows disable you a bit and is not too atractive to use.
I’ve found a terminal emulator called CMDER. It’s a nice and quite useful terminal full of small features that we really need to develop:

– Console Tabs: you can choose powershell, cmd and another types
– search feature: search box to find content around.
– edit features: custom copy and paste features.

Is really a must have!

Note:

As a portable exe, it can happen a execution error about missing DLL like:

The program can’t start because api-ms-win-crt-runtime-l1-1-0.dll is missing

Just install the C++ Redistributable:
x64: C++ Redistiributable
x32: x32 C++ Redistributable  CMDER Windows terminal emulator

Homepage: http://gooseberrycreative.com/cmder/

 

Vagrant & Laravel: storage/sessions permission denied

Standard

Hi there!
Exploring Vagrant (awesome tool!) and recently used to me Laravel Framework I got a problem with new host created at my vagrant VMachine:

Permission denied to app/storage/sessions

At your vagrant file just add:

config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=666"]

Just halt and up again your vagrant machine and it’s done!