2014年12月9日 星期二

windows底下裝virtualbox跑centos7 並安裝 laravel

.在virtual box上安裝CentOS-7.0-1406-x86_64-Minimal.iso
.安裝完後關掉虛擬機,重開登入後,先查ip,安裝#yum install net-tool,之後#ifconfig ,記下這台虛擬機的ip
.關掉虛擬機,並用VBoxManage.exe startvm "centos" --type headless 重新打開虛擬機 裡面的centos 是你虛擬機的名稱,這樣做可以讓虛擬機在背景跑。
.使用putty,連上虛擬機,安裝常用套件 yum install -y denyhosts rdate sudo wget man mlocate vim unzip lsof
.更新yum ,#yum update
.安裝nginx
#sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
#sudo yum install nginx
.把80 port打開,/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
.啟動nginx #sudo systemctl start nginx.service
.試著連連看 ip 能不能打開nginx的welcome頁面
.#sudo systemctl enable nginx.service 加入開機執行
.安裝mysql db (安裝中的問題可以參考這篇 http://www.orztw.com/2014/02/install-mariadb-on-centos.html)
#sudo yum install mariadb-server mariadb
#sudo systemctl start mariadb
#sudo mysqladmin -u root password 'your-password'
.安裝php
#sudo yum install php php-mysql php-fpm

#sudo vi /etc/php.ini 把;cgi.fix_pathinfo=1的;拿掉後面改成0 cgi.fix_pathinfo=0

#sudo vi /etc/php-fpm.d/www.conf


修改listen = /var/run/php-fpm/php-fpm.sock

#sudo systemctl start php-fpm


#sudo systemctl enable php-fpm.service

修改nginx conf #sudo vi /etc/nginx/conf.d/default.conf


server {
    listen       80;
    server_name  server_domain_name_or_IP;

    root   /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

#sudo systemctl restart nginx

web root在/usr/share/nginx/html/

安裝phpmyadmin(https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-with-nginx-on-a-centos-7-server)

sudo yum install epel-release(這裡面有mcrypt)

sudo yum install phpmyadmin

sudo ln -s /usr/share/phpMyAdmin /usr/share/nginx/html

sudo systemctl restart php-fpm

http://your/phpMyAdmin/

安裝laravel,先安裝composer

下載->#sudo curl -sS https://getcomposer.org/installer | sudo php

移到bin底下->#mv composer.phar /usr/local/bin/composer
try-> #composer

安裝laravel

#composer global require "laravel/installer=~1.1"

找個好目錄執行
composer create-project laravel/laravel your-project-name --prefer-dist

把新增的專案裡的

app/storage 設定可寫權限

進入專案,執行 #php artisan serve --host 你的ip --port 你的port

port如果設80會跟ngiinx相衝,關掉nginx的就可以了

之後就可以在外部連上去看結果了。


※假如你直接使用#php artisan serve,他應該是顯示 http://localhost:8000/
這在虛擬機裡是連的到的,但在外面就連不到了 因為你外面的localhost是指向127.0.0.1









沒有留言:

張貼留言