Laravel Deployment on Ec2

You gotta have composer installed

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

cd /var/www/html/website-directory
// make vendor folder
sudo mkdir vendor
// change permissions
sudo chmod -R 755 vendor/
// change the entire directory's group 
sudo chown -R ec2-user:apache *
sudo chmod -R ug+rwx storage bootstrap/cache
// install dependencies
composer install

Create your .env file

cp .env.example .env
php artisan key:generate

If your app requires a DB create the db (whatever steps you’d take to do that – in mysql you just create the empty db)
Then run artisan migrate

php artisan migrate

This builds your db.

Your vhost should look like this – be sure it is pointed to public directory

<VirtualHost *:80>
    DocumentRoot "/var/www/html/website-directory/public"
    ServerName website.com
    <Directory "/var/www/html/website-directory/public">
    </Directory>
</VirtualHost>

If the site won’t work and you are getting a server 500 error but can’t seem to find out why, turn on Debugging in the .env file

APP_DEBUG=true

This can help point you in the right direction for locating the issue

You may also like...

Leave a Reply

Your email address will not be published.