标题:[实践OK]Linux下 php环境安装、配置composer,使用composer安装laravel/lumen、zan等框架,写一个读取数据库的。 出处:向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除 时间:Tue, 10 Jan 2017 23:17:33 +0000 作者:jackxiang 地址:http://jackxiang.com/post/9170/ 内容: /usr/bin/env: PHP: No such file or directory报错 su www [root@VM-0-15-centos ~]# curl -sS https://getcomposer.org/installer | php #把composer.phar转移之bin目录以便全局使用 [root@VM-0-15-centos ~]# mv composer.phar /usr/local/bin/composer #展示版本信息说明成功 [root@VM-0-15-centos ~]# composer -v 如果出现这个提示,是因为composer不建议root账号运行,可以输入y,或者切换账号 Do not run Composer as root/super user! See https://getcomposer.org/root for details Continue as root/super user [yes]? sudo -u www -H/usr/local/composer/bin/composer config repo.packagist composer https://mirrors.aliyun.com/composer/ [ErrorException] touch(): Unable to create file /home/www/.config/composer/config.json because No such file or directory #composer clear-cache Do not run Composer as root/super user! See https://getcomposer.org/root for details Continue as root/super user [yes]? yes Cache directory does not exist (cache-vcs-dir): Cache directory does not exist (cache-repo-dir): Cache directory does not exist (cache-files-dir): Clearing cache (cache-dir): /root/.cache/composer 如果是其它用户就是在它的家目录下面建立配置文件。 [root@nexus-repo-10-10-0-109:/data/www/l.levoo.com] #sudo -u www -H /usr/local/composer/composer update Loading composer repositories with package information [root@nexus-repo-10-10-0-109:/data/www/l.levoo.com] #sudo -u www -H /usr/local/composer/composer update ...... Package operations: 41 installs, 14 updates, 38 removals Failed to download dragonmantank/cron-expression from dist: The zip extension is missing and unzip/7z commands cannot be called as proc_open is disabled, skipping. Your command-line PHP is using multiple ini files. Run `php --ini` to show them. Now trying to download from source PHP的一些安全函数禁用了,打开就成功了: - Upgrading easyswoole/task (1.0.5 => 1.1.2): Extracting archive - Upgrading easyswoole/log (1.0.3 => 1.1.1): Extracting archive Generating autoload files 28 packages you are using are looking for funding. Use the `composer fund` command to find out more! 然后执行compser up 或者备份composer.lock ========================================================================== composer config -g repo.packagist composer https://packagist.phpcomposer.com #换国内镜像URL地址。 composer是一个可执行命令,你在一个空目录下写一个composer.json 然后执行composer update,就能生成。 ====================两步:软链接composer/PATH/下载autoloader=========================== 软链接加PATH: cat > /etc/profile.d/composer.sh <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用户即可 su www mkdir -p /home/www/.cache chown -R www:www /home/www/.cache composer require easyswoole/hot-reload Cannot create cache directory /home/www/.cache/composer/repo/https---mirrors.aliyun.com-composer/, or directory is not writable. Proceeding without cache Cannot create cache directory /home/www/.cache/composer/files/, or directory is not writable. Proceeding without cache Using version ^0.1.2 for easyswoole/hot-reload ./composer.json has been updated 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没有成功: su xiangdong /usr/local/composer/composer.phar global require "laravel/lumen-installer" Changed current directory to /home/xiangdong/.config/composer 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 input("name");//请求参数 $results = app('db')->select("SELECT * FROM users"); return $results ; } } /data/htdocs/lumen.levoo.com/blog/routes/web.php 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