Here are steps to install Laravel into your Ubuntu.
-
Update Package Lists: Ensure your package lists are up-to-date by running:
sudo apt update -
Install PHP and Required Extensions: Laravel requires PHP and several extensions. Install them using the following command:
sudo apt install php php-cli php-mbstring php-xml php-zip php-json php-mysql php-curl -
Install Composer: Composer is a dependency manager for PHP, required for Laravel. Run the following commands to download and install Composer:
sudo apt install curl php-cli php-mbstring unzip
cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php –install-dir=/usr/local/bin –filename=composer -
Install Node.js and npm: Laravel Mix requires Node.js and npm. You can install them using the following commands:
sudo apt install nodejs npm -
Install Laravel Installer: Laravel provides a convenient installer for setting up new projects. Install it globally using Composer:
composer global require laravel/installer -
Add Composer Global Bin Directory to PATH: Ensure that Composer’s global bin directory is in your system’s PATH so that you can run the Laravel executable globally:
echo ‘export PATH=”$HOME/.config/composer/vendor/bin:$PATH”‘ >> ~/.bashrc source ~/.bashrc -
Create a New Laravel Project: Once Laravel Installer is installed, you can create a new Laravel project using the following command:
laravel new my-projectReplace my-project with your preferred project name.
-
Set Permissions (Optional): If you encounter any permission issues, especially when writing to storage or bootstrap/cache directories, you might need to adjust the permissions. For example:
sudo chown -R www-data:www-data /path/to/your/laravel/directory sudo chmod -R 775 /path/to/your/laravel/directory/storage sudo chmod -R 775 /path/to/your/laravel/directory/bootstrap/cache -
Replace/path/to/your/laravel/directory with the actual path to your Laravel project directory.
-
For creating file use:
sudo touch /etc/apache2/sites-available/devlaravel.conf
Now open the file :
sudo nano /etc/apache2/sites-available/devlaravel.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName www.devlaravel.com
DocumentRoot /var/www/html/laravel/
</VirtualHost> -
Now need to run few more commands.
sudo a2ensite devlaravel.conf
sudo a2enmod rewrite
sudo service apache2 status -
After that add your domain in host file.
Folder Path : /etc/host
127.0.0.1 www.devlaravel.com