I know you’re fed up watching tutorials on how to host the Laravel app to digital ocean droplets. I had been there too. Thankfully I came up with a solution and want to share it with you all. It is the most straightforward guide available on the internet. Additionally, I will also provide you with a time-saving tip to manage the maximum_upload_size error while hosting Laravel app into digital ocean droplets.
Step 1: Initial Server Setup
- Create a Droplet:
Launch a new Ubuntu droplet from your chosen cloud provider i.e. Digital Ocean. - SSH into the Droplet:
Use SSH to connect to your droplet. You’ll need the IP address or hostname of the droplet and the SSH key you associated with it.
ssh your_username@your_droplet_ip
- Update Packages:
Update your package repositories and upgrade the existing packages.
sudo apt update
sudo apt upgrade
Step 2: Install LAMP Stack
- Install Apache:
sudo apt install apache2
- Install MySQL:
sudo apt install mysql-server
sudo mysql_secure_installation
- Install PHP:
sudo apt install php libapache2-mod-php php-mysql php-cli php-curl php-json php-mbstring php-zip php-gd php-xml php-pear
Step 3: Install Composer
- Download Composer:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"
- Check Composer Installation:
composer --version
Step 4: Configure Apache for Laravel
- Enable Rewrite Module:
sudo a2enmod rewrite
sudo systemctl restart apache2
- Create a Virtual Host: Create a new Apache configuration file for your Laravel project or you can use the 000-default.conf which is already available there.
sudo nano /etc/apache2/sites-available/your-project.conf
Replace your-project
with a suitable name.
Add the following content to the file:
<VirtualHost *:80>
ServerName your-domain.com
DocumentRoot /var/www/your-project-folder-name/public
<Directory /var/www/your-project-folder-name>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save the file and exit the text editor.
- Enable the Virtual Host:
sudo a2ensite your-project.conf
use this if you created your new config file
sudo a2enmod rewrite
Use this if you choose to update the 000-default.conf
sudo systemctl restart apache2
Step 5: Install Laravel
- Navigate to Web Directory:
cd /var/www/
- Install Laravel via Composer or clone your Laravel project to this path:
composer create-project --prefer-dist laravel/laravel your-project
- Adjust Permissions:
sudo chown -R www-data:www-data /var/www/your-project/storage
sudo chmod -R 775 /var/www/your-project/storage
Step 6: Configure Laravel Environment
- Create a .env File:
cd /var/www/your-project
cp .env.example .env
- Generate Laravel Application Key:
php artisan key:generate
Step 7: Access Your Laravel Project
You should now be able to access your Laravel project by visiting your domain or IP address in a web browser.
Remember that this is an essential setup guide, and depending on your project’s requirements, you might need to install additional software or configure specific services. Also, consider enabling HTTPS with SSL certificates for better security.
Additional note
Your Laravel app will only let you upload files up to 2MB this thing just wasted my day what you can simply do is go to cd /etc/php//8.1/apache2/ or whatever the version, find the apache2 folder that has php.ini file in it; after that change, the following values according to your preferences ( memory_limit = 500M post_max_size = 500M upload_max_filesize = 500M ) and save it, and restart the apache server with
sudo systemctl restart apache2 and there you go enjoy your deployment.