---
# System prepended metadata

title: laravel on apache virtual host
tags: [laravel 筆記]

---

---
tags: laravel 筆記
---
# laravel on apache virtual host
參考：https://medium.com/%E6%B5%A6%E5%B3%B6%E5%A4%AA%E9%83%8E%E7%9A%84%E6%B0%B4%E6%97%8F%E7%BC%B8/laravel-5-4-on-apache-%E5%9C%A8-apache-%E6%9E%B6-laravel-%E7%B6%B2%E7%AB%99-9b7d1ad938af

- ### 使用apache 創立新的虛擬機
```
sudo vim /etc/apache2/sites-available/laravel.conf
```
- ### 內容
```
<VirtualHost *:8080>
    ServerName localhost

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/apache/laravel_test/public

    <Directory /var/www/apache/laravel_test>
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

```
將路徑改到laravel 專案

- ### 將預設的虛擬機停掉 啟用新建的虛擬機
```
sudo a2dissite 000-default.conf #=> 把原本預設的設定 disable
sudo a2ensite laravel.conf
```
ps. 啟用後在 /etc/apache2/sites-enabled 內會有連結檔案 內容會跟原本檔案同步，使用ln -s 指過去一樣可以。Symbolic Link 功能類似windows的捷徑

- ### 啟用rewite模組
```
sudo a2enmod rewrite
```
成功後一樣在 /etc/apache2/mods-enabled 會看到連結

- ### 重啟apache
```
sudo service apache2 restart
```

- ### 權限問題
```
sudo chmon -R www-data:www-data /var/www/apache/laravel_test
sudo chmod -R 775 /var/www/apache/laravel_test/storage
```