阿里云这个月推出了云翼计划,让学生党可以低价(10CNY/M)购买阿里的低配ECS虚拟机,这大概是国内科技公司对学生做的较大的一次优惠了吧 =。=
可惜我已经大四开学了,正好也有开几个网站的想法,就入了这个ECS,不得不吐槽国内厂商没有国外厂商厚道啊,不仅没有免费服务,而且还斤斤计较享受优惠的人。要求申请账号的学生信息必须录入全国的学籍信息,也就是说大专学生不能享受这个优惠了;再者严格控制优惠到期时间,要求续费时间必须在毕业期间以内,我只能说:哎,相见恨晚;还有一点就是限定死的配置,我想稍微提高一点配置都不行,直接就给按原价来了……
那么闲话少说,今天没去图书馆复习考研,而是在搭建laraval框架 -。- 这个世界上最NB的PHP框架!
首先就在安装composer这一步卡住了。没有离线安装包,只有在线安装。我本机windows用的是upupw集成环境,里面的php有问题,组建不完整(没有openssl),于是我安装了windows的openssl命令行工具,然并卵。还是需要php包含openssl。
没办法,从官网上下载了一个最新的5.6.13 x64的php覆盖上去,不错可以运行,然后composer安装完毕,按照步骤走:
composer config -g repositories.packagist composer http://packagist.phpcomposer.com
composer create-project laravel/laravel mewxlaravel 5.0.22
搭建完成后在upupw里面建立新的虚拟机啊什么的,按照常规走,然后就遇到了纠结的地方:
- 站点目录指向/mewxlaravel
- 站点目录指向/mewxlaravel/public
因为laravel的网站主目录是在public文件夹,但是如指向public的话在前面几个目录还要调用文件的,所以会没有权限会失败;如果指向laravel根目录的话虽然可以通过<domain>/public/index.php访问,没有权限的问题了,但是我这个强迫症呐!
查了一下Apache的配置文件/Apache2/conf/httpd-vhosts.conf是这样的,3个路径全部指向laravel根目录:
<VirtualHost *:80>
DocumentRoot "D:/upupw/vhosts/learnlaravel"
ServerName 127.0.0.2:80
ServerAlias laravel.5
ServerAdmin [email protected]
DirectoryIndex index.html index.htm index.php default.php app.php u.php server.php
ErrorLog logs/127.0.0.2-error.log
CustomLog logs/127.0.0.2-access_%Y%m%d.log comonvhost
php_admin_value open_basedir "D:\upupw\vhosts\learnlaravel;D:\upupw\memcached\;D:\upupw\phpmyadmin\;D:\upupw\temp\;C:\WINDOWS\Temp\"
<Directory "D:/upupw/vhosts/learnlaravel">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<LocationMatch "/(inc)/(.*)$">
AllowOverride none
Require all denied
</LocationMatch>
<LocationMatch "/(attachment|attachments|uploadfiles|avatar)/(.*).(php|php5|phps|asp|asp.net|jsp)$">
AllowOverride none
Require all denied
</LocationMatch>
</VirtualHost>
查了很多资料最后了解到只要把DocumentRoot后面的路径改成public就行了,其他的都是和权限相关的,用laravel根目录,改完之后是这样的(只改了一处路径):
<VirtualHost *:80>
DocumentRoot "D:/upupw/vhosts/learnlaravel/public"
ServerName 127.0.0.2:80
ServerAlias laravel.5
ServerAdmin [email protected]
DirectoryIndex index.html index.htm index.php default.php app.php u.php server.php
ErrorLog logs/127.0.0.2-error.log
CustomLog logs/127.0.0.2-access_%Y%m%d.log comonvhost
php_admin_value open_basedir "D:\upupw\vhosts\learnlaravel;D:\upupw\memcached\;D:\upupw\phpmyadmin\;D:\upupw\temp\;C:\WINDOWS\Temp\"
<Directory "D:/upupw/vhosts/learnlaravel">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<LocationMatch "/(inc)/(.*)$">
AllowOverride none
Require all denied
</LocationMatch>
<LocationMatch "/(attachment|attachments|uploadfiles|avatar)/(.*).(php|php5|phps|asp|asp.net|jsp)$">
AllowOverride none
Require all denied
</LocationMatch>
</VirtualHost>
然后就可以尽情地装币咯!因为教程是4.0.x的版本,所以<domain>/home也可以访问!(P.S.如果rewrite错误的话Auth访问需要通过<domain>/index.php/home)
This month Alibaba Cloud launched its Cloud Wings Program, letting students buy a low-spec Alibaba ECS virtual machine on the cheap (10 CNY/month). This is probably one of the biggest student discounts offered by a domestic tech company so far =。=
Too bad I’m already starting my senior year of college! Still, I happened to have ideas for launching a few websites, so I grabbed this ECS. I can’t help grumbling that domestic providers just aren’t as generous as overseas ones—not only are there no free tiers, they’re also super stingy about who qualifies for the discount. Your student info has to be registered in the national higher-education student registry (meaning vocational college students don’t qualify); on top of that, they strictly cap the discount duration so renewals must fall before graduation—all I can say is, man, I wish I’d met you sooner! And the hardware specs are completely locked down: even if I want to bump them up slightly, nope, straight back to full price…
Anyway, enough rambling. Today I skipped going to the library to study for grad school entrance exams and instead set up the Laravel framework -。- the most badass PHP framework on earth!
Right off the bat, I got stuck installing Composer. There’s no offline installer, only an online one. On my local Windows machine I use the UPUPW all-in-one stack, and its bundled PHP was broken—missing components (no OpenSSL). I installed the Windows OpenSSL CLI tool, which did absolutely nothing. PHP itself still needed OpenSSL built in.
With no other choice, I downloaded the latest PHP 5.6.13 x64 from the official site and overwrote the old one. Nice, it worked! Composer installed cleanly, and I followed the setup steps:
composer config -g repositories.packagist composer http://packagist.phpcomposer.com
composer create-project laravel/laravel mewxlaravel 5.0.22
After setting up the project and creating a new virtual host in UPUPW as usual, I hit a dilemma:
- Point the site directory to
/mewxlaravel - Point the site directory to
/mewxlaravel/public
Laravel’s web root is the public folder, yet if you point everything to public, Laravel still needs to load files from parent directories, which fails with permission errors. Pointing it to the Laravel root directory solves the permission issue since you can access <domain>/public/index.php—but my OCD just couldn’t stand that!
I checked Apache’s config file /Apache2/conf/httpd-vhosts.conf, and it looked like this, with all three paths pointing to the Laravel root directory:
<VirtualHost *:80>
DocumentRoot "D:/upupw/vhosts/learnlaravel"
ServerName 127.0.0.2:80
ServerAlias laravel.5
ServerAdmin [email protected]
DirectoryIndex index.html index.htm index.php default.php app.php u.php server.php
ErrorLog logs/127.0.0.2-error.log
CustomLog logs/127.0.0.2-access_%Y%m%d.log comonvhost
php_admin_value open_basedir "D:\upupw\vhosts\learnlaravel;D:\upupw\memcached\;D:\upupw\phpmyadmin\;D:\upupw\temp\;C:\WINDOWS\Temp\"
<Directory "D:/upupw/vhosts/learnlaravel">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<LocationMatch "/(inc)/(.*)$">
AllowOverride none
Require all denied
</LocationMatch>
<LocationMatch "/(attachment|attachments|uploadfiles|avatar)/(.*).(php|php5|phps|asp|asp.net|jsp)$">
AllowOverride none
Require all denied
</LocationMatch>
</VirtualHost>
After digging through a bunch of docs, I finally realized you only need to change the DocumentRoot path to public. The other two paths are permission-related and should stay pointing at the Laravel root directory. After editing, it looks like this (only one path changed):
<VirtualHost *:80>
DocumentRoot "D:/upupw/vhosts/learnlaravel/public"
ServerName 127.0.0.2:80
ServerAlias laravel.5
ServerAdmin [email protected]
DirectoryIndex index.html index.htm index.php default.php app.php u.php server.php
ErrorLog logs/127.0.0.2-error.log
CustomLog logs/127.0.0.2-access_%Y%m%d.log comonvhost
php_admin_value open_basedir "D:\upupw\vhosts\learnlaravel;D:\upupw\memcached\;D:\upupw\phpmyadmin\;D:\upupw\temp\;C:\WINDOWS\Temp\"
<Directory "D:/upupw/vhosts/learnlaravel">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<LocationMatch "/(inc)/(.*)$">
AllowOverride none
Require all denied
</LocationMatch>
<LocationMatch "/(attachment|attachments|uploadfiles|avatar)/(.*).(php|php5|phps|asp|asp.net|jsp)$">
AllowOverride none
Require all denied
</LocationMatch>
</VirtualHost>
Now you can flex like a pro to your heart’s content! Because the tutorial is for version 4.0.x, <domain>/home works too! (P.S. If URL rewriting is misconfigured, Auth routes will need to be accessed via <domain>/index.php/home.)