Ubuntu 20.04 安裝 Laravel

Step1. install Apacher Server
sudo apt install apache2

執行apache2伺服器

sudo sytemctl start apache2

開機啟動apache2

sudo systemctl enable apache2 

測試apach2執行情形

sudo systemctl status apache2
Step2. Installing PHP and its additional plugins

安裝PHP

sudo apt install php libapache2-mod-php php-mbstring php-cli php-bcmath php-json php-xml php-zip php-pdo php-common php-tokenizer php-mysql

測試安裝情形

php -v
Step3. creating a database

安裝MariaDB伺服器

sudo apt install mariadb-server

執行Mariadb

sudo mysql -u root -p

執行SQL語法

CREATE DATABASE laravel_db;
CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'secretpassword';
GRANT ALL ON laravel_db.* TO 'laravel_user'@'localhost';
FLUSH PRIVILEGES;
QUIT;
Step 4: Install Composer

執行”連線到安裝網站,使用PHP安裝”

$ curl -sS https://getcomposer.org/installer | php

安裝完後設定

sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
composer --version
Step 5: Install Laravel 8 on Ubuntu
cd /var/www/html
sudo composer create-project laravel/laravel laravelapp
sudo chown -R www-data:www-data /var/www/html/laravelapp
sudo chmod -R 775 /var/www/html/laravelapp/storage
cd laravelapp
php artisan
Step 6: Configure Apache to serve Laravel

 建立laravel.conf檔案

<VirtualHost *:80>
ServerName example.com
ServerAdmin admin@example.com
DocumentRoot /var/www/html/laravelapp/public
<Directory /var/www/html/laravelapp>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

執行下列兩個指令,讓他們進入Apache rewiter 模組

sudo a2ensite laravel.conf
$ sudo a2enmod rewrite

重新啟動apache2

sudo systemctl restart apache2
Step 7: Run Laravel in a web browser

網站在 /var/www/html/laravelapp/public

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料