vagrant的学习 之 Yii2


本文根据慕课网的视频教程练习,感谢慕课网!

慕课视频学习地址:https://www.imooc.com/video/14218

慕课的参考文档地址:https://github.com/apanly/mooc/tree/master/va

Yii2的中文官网地址:https://www.yiichina.com/


第一步,需要安装composer:

curl -sS https://getcomposer.org/installer | php

返回失败:

All settings correct for using Composer
Downloading...
Failed to decode zlib stream

再次执行该命令,返回成功:

All settings correct for using Composer
Downloading... Composer (version 1.7.) successfully installed to: /home/www/yii2/composer.phar
Use it: php composer.phar

然后把composer修改为全局变量,执行:

mv composer.phar /usr/local/bin/composer

第二步,安装Yii:

composer create-project --prefer-dist yiisoft/yii2-app-basic basic

报错:

Cannot create cache directory /home/vagrant/.composer/cache/repo/https---repo.packagist.org/, 
or directory is not writable. Proceeding without cache

给目录增加权限:

sudo chmod -R  /home/vagrant/.composer/cache/

再次执行,还是报错:

The "https://repo.packagist.org/packages.json" file could not be downloaded: SSL: crypto enabling timeout
Failed to enable crypto
failed to open stream: operation failed
https://repo.packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date [Composer\Downloader\TransportException]
Content-Length mismatch, received bytes out of the expected

超时了,搜索后尝试修改composer的国内镜像下载地址,实现加速试一试:

composer config -g repo.packagist composer https://packagist.phpcomposer.com

结果显示无权限:

[ErrorException]
touch(): Unable to create file /home/vagrant/.composer/config.json because Permission denied

给文件增加权限:

sudo chmod -R  /home/vagrant/.composer/

然后再次执行修改composer的下载地址:

  composer config -g repo.packagist composer https://packagist.phpcomposer.com

这次没有报错,查看配置文件已经修改:

cat /home/vagrant/.composer/config.json

显示:

{
"config": {},
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.phpcomposer.com"
}
}
}

然后再次尝试下载yii框架:

composer create-project --prefer-dist yiisoft/yii2-app-basic basic

下载成功,发现目录下多了个basic目录

重命名项目名字:

mv basic yii2

第三步,配置nginx:

//进入nginx的配置目录
cd /etc/nginx/conf.d/
//常见yii的配置文件
sudo touch yii2.conf
//编辑配置文件
sudo vim yii2.conf
//文件内容
server{
server_name study.yii2.com;
root /home/www/yii2/web;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
} location ~ \.php${
include fastcgi_params;
fastcgi_pass 127.0.0.1:;
try_files $uri = ; }
}

修改host文件:

sudo vim  /etc/hosts

增加:

IP地址   study.yii2.com

然后重启nginx

sudo /etc/init.d/nginx restart

最后配置本地主机的host文件:

也增加:

IP地址  study.yii2.com

就可以在本地访问 study.yii2.com 了。


第四步,配置apache:

进入apache的配置目录:

cd /etc/apache2/sites-enabled

创建配置文件:

sudo touch yii2.conf

编辑配置文件:

sudo vim yii2.conf
<VirtualHost *:>
ServerName study.yii2.com
DocumentRoot /home/www/yii2/web/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

重启apache:

sudo /etc/init.d/apache2 restart

ok,配置完成。


总结:

  1、虽然看视频或者文档感觉简单,很快就看完了,但是自己并没有记住,还是需要多加练习才行;

  2、实际操作起来更会有很多意外的错误发生,这时候就需要耐心,分析解决问题,有的错误可能很快找到解决方法,但是有些却耗费时间也没有搜到答案,只能另寻途径或暂时跳过。

  


欢迎大家指点。

最新文章

  1. OpenCV在VS2005下的配置
  2. 解决VS Code调试.NET Core应用遇到的坑
  3. collectionView使用细节
  4. NSBlockOperation添加多个任务
  5. .NET DLL 保护措施详解(三)最终效果
  6. Girls&#39; research
  7. jquery ajax 跨域提交(附IE浏览器解决方案)
  8. window.showModalDialog()的简单用法
  9. Boost的VS开发环境搭建
  10. 屌丝技能--转Json(Newtonsoft.Json.dll)
  11. Python+requests库 POST接口图片上传
  12. mysql数据与Hadoop之间导入导出之Sqoop实例
  13. C#即时释放内存
  14. MySQL 练习题 附答案,未完
  15. thymeleaf(二)
  16. springboot mybatis pagehelper 分页问题
  17. mysql之 mysql_config_editor/login-path 登录密码保护
  18. Sprint 1 Review &amp; Daily Scrum - 11/18
  19. JAVA动态编译(JavaCompiler)
  20. Keepalived系列一:Keepalived.conf 详解

热门文章

  1. ssl证书过期问题解决
  2. 在colab上运行style-transfer
  3. 计算1至n的k次方的和
  4. 写给技术lead的招聘指南
  5. 【转】windows server 2012 安装 VC14(VC2015) 安装失败解决方案
  6. sccm系统更新补丁后服务无法正常启动
  7. Vsphere中ESXi主机ssh开启的三种方法
  8. 【转】密码学 :CSP的概念
  9. QT+模态对话框与非模态对话框
  10. ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath