[实践OK]Linux下 php环境安装、配置composer,使用composer安装laravel/lumen、zan等框架,写一个读取数据库的。 不指定

justwinit 2017-1-10 23:17 | |
实践如下:
/usr/local/composer


From:https://getcomposer.org/download/
http://blog.csdn.net/yoywow/article/details/52074512

二、使用composer安装laravel/lumen:
遇到问题:
修改 composer 的全局配置文件(推荐方式)

打开命令行窗口(windows用户)或控制台(Linux、Mac 用户)并执行如下命令:
[root@a composer]# chtdocs
[root@a htdocs]# cd lumen.levoo.com/
[root@a lumen.levoo.com]# /usr/local/composer/composer.phar global require "laravel/lumen-installer"
Changed current directory to /root/.config/composer
Do not run Composer as root/super user! See https://getcomposer.org/root for details
compser 执行命令提示do not run composer as root/super !
这个是因为composer为了防止非法脚本在root下执行,解决办法随便切换到非root用户即可
PATH变量设置Ok的方法如下:
打开~/.bashrc
sudo vim ~/.bashrc
添加行:
export PATH=$PATH:/home/lumen/.config/composer/vendor/bin


用Linux系统。比如要把/etc/apache/bin目录添加到PATH中,方法有三:
1.#PATH=c/etc/apache/bin
使用这种方法,只对当前会话有效,也就是说每当登出或注销系统以后,PATH 设置就会失效

2.#vi /etc/profile
在适当位置添加 PATH=$PATH:/etc/apache/bin (注意:= 即等号两边不能有任何空格)
这种方法最好,除非你手动强制修改PATH的值,否则将不会被改变

3.#vi ~/.bash_profile
修改PATH行,把/etc/apache/bin添加进去
这种方法是针对用户起作用的
From:http://opsmysql.blog.51cto.com/2238445/665990


lumen没有成功:



useradd lumen
su lumen
cd /data/htdocs/laravel.levoo.com
/usr/local/composer/composer.phar  config -g repo.packagist composer https://packagist.phpcomposer.com


进行上述设置后,laravel有门,能下载了:
[lumen@a laravel.levoo.com]$ pwd
/data/htdocs/laravel.levoo.com
[lumen@a laravel.levoo.com]$ /usr/local/composer/composer.phar global require "laravel/lumen-installer"  
Changed current directory to /home/lumen/.config/composer
Using version ^1.0 for laravel/lumen-installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 10 installs, 0 updates, 0 removals
  - Installing symfony/process (v3.2.1) Downloading: 100%        
  - Installing psr/log (1.0.2) Downloading: 100%        
  - Installing symfony/debug (v3.2.1) Downloading: 100%        
  - Installing symfony/polyfill-mbstring (v1.3.0) Downloading: 100%        
  - Installing symfony/console (v3.2.1) Downloading: 100%        
  - Installing guzzlehttp/promises (v1.3.1) Downloading: 100%        
  - Installing psr/http-message (1.0.1) Downloading: 100%        
  - Installing guzzlehttp/psr7 (1.3.1) Downloading: 100%        
  - Installing guzzlehttp/guzzle (6.2.2) Downloading: 100%        
  - Installing laravel/lumen-installer (v1.0.2) Downloading: 100%        
symfony/console suggests installing symfony/event-dispatcher ()
symfony/console suggests installing symfony/filesystem ()
Writing lock file
Generating autoload files


生成文件如下:
[lumen@a composer]$ pwd
/home/lumen/.config/composer

[lumen@a composer]$ ls  /home/lumen/.config/composer
auth.json  composer.json  composer.lock  config.json  vendor


开始学习数据库:
http://blog.csdn.net/wowkk/article/details/52104689

/data/htdocs/lumen.levoo.com/blog/.env
APP_ENV=local
APP_DEBUG=true
APP_KEY=
APP_TIMEZONE=UTC

DB_CONNECTION=mysql
DB_HOST=10.44.202.177
DB_PORT=3306
DB_DATABASE=levoo_egg
DB_USERNAME=levoo
DB_PASSWORD=new@levoo.com

CACHE_DRIVER=memcached
QUEUE_DRIVER=sync

/data/htdocs/lumen.levoo.com/blog/app/Http/Controllers/AccountController.PHP


/data/htdocs/lumen.levoo.com/blog/routes/web.php
<?php

$app->group(["namespace"=>"App\Http\Controllers"], function()use($app){
    //账户控制器
    $app->get("/AccountController",["uses" => "AccountController@accountController"]);
});


model:/data/htdocs/lumen.levoo.com/blog/app/Models/User.php
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
class User extends Model
{
}



在app/Http/Controllers目录下AccountController.php,修改为

<?php

namespace App\Http\Controllers;

use App\user;   //新增部分
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class AccountController extends BaseController
{
    //直接传人sql方式操作数据库
    function accountController(Request $request){
        return User::all();
    }
}

http://101.200.189.210/AccountController/accountController

作者:justwinit@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://justwinit.cn/post/9170/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: justwinit 编辑于2017-1-12 23:30
评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]