Markdown

[PHP] 環境設定

PHP

參考:
1.http://php.net/manual/en/index.php
2.PHP,MYSQL,JAVASCRIPT 學習手冊
先照著laravel教學安裝環境
https://laravel.com/docs/5.4

install

Server Requirements
The Laravel framework has a few system requirements. Of course, all of these requirements are satisfied by the Laravel Homestead virtual machine, so it’s highly recommended that you use Homestead as your local Laravel development environment.
However, if you are not using Homestead, you will need to make sure your server meets the following requirements:
PHP >= 5.6.4
OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
XML PHP Extension
install vargant

通常要使用laravel需要安裝上面那堆東西,不過通過 homestead 這個設定好的環境,可以免去這些步驟。

不過往下讀,好像發現另一個東西更方便,叫做valet。
https://laravel.com/docs/5.4/valet
我們先安裝php 再安裝 composer 再來安裝 valet
brew update 
遇到問題
Error: /usr/local is not writable. You should change the ownership
and permissions of /usr/local back to your user account:
sudo chown -R $(whoami) /usr/local
跟著做
sudo chown -R $(whoami) /usr/local
然後就可以更新了
再來要裝php
brew install homebrew/php/php71
裝完之後來裝composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

This installer script will simply check some php.ini settings, warn you if they are set incorrectly, and then download the latest composer.phar in the current directory. The 4 lines above will, in order:
Download the installer to the current directory
Verify the installer SHA-384 which you can also cross-check here
Run the installer
Remove the installer
WARNING: Please do not redistribute the install code. It will change with every version of the installer. Instead, please link to this page or check how to install Composer programmatically.

裝完composer後
將composer 加到全域環境
mv composer.phar /usr/local/bin/composer
composer 是透過在 composer.json 中 require 套件來進行管理
composer global require laravel/valet
valet install 
solution:
echo PATH:~/.composer/vendor/bin
to ~/.bash_profile
Last login: Wed Apr 26 14:06:55 on ttys002
dujiahaodeMacBook-Pro:~ Eric$ echo $PATH
/Users/Eric/.nvm/versions/node/v6.2.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/Eric/.composer/vendor/bin
dujiahaodeMacBook-Pro:~ Eric$ valet install
Password:
[nginx] is not installed, installing it now via Brew... 🍻
[dnsmasq] is not installed, installing it now via Brew... 🍻

Valet installed successfully!
Once Valet is installed, try pinging any *.dev domain on your terminal using a command such as ping foobar.dev. If Valet is installed correctly you should see this domain responding on 127.0.0.1.
ping看看是否成功
成功後我們安裝symfony
 sudo mkdir -p /usr/local/bin
 sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
 sudo chmod a+x /usr/local/bin/symfony
安裝完建立第一個專案
$ symfony new hello
先用 valet park 建立環境

成功!

關於 valet park valet link
Serving Sites
Once Valet is installed, you’re ready to start serving sites. Valet provides two commands to help you serve your Laravel sites: park and link.
The park Command
Create a new directory on your Mac by running something like mkdir ~/Sites. Next, cd ~/Sites and run valet park. This command will register your current working directory as a path that Valet should search for sites.
Next, create a new Laravel site within this directory: laravel new blog.
Open http://blog.dev in your browser.
That’s all there is to it. Now, any Laravel project you create within your “parked” directory will automatically be served using the http://folder-name.dev convention.
The link Command
The link command may also be used to serve your Laravel sites. This command is useful if you want to serve a single site in a directory and not the entire directory.
To use the command, navigate to one of your projects and run valet link app-name in your terminal. Valet will create a symbolic link in ~/.valet/Sites which points to your current working directory.
After running the link command, you can access the site in your browser at http://app-name.dev.
To see a listing of all of your linked directories, run the valet links command. You may use valet unlink app-name to destroy the symbolic link.

vargant 有空再來研究。

亂玩一通

首先使用 Interactive shell
在terminal 輸入 php -a
echo “hi”
怎麼沒反應?
記得加 “;”
echo “hi”;
hi

留言