To set up an Apache2 virtual host with Laravel on Ubuntu, follow these steps:
1. Install Apache2: Use 'sudo apt update' and 'sudo apt install apache2' commands.
2. Install PHP and Required Extensions: Use 'sudo apt install php libapache2-mod-php php-mysql php-xml php-mbstring php-curl' command.
3. Configure Apache for Virtual Hosts: Enable 'mod_rewrite' module and restart Apache with 'sudo a2enmod rewrite' and 'sudo systemctl restart apache2' commands.
4. Set Up Laravel Directory: Move your Laravel project to '/var/www/laravel' directory, set correct permissions with 'sudo chown -R www-data:www-data /var/www/laravel' and 'sudo chmod -R 755 /var/www/laravel' commands.
5. Create Virtual Host Configuration: Create a virtual host configuration file with 'sudo nano /etc/apache2/sites-available/laravel.conf' and add the necessary content.
6. Enable the Virtual Host: Enable the new virtual host with 'sudo a2ensite laravel.conf' command and disable the default site if necessary with 'sudo a2dissite 000-default.conf' command.
7. Update /etc/hosts: Edit the /etc/hosts file and add the domain mapping.