Updating the site, blog, and Nginx to use Laravel 5
08.07.16
A few months ago I finished rebuilding the blog and CMS I use to manage the site with Laravel 5. The bulk of the business logic is in a repository pattern with a base class of CRUD methods that is used by the Users, Posts, and Comments repositories. Overall I really like the framework with the exception of creating routes being very verbose. As far as I could tell a route has to be specified for every controller method. There is not logic like in ASP.NET MVC where the controller endpoints are figured out using reflection. For example in ASP.NET MVC something like /{controller}/{action}
can be specified which will be a route for all controller methods.
I updated the front-end to use the latest version of Bootstrap and kept it simple since I am mainly interested and work in back-end development.
Since my server hosting was expiring this month I also decided to switch from A Small Orange to Digital Ocean. So far Digital Ocean is awesome and creating your own Ubuntu server and configuring it to the LEMP (or LAMP) stack is easy with their tutorials and documentation.
To get Laravel 5 to work with Nginx the config /etc/nginx/sites-available/default
needs the following edits:
root /var/www/html/yourLaravel/public; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { try_files $uri /index.php?$query_string /index.php =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
Another update that is required as a result of the above Nginx change is to update the php fpm config file /etc/php/7.0/fpm/pool.d/www.conf
and change
listen = /some/path/to/php/to
listen = 127.0.0.1:9000
After making the above configuration changes remember to restart the services by running the following commands.
sudo service php7.0-fpm restart sudo service nginx restart
The code for the updated website can be found here and the updated Laravel blog code is here.