--- tags: PHP / Laravel / Lumen --- # Laravel 開發環境設定 ### 開發環境 本文章以 Ubuntu 的 LAMP 安裝為主軸 請先備齊PHP、MySQL、Composer、Apache、Git ※本系列文章以 Laravel 5.8 + PHP 7.2 進行撰寫 ### Windows 環境建置 (兩者擇一) 1. [wagon](https://opensource.laravel-dojo.com/packages/wagon) 2. [WampServer](http://www.wampserver.com/en/) 3. [XAMPP](https://www.apachefriends.org/zh_tw/download.html) ※WampServer使用者需額外下載 [Visual C++ 可轉散發套件2012](https://www.microsoft.com/zh-tw/download/details.aspx?id=30679) [Visual C++ 可轉散發套件2015](https://www.microsoft.com/zh-TW/download/details.aspx?id=48145) ※WampServer 與 XAMPP 需額外安裝 Git 與 Composer ※wagon內的 Cmder (終端命令工具) 已設定環境變數,所以無須另外下載 Composer 與 Git ※wagon UwAmp 的 MySQL 預設 Port 為 33060 ### 建立專案 1. wagon使用者將目錄切換至 uwamp\www 2. Wamp使用者將目錄切換至 wamp64\www 3. XAMPP使用者將目錄切換至 xampp\htdocs 4. 執行命令 ```composer create-project laravel/laravel --prefer-dist blog 5.8.*``` ### 修改專案環境參數 修改專案根目錄「.env」內之DB_DATABASE、DB_USERNAME、DB_PASSWORD ※由於UwAmp MySQL預設Port為33060,所以請UwAmp使用者將DB_PORT改為33060 ### 啟動服務 請參照各工具相關之 Apache 設定文章 --- ### Ubuntu 16.04 1. Apache、vim、Git、wget ``` $ apt update $ apt install vim git apache2 wget -y ``` 2. MySQL (安裝過程中,會要求設定root密碼,此處示範密碼為root) ``` $ apt install mysql-server -y $ mysql -u root -proot # 進入MySQL後 mysql > CREATE DATABASE blog; # 可自行新增使用者,並賦予權限 (以帳號test、密碼1234為例) mysql > CREATE USER 'test'@'localhost' IDENTIFIED BY '1234'; mysql > GRANT ALL ON *.* TO 'test'@'%' IDENTIFIED BY '1234' WITH GRANT OPTION; mysql > FLUSH PRIVILEGES; # 離開MySQL mysql > quit $ service mysql restart $ service apache2 restart ``` 3. PHP ``` $ apt install software-properties-common -y $ apt install python-software-properties -y $ apt-add-repository ppa:ondrej/php $ apt update $ apt install -y php7.2 php7.2-cli php7.2-fpm php7.2-mbstring php7.2-xml php7.2-zip php7.2-common php7.2-opcache php7.2-soap php7.2-gd php7.2-imap php7.2-curl php7.2-tidy php7.2-dev php7.2-json php7.2-mysql php7.2-bcmath php7.2-intl libapache2-mod-php7.2 $ a2dismod php7.0 $ a2query -m php7.2 (或 a2enmod php7.2) $ a2enmod rewrite $ service apache2 restart ``` 4. phpMyAdmin ``` $ apt install phpmyadmin -y $ ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin ``` 5. Composer ``` $ wget -c https://getcomposer.org/composer.phar $ chmod u+x composer.phar $ mv composer.phar /usr/local/bin/composer ``` 6. 建立專案 ``` $ cd /var/www $ composer create-project laravel/laravel --prefer-dist blog 5.8.* # 設定專案參數 (資料庫名稱、帳號、密碼) $ vim blog/.env # 更改目錄擁有者及Storage存取權限 $ chown -R www-data:www-data blog/ $ chmod -R 775 blog/storage/ ``` 7. Apache 站台設定 ``` # 設定vhost $ vim /etc/hosts # /etc/hosts加入此行 127.0.0.1 laravel.local # 設定站台 $ vim /etc/apache2/sites-enabled/000-default.conf <VirtualHost *:80> ServerName laravel.local ServerAdmin webmaster@localhost DocumentRoot /var/www/blog/public <Directory "/var/www/blog/public"> Options FollowSymLinks AllowOverride All </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> # 重啟Apache $ service apache2 restart ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up