0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ubuntu環境でのLaravelセットアップ

Last updated at Posted at 2025-05-20

必要なものをインストール

sudo apt update && sudo apt upgrade -y
sudo apt install apache2 php php-cli php-mbstring php-xml php-bcmath php-curl php-mysql php-zip unzip curl git -y

Composerも

cd ~
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

MySQLも

sudo apt install mysql-server -y
sudo mysql_secure_installation

Laravelをclone

アプリ名をlaravel-appとする

git clone https://github.com/***/***.git
sudo chown -R $USER:www-data laravel-app

MySQLの設定と.envの設定

sudo mysql -u root -p

データベース名をlaravel_db、ユーザー名をlaravel_user、パスワードをpasswordとする

CREATE DATABASE laravel_db;
CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON laravel_db.* TO 'laravel_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

.envの雛形をコピー

cd laravel-app
cp .env.example .env
vim .env

以下を編集

DB_DATABASE=laravel_db
DB_USERNAME=laravel_user
DB_PASSWORD=password

Laravelの準備

必要なものをインストール

composer install
sudo apt install nodejs npm

アプリケーションキーの作成

php artisan key:generate

できたらmigration

php artisan migrate

依存をインストール

npm install

本番環境用のViteビルドを実行

npm run build

パーミッションを変更

sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache

Apache2の設定

.htaccessを有効にするため、mod_rewriteを有効にする

sudo a2enmod rewrite

Virtualhostの設定

sudo vim /etc/apache2/sites-available/laravel-app.conf

以下のように記載

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/laravel-app/public

    <Directory /var/www/laravel-app/public>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/laravel-error.log
    CustomLog ${APACHE_LOG_DIR}/laravel-access.log combined
</VirtualHost>
# virtualhostを有効化
sudo a2ensite laravel-app.conf

#デフォルト設定を無効化
sudo a2dissite 000-default.conf

Certbotのインストール

sudo apt install certbot python3-certbot-apache

Let's Encrypt の証明書を取得して Apache に設定

sudo certbot --apache -d your_domain.com

最後にapacheの再起動

sudo systemctl restart apache2

そうすればhttps://yourdomain.comにアクセスできる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?