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?

More than 1 year has passed since last update.

Laravel (ubuntu&Centos8)バーチャルホスト

0
Last updated at Posted at 2023-03-11

composer

sudo apt-get install curl
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
which composer
source ~/.bashrc

Laravel

composer create-project --prefer-dist laravel/laravel Laravelapp
cd Laravelapp
composer require "laravelcollective/html"
composer require laravel/jetstream
php artisan jetstream:install livewire
npm install && npm run dev

Laravel VirtualHost(apache)ubuntu

git clone https://github.com/yuukisfurue/LaravelBoard-redis
sudo mv LaravelBoard-redis /var/www/LaravelBoard-redis
以下、Laravelのディレクトリの所有権を設定致します。
※注意sqliteの所有権はこのようにしてしまうと全世界解放なので本番環境で行うのは辞めましょう。
sudo chgrp -R www-data /var/www/LaravelBoard-redis
sudo chmod -R 775 /var/www/LaravelBoard-redis/storage
cd /var/www/LaravelBoard-redis
vi .env
※ここで作成していた.envを挿入
その後以下のコマンドを入力
php artisan migrate
npm install && npm run dev

sudo chmod -R 775 database
sudo chmod +x database
sudo chgrp -R www-data database
sudo chmod -R 777 storage
sudo chmod -R 777 bootstrap/cache
sudo chmod 777 bootstrap/cache -R
cd database
sudo chmod 777 database.sqlite
sudo chmod a=rwx,u=rwx,g=rwx,o=rwx database.sqlite
以下、バーチャルホストの設定。
cd /etc/apache2/sites-available

sudo vi laravel.conf

<VirtualHost *:80>
    ServerName  ドメイン or ip
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/LaravelBoard-redis/public
    <Directory /var/www/LaravelBoard-redis/>
        AllowOverride All
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

下記も追加でapache2の設定をお願い致します


sudo a2dissite 000-default.conf
sudo a2ensite laravel.conf
sudo a2enmod rewrite
sudo service apache2 restart

Laravel VirtualHost(nginx)ubuntu
sudo vi /etc/nginx/sites-available/default

server{
        server_name www.example.com;
        root        /var/www/html/LaravelBoard-redis/public;
        index       index.php;

        charset utf-8;
        gzip on;
        gzip_types text/css application/javascript text/javascript application/x-javascript  image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php {
                include fastcgi.conf;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        }
        location ~ /\.ht {
                deny all;
        }
}

:wq!
nginxの再起動

sudo nginx -t
sudo systemctl restart nginx
sudo rm /etc/nginx/sites-enabled/default

その後、IPかドメインで画面が表示されます。


Laravel VirtualHost(apache)Centos7.8

git clone https://github.com/yuukisfurue/LaravelBoard-redis
Centos7#curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
Centos7#sudo yum install nodejs -y

sudo mv LaravelBoard-redis /var/www/LaravelBoard-redis
sudo chmod -R 775 /var/www/LaravelBoard-redis/storage
sudo chown -R apache.apache /var/www/LaravelBoard-redis
cd /var/www/LaravelBoard-redis
vi .env

※ここで作成していた.envを挿入
その後以下のコマンドを入力
php artisan migrate
npm install && npm run dev

sudo chmod -R 775 database
sudo chmod +x database
sudo chmod -R 777 storage
sudo chmod 777 bootstrap/cache -R
sudo chmod -R 777 bootstrap/cache
cd /etc/httpd/conf.d

sudo vi laravel.conf

<VirtualHost *:80>
    ServerName  ドメイン or ip
    DocumentRoot /var/www/LaravelBoard-redis/public
    <Directory /var/www/LaravelBoard-redis/>
        AllowOverride All
    </Directory>
</VirtualHost>

sudo systemctl restart httpd.service

ひとまずこれで画面は見えるようになります。
自分の場合はデフォルトでログイン画面に推移できるような画面にしております。
以上です。

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?