How To Install Laravel 5 Framework on Ubuntu 16.04, 14.04 & LinuxMint

2017年1月19日

Laravel is an open source PHP framework, designed for the faster development of MVC web applications in PHP. This article will help you to install Laravel 5 PHP Framework on Ubuntu 15.04 LTS, 14.04 LTS, 12.04 LTS, Debian and LinuxMint operating systems.

Step 1 – 安装 LAMP

To start with Laravel, we first need to set up a running LAMP server. If you have already running LAMP stack skip this step else use followings commands to set up lamp on Ubuntu system.

Install PHP 5.6

  1. $ sudo apt-get install python-software-properties
  2. $ sudo add-apt-repository ppa:ondrej/php
  3. $ sudo apt-get update
  4. $ sudo apt-get install -y php5.6 php5.6-mcrypt php5.6-gd

Install Apache2

  1. $ apt-get install apache2 libapache2-mod-php5

Install MySQL

  1. $ apt-get install mysql-server php5.6-mysql

Step 2 – 安装 Composer

Composer is required for installing Laravel dependencies. So use below commands to download and use as a command in our system.

建立自己规划的目录 例如 我希望我的目录在 /home/baron/

  1. useradd baron
  2. mkdir /home/baron/
  3. chown -R baron:baron /home/baron/
  4. cd /home/baron/
  5. $ curl -sS https://getcomposer.org/installer | php
  6. $ sudo mv composer.phar /usr/local/bin/composer
  7. $ sudo chmod +x /usr/local/bin/composer

Step 3 – 安装 Laravel

现在您已经安装了composer,我们可以用它来安装Laravel。 我们希望安装Laravel /home/baron/website 目录。Laravel安装最新版本,你可以输入:

cd /home/baron/

sudo composer create-project laravel/laravel /home/baron/website

Installing laravel/laravel (v5.3.16)
- Installing laravel/laravel (v5.3.16) Loading from cache
Created project in /home/crm/web-crm
> php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 61 installs, 0 updates, 0 removals
- Installing vlucas/phpdotenv (v2.4.0) Downloading: 100%
- Installing symfony/polyfill-mbstring (v1.3.0) Downloading: 100%
- Installing symfony/var-dumper (v3.1.9) Downloading: 100%
- Installing symfony/translation (v3.1.9) Downloading: 100%
- Installing symfony/routing (v3.1.9) Downloading: 100%
- Installing symfony/process (v3.1.9) Downloading: 100%
- Installing psr/log (1.0.2) Downloading: 100%
- Installing symfony/debug (v3.1.9) Downloading: 100%
- Installing symfony/http-foundation (v3.1.9) Downloading: 100%
- Installing symfony/event-dispatcher (v3.2.2) Downloading: 100%
- Installing symfony/http-kernel (v3.1.9) Downloading: 100%
- Installing symfony/finder (v3.1.9) Downloading: 100%
- Installing symfony/console (v3.1.9) Downloading: 100%
- Installing swiftmailer/swiftmailer (v5.4.5) Downloading: 100%
- Installing paragonie/random_compat (v2.0.4) Downloading: 100%
- Installing ramsey/uuid (3.5.2) Downloading: 100%
- Installing jakub-onderka/php-console-color (0.1) Downloading: 100%
- Installing jakub-onderka/php-console-highlighter (v0.3.2) Downloading: 100%
- Installing dnoegel/php-xdg-base-dir (0.1) Downloading: 100%
- Installing nikic/php-parser (v3.0.2) Downloading: 100%
- Installing psy/psysh (v0.8.1) Downloading: 100%
- Installing nesbot/carbon (1.22.1) Downloading: 100%
- Installing mtdowling/cron-expression (v1.1.0) Downloading: 100%
- Installing monolog/monolog (1.22.0) Downloading: 100%
- Installing league/flysystem (1.0.32) Downloading: 100%
- Installing symfony/polyfill-util (v1.3.0) Downloading: 100%
- Installing symfony/polyfill-php56 (v1.3.0) Downloading: 100%
- Installing jeremeamia/superclosure (2.3.0) Downloading: 100%
- Installing doctrine/inflector (v1.1.0) Downloading: 100%
......
......

Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader
The compiled class file has been removed.
> php artisan key:generate
Application key [base64:iudMCCDQtp4DKZQ9jEAXHmlXprpfYFZBCSr7FI8D7ww=] set successfully.

cd website
ls
app bootstrap composer.lock database package.json public resources server.php tests
artisan composer.json config gulpfile.js phpunit.xml readme.md routes storage vendor

指定版本

  1. composer create-project laravel/laravel /var/www/laravel 4.2

权限的设定 根据自己的需求自定义

  1. sudo chown -R :www-data /var/www/laravel
  2. sudo chmod -R 775 /var/www/laravel/app/storage

Step 4 – Nginx + php-fpm

Nginx 的配置

  1. server {
  2. listen 192.157.228.47:8082;
  3. server_name 192.157.228.47;
  4. root /home/crm/web-crm/public;
  5. access_log /var/log/nginx/mysql.rive.com-access.log;
  6. error_log /var/log/nginx/mysql.rive.com-error.log;
  7. set $root_path /home/crm/web-crm/public;
  8. allow 221.226.186.102;
  9. allow 121.225.75.245;
  10. allow 106.187.53.193;
  11. allow 47.90.42.218;
  12. allow 110.10.178.82;
  13. deny all;
  14. #auth_basic "Restricted Please Tell Me Who Are You?";
  15. #auth_basic_user_file /etc/nginx/pwd/rive.pwd;
  16. location / {
  17. index index.php index.html index.htm;
  18. try_files $uri $uri/ index.php$uri?$args;
  19. }
  20. location ~ \.php$ {
  21. root $root_path;
  22. proxy_intercept_errors on;
  23. proxy_buffer_size 128k;
  24. proxy_buffers 4 128k;
  25. fastcgi_keep_conn on;
  26. fastcgi_buffers 16 128k;
  27. fastcgi_buffer_size 128k;
  28. #fastcgi_pass 127.0.0.1:9000;
  29. fastcgi_pass unix:/run/php/php5.6-fpm.sock;
  30. fastcgi_read_timeout 240;
  31. fastcgi_index index.php;
  32. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  33. include fastcgi_params;
  34. #include fastcgi_params.conf;
  35. }
  36. }

参考
https://www.digitalocean.com/community/tutorials/how-to-install-laravel-with-an-nginx-web-server-on-ubuntu-14-04

How To Install Laravel 5 Framework on Ubuntu 16.04, 14.04 & LinuxMint

没有评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注