INSTALL LARAVEL ON UBUNTU 18.04

First install and setup Apache, PHP ( > or = 7.3 or 8), Mysql/Mariadb. PHP extension ‘mbstring’ should be enabled on the server.

Then install composer:

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

mv composer.phar /usr/local/bin/composer

chmod +x /usr/local/bin/composer

Now we can install Laravel:

cd /var/www

git clone https://github.com/laravel/laravel.git

cd laravel

Now we can install dependency packages of laravel using the command ‘composer install’

Important Note: Try to avoid running the install command as root user. For more details read: https://getcomposer.org/root

I am running this command as sudo user ‘ubuntu’.

composer install

You may get into some ‘memory’ issues while running this command.

Try running the below command as a workaround:

php -d memory_limit=-1 /usr/local/bin/composer install

If the issue persists, your RAM is exhausted.

Try creating a swap file:

https://linuxize.com/post/how-to-add-swap-space-on-ubuntu-18-04

After successful installation of dependencies, give the proper permissions to the file:

chown -R www-data:www-data /var/www/laravel

Set 644 on files:

find /var/www/laravel/ -type f -exec chmod 644 {} \;

Set 755 on directories:

find /var/www/laravel/ -type d -exec chmod 755 {} \;

Give full permission on storage directory:

chmod -R 777 /var/www/laravel/storage

Setup Encryption Key:

mv .env.example .env

Now generate base64 random number encryption key, using the below command:

php artisan key:generate

Edit the .env configuration file and update the APP_URL:

Create Database for Laravel:

CREATE DATABASE lara;

GRANT ALL ON lara.* to ‘lara’@’localhost’ IDENTIFIED BY ‘passwd’;

FLUSH PRIVILEGES;

Again edit the .env configuration file and update the db details:

Apache Virtualhost:

Disable the default virtualhost:

vim /etc/apache2/sites-enabled/lara.conf

<VirtualHost *:80>

     ServerName lara.spotfixcrew.com

     DocumentRoot /var/www/laravel/public

     <Directory /var/www/laravel>

             AllowOverride All

     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/error.log

     CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Restart Apache:

Systemctl restart apache2

That’s it! Now we can access the Laravel installation from browser:

Leave a Reply

Your email address will not be published. Required fields are marked *