Centos6.5中 一键安装LNMP 安装Yii2.0 手工配置

时间:2021-07-22 02:13:05

1、一键安装LNMP

cd /usr
wget -c http://soft.vpser.net/lnmp/lnmp1.2-full.tar.gz 
tar zxf lnmp1.-full.tar.gz 
cd lnmp1.-full 
./install.sh lnmp

进入安装状态后按照提示做安装选择( 参考 http://lnmp.org/install.html )

2、安装Yii2.0 

a 先安装好composer

//进入/usr目录
curl -sS https://getcomposer.org/installer | php
//移动(mv)composer到/usr/local/bin/ 并让它全局可执行(sudo)
sudo mv composer.phar /usr/local/bin/composer

b 然后在 /home/wwwroot 目录中运行 (参考 http://www.yiichina.com/doc/guide/2.0/start-installation)

composer global require "fxp/composer-asset-plugin:~1.0.0"
composer create-project --prefer-dist yiisoft/yii2-app-basic basic

可能的错误:

[Symfony\Component\Process\Exception\RuntimeException]
The Process class relies on proc_open, which is not available on your PHP installation.

解决办法:vim php.ini 查找proc,把禁用函数列表中proc相关的两个函数删除即可解决

c 出现:

> yii\composer\Installer::postCreateProject

chmod('runtime', 0777)...done.
chmod('web/assets', 0777)...done.
chmod('yii', 0755)...done.

就安装好了

安装过程中可能提示:

Could not fetch https://api.github.com/repos/RobinHerbots/jquery.inputmask/contents/bower.json?ref=4551607fef63fd4bcd675479a8c347b668b915eb, please create a GitHub OAuth token to go over the API rate limitHead to https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+localhost.localdomain+2015-12-24+1743to retrieve a token. It will be stored in "/root/.composer/auth.json" for future use by Composer.Token (hidden):

是要Github验证,参考http://www.cnblogs.com/jiufen/p/5073887.html即可

d 检查一下看看下载的文件,确实安装好了

[root@localhost wwwroot]# ll
total
drwxr-xr-x. root root Dec : basic
drwxr-xr-x. root root Dec : blog
drwxr-xr-x. www www Dec : default
drwxrwxrwx. root root Dec : yiibasic
[root@localhost wwwroot]# cd basic
[root@localhost basic]# ll
total
drwxr-xr-x. root root Aug : assets
drwxr-xr-x. root root Aug : commands
-rw-r--r--. root root Aug : composer.json
-rw-r--r--. root root Dec : composer.lock

3、手工配置基于域名的虚拟主机

a 打开/usr/local/nginx/conf/nginx.conf文件,复制 server{} 整体,粘贴在它的下面,修改部分见代码的注释

server
{
listen ;
#listen [::]: default_server ipv6only=on;
server_name www.blog.com;
index index.html index.htm index.php;
root /home/wwwroot/blog/public; #error_page /.html;
include enable-php.conf; location /nginx_status
{
stub_status on;
access_log off;
} location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
} location ~ .*\.(js|css)?$
{
expires 12h;
} location ~ /\.
{
deny all;
} access_log /home/wwwlogs/access.www.blog.com.log access;
} server
{
listen ;
#listen [::]: default_server ipv6only=on;
server_name www.basic.com;//虚拟域名!!!!!!!!!!!!!!!!!!!!!!!!!!!!
index index.html index.htm index.php;
root /home/wwwroot/basic/web;//网站index.php目录,一定要注意不是根目录,而且要有访问权限(yii2.0不用调整权限了可忽略)!!!!!!!!!! #error_page /.html;
include enable-php.conf; location /nginx_status
{
stub_status on;
access_log off;
} location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
} location ~ .*\.(js|css)?$
{
expires 12h;
} location ~ /\.
{
deny all;
} access_log /home/wwwlogs/access.www.basic.com.log access;//日志文件的位置!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}

b 重启服务器

service nginx restart    
用这个方式可以查找相关服务的位置,如果在/usr/bin/中有,就可以在任何地方直接执行这个服务相关的命令

[root@localhost web]# whereis nginx
nginx: /usr/bin/nginx /usr/local/nginx
[root@localhost web]#

c 在本机注册这个域名(这个不注册也可以啊,有点奇怪)

vim /etc/hosts

在文件中加入

127.0.0.1 www.basic.com

在本机(nginx主机)浏览器访问www.basic.com即可看到yii2.0的主页

可能的错误

Invalid Parameter – yii\base\InvalidParamException
The file or directory to be published does not exist: /home/wwwroot/basic/vendor/bower/jquery/dist

解决办法(然而,并不靠谱,试过不行,但在新系统中,先执行这里的命令在安装yii就没有错误)

composer self-update 1.0.-alpha11
composer clear-cache

参考 http://www.yiichina.com/topic/6077