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

jackxiang 2017-1-10 23:17 | |
composer config -g repo.packagist composer https://packagist.phpcomposer.com #换国内镜像URL地址。
composer是一个可执行命令,你在一个空目录下写一个composer.json
然后执行composer update,就能生成。
====================两步:软链接composer/PATH/下载autoloader===========================
软链接加PATH,/usr/local/composer/composer -> composer.phar:
ls /usr/local/composer/
composer  composer.phar

cat /etc/profile.d/composer.sh
PATH=$PATH:/usr/local/composer
export PATH
source /etc/profile.d/composer.sh


cd /usr/local/kafka-php
cat composer.json
{
        "require": {
                "nmred/kafka-php": "0.2.*"
        }
}

composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 3 installs, 0 updates, 0 removals
  - Installing amphp/amp (v1.2.2): Downloading (100%)        
  - Installing psr/log (1.0.2): Downloading (100%)        
  - Installing nmred/kafka-php (v0.2.0.8): Downloading (100%)        
Writing lock file
Generating autoload files

cd /usr/local/kafka-php
composer.json  composer.lock  vendor
目的是看下同事所说的Kafka死光了,kafka-php会退出的问题:
https://github.com/weiboad/kafka-php

===========================================================================

cd /usr/local/composer  ,sudo -u www -H composer.phar install ,会去读取:/usr/local/composer/composer.json文件。
chown -R www.www /data/htdocs/sd.levoo.com #否则会报:/data/htdocs/sd.levoo.com/vendor does not exist and could not be created.
sudo -u www -H composer.phar install

实践如下:


vi /etc/sudoers
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/mysql/bin:/usr/local/composer:/usr/local/php/bin


#sudo -u www -H composer.phar config -g repo.packagist composer https://packagist.phpcomposer.com                                                                                                    
  [ErrorException]                                                                                  
  touch(): Unable to create file /home/www/.composer/config.json because No such file or directory  

#mkdir  /home/www
#chown www.www /home/www
#chmod 755 /home/www
#sudo -u www -H composer.phar config -g repo.packagist composer https://packagist.phpcomposer.com


#sudo -u www -H composer.phar install
Composer could not find a composer.json file in /usr/local/composer
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section

建立composer.json如下,可以根据需要添加你所依赖的库,但下面一定得包含在内,autoload必须要指定app和test的目录不得省略。

{
  "require": {
    "tmtbe/swooledistributed":">2.0.0"
  },
"autoload": {
    "psr-4": {
      "app\\": "src/app",
      "test\\": "src/test"
    }
  }
}
/usr/local/composer/composer.json
运行:
#sudo -u www -H composer.phar install
Loading composer repositories with package information
Updating dependencies (including require-dev)
  [RuntimeException]                                                  
  /usr/local/composer/vendor does not exist and could not be created.

  [RuntimeException]                                                                
  /usr/local/composer/vendor/symfony/intl does not exist and could not be created

  - Installing symfony/intl (v3.3.8):
                                                                                          
  [Symfony\Component\Process\Exception\RuntimeException]                                  
  The Process class relies on proc_open, which is not available on your PHP installation.  
      
PHP需有proc_open,得从PHP的php.ini里给去掉:
; disable_functions = chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_
restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket

#sudo -u www -H composer.phar install
Composer could not find a composer.json file in /usr/local/php/etc
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
得cd到:/usr/local/composer 里,再执行:sudo -u www -H composer.phar install
#sudo -u www -H composer.phar install
  [ErrorException]                                          
  proc_get_status() has been disabled for security reasons   和上面一样:得从PHP的php.ini里给去掉。
  [RuntimeException]                                          
  Could not delete /usr/local/composer/vendor/symfony/intl:
  chown -R www.www  /usr/local/composer/vendor
  [ErrorException]                                                              
  file_put_contents(./composer.lock): failed to open stream: Permission denied   #写入/usr/local/composer/composer.lock权限不够。
[root@gitlab-jenkins_php-redis_123.57.252.183:/usr/local]
#chown www.www composer
#sudo -u www -H composer.phar install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。


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

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


最后编辑: jackxiang 编辑于2017-12-20 11:16
评论列表
发表评论

昵称

网址

电邮

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