Problem description
Laravel is the most popular Web application Development framework under PHP today, and the start number on GitHub is much more than the second symfony, which I used to do when I was using this framework as a project, usually in Apache. Then configure the. htaccess file to remove the public word from the route, to achieve the pretty URLs effect, this two days in the refinement of the various versions of the wall, ready to deploy on azure, the results found previously installed in the NGINX,MYSQL environment, So it took a little time to study how to deploy, then there is this article, nonsense less, on dry:
Configuring the Environment
sudo apt-get install nginx php5-fpm php5-cli php5-mcrypt git
Nginx will be installed as a Web server, and some PHP tools will be installed, and git is installed to pull the replacement code for post-deployment.
Change PHP Configuration
After installing the appeal component, we need to do some configuration, first we need to open fpm/php.ini, to change the fix_pathinfo to 0
sudo vim /etc/php5/fpm/php.ini
cgi.fix_pathinfo=0
The setting here is to let PHP do not attempt to execute a similar name script when the requested file is absent, to prevent the attacker from tricking PHP into executing some code that should not be executed, and finally we need to explicitly enable the MCrypt extension and restart the PHP5-FPM service to reload so that the changes
sudo php5enmod mcrypt
sudo service php5-fpm restart
Configure Nginx
Below we want to configure Nginx, there are some paths, here I use Apt-get installed Nginx, if it is manually compiled installation, please self-seeking path, first we want to create a directory to place our Laravel code, here I put directly to/usr/share/ Nginx/laravel
sudo mkdir -p /usr/share/nginx/laravel
Below we need to configure our Nginx
sudo nano /etc/nginx/sites-available/default
That's probably what you see here.
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}
#location ~ \.php$ {
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_index index.php;
#include fastcgi_params;
#}
#}
Need to replace it with the following configuration file, where server_name to replace your own domain name or IP, where root content is just the directory we created Laravel and a public directory, The purpose of the public directory here is to remove the public from the Laravel route we request each time, giving way to a more semantic
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/laravel/public;
index index.php index.html index.htm;
server_name server_domain_or_IP;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Finish these our work basically finished, in the directory to deploy the written Laravel program, open the bound domain name can see the effect of the
Postscript
Today, someone on the QQ asked me the deployment of the problem, in general can use FTP, in the advanced point can use SFTP, or build svn, but since the git, I usually first create a project on Git, the local development of the push up, pull down on the test server, test pass , pull down on the production server, this is enough to deal with most of the scenes, but in the construction of distributed projects I usually write an automated script to do the repetitive work for me, so that the recent period of good mood when I will use Docker.
Note: GitHub above the public project is free, but private projects to spend money, and these two days home to my home network is not even on GitHub, so domestic I recommend to do ' Hidden ' project when using Oschina git, the speed is quite good, and each account can create 1000 free items, public or private can be. This year's new projects have been put on the Oschina,. NET project also gave up TFS (because of the speed reason, sometimes disconnect), except for occasional conflicts vs can't solve the command line that needs to be on git, the experience is pretty good
Use Nginx to deploy Laravel under Ubuntu