This tutorial will involve the following tools: Ubuntu14.04LTSPHP5.5MySQLLaravel5.0Nginx this article has modified and added the original article based on Laravel4. It is also applicable to deployment and development on servers and is recommended to build a virtual machine environment through Vagrant for practice. Laravel is an open-source and modern PHP development framework. His goal is to provide developers with a simple and elegant development method.
This tutorial will involve the following tools:
- Ubuntu 14.04 LTS
- Python 5.5
- MySQL
- Laravel 5.0
- Nginx
This article adds some modifications to the original article based on Laravel 4, which is also applicable to server deployment.
We recommend that you use Vagrant to build a virtual machine environment and perform exercises.
Introduction
Laravel is an open-source and modern PHP development framework. His goal is to provide a simple and elegant development method that allows developers to quickly develop a complete web application.
In this guide, we will discuss how to install Laravel on Ubuntu 14.04 (LTS. We will use Nginx as our web server and Laravel 5.0.
Install Server Components
First, we need to update the software package to ensure that we have a new list of available software packages. Then we can install the necessary components:
Sudo apt-get update // get the list of recent packages sudo apt-get install nginx // install Nginx server sudo apt-get install php5-fpm // install php5sudo apt-get install php5-cli/ /install the php5 interface sudo apt-get install php5-mcrypt that runs on the command line // install php5 encrypted extended library sudo apt-get install php5-mysql // install php MySQL driver sudo apt-get install git // install git artifacts
Command to install Nginx as our web server and PHP language environment. Installgit
Becausecomposer
The basic component of the tool is git. We will use composer to install Laravel and update related packages.
Modify the PHP configuration file
Open the PHP configuration file.
sudo vim /etc/php5/fpm/php.ini
Findcgi.fix_pathinfo
Change0
, As follows:
cgi.fix_pathinfo=0
Save and exit because this is a possible security vulnerability.
Use php5enmod to enable the MCrypt extension:
sudo php5enmod mcrypt
Now we need to restart the php5-fpm service:
sudo service php5-fpm restart
PHP has been configured.
Configure Nginx and Web directories
Create a website directory:
sudo mkdir -p /var/www/laravel
Open the default nginx configuration file:
sudo vim /etc/nginx/sites-available/default
The default configuration is as follows:
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.html index.htm; server_name localhost; location / { try_files $uri $uri/ =404; }}
Modify as follows:
Server {listen 80 default_server; listen [:]: 80 default_server defaults 6only = on; # Set the root directory root/var/www/laravel/public; # default homepage index of the website. php index.html index.htm; # server name. Replace server_domain_or_IP with your own name or IP address server_name server_domain_or_IP; # modify it to Laravel forwarding rule; otherwise, PHP cannot obtain $ _ GET information, error 404: location/{try_files $ uri // index. php? $ Query_string ;}# PHP supports location ~ \. Php $ {try_files $ uri/index. php = 404; fastcgi_split_path_info ^ (. + \. php )(/. +) $; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index. php; fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; include fastcgi_params ;}}
After the modification is complete, we need to restart the nginx service:
sudo service nginx restart
Install Composer
Run the following command on the command line:
cd ~curl -sS https://getcomposer.org/installer | php
In the current directory, you will findcomposer.phar
This file is the execution file of Compoesr. We need to move it/usr/local/bin
In this way, Composer can be called globally.
sudo mv composer.phar /usr/local/bin/composer
The installation of Composer is complete.
Install Laravel
1. We use composer to install Laravel 5.0 to/var/www/laravel.
sudo composer create-project laravel/laravel laravel 5.0.22
2. Use Git to clone existing projects in the remote repository. Refer to Liao Xuefeng's article. This is also a good article for beginners to learn about Git.
Write Permission granted
Change the group to which the website directory belongs:
sudo chown -R :www-data /var/www/laravel
/var/www/laravel
This directory stores temporary files for various Laravel services, so you need to write the following permissions:
sudo chmod -R 775 /var/www/laravel
Complete
Open the IP address or domain name of the server in the browser and you should see that your website is running.
At this time, you can improve your code according to your own needs.
For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2
This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-08/121986.htm