Here’s a step-by-step example of uploading a Laravel project to a cloud hosting platform, specifically using DigitalOcean as the cloud hosting provider:
- Sign Up for DigitalOcean:
- Go to the DigitalOcean website (https://www.digitalocean.com/) and sign up for an account.
- Once signed up, log in to the DigitalOcean control panel.
- Create a Droplet (Virtual Private Server):
- Click on the “Create” button and select “Droplets” from the dropdown menu.
- Choose a distribution (e.g., Ubuntu) and plan for your droplet. Select the amount of CPU, memory, and disk space according to your requirements.
- Choose a datacenter region closest to your target audience.
- Add any additional options you may need (e.g., backups, monitoring).
- Click “Create Droplet” to create your virtual server.
- Connect to Your Droplet:
- Once your droplet is created, you’ll receive an email with the root password or SSH key (if you chose SSH key authentication).
- Use an SSH client (e.g., PuTTY on Windows, Terminal on macOS/Linux) to connect to your droplet. Use the provided IP address and login credentials.
- If you’re using SSH key authentication, make sure to set the correct permissions for your private key file (
chmod 400 your-private-key.pem
) and connect using the SSH key (ssh -i your-private-key.pem root@your-droplet-ip
).
- Install Required Software:
- Update the package index on your droplet:
apt update
. - Install necessary software packages:
apt install apache2 php mysql-server php-mysql unzip
.
- Update the package index on your droplet:
- Transfer Your Laravel Project:
- Navigate to your Laravel project directory on your local machine.
- Compress your Laravel project directory into a zip file.
- Use SCP to transfer the zip file to your droplet:typescript
scp your-project.zip root@your-droplet-ip:/var/www/html
- SSH into your droplet and navigate to the
/var/www/html
directory. - Unzip your project file:python
unzip your-project.zip
- Configure Laravel Environment:
- Rename the
.env.example
file to.env
:mv .env.example .env
. - Open the
.env
file and update the database connection settings (DB_HOST
,DB_DATABASE
,DB_USERNAME
,DB_PASSWORD
) with your database credentials. - Generate a new application key:
php artisan key:generate
.
- Rename the
- Set File Permissions:
- Set the correct permissions for the Laravel project directories:bash
chown -R www-data:www-data /var/www/html chmod -R 755 /var/www/html/storage
- Configure Apache:
- Create a new virtual host configuration file for your Laravel project:bash
nano /etc/apache2/sites-available/your-domain.conf
- Add the following configuration:php
<VirtualHost *:80> ServerName your-domain.com DocumentRoot /var/www/html/public <Directory /var/www/html/public> AllowOverride All </Directory> </VirtualHost>
- Enable the new virtual host:
a2ensite your-domain.conf
. - Reload Apache for the changes to take effect:
systemctl reload apache2
.
- Create a new virtual host configuration file for your Laravel project:bash
- Set Up Database:
- Log in to MySQL:
mysql -u root -p
. - Create a new database for your Laravel project:
CREATE DATABASE your_database;
. - Create a new MySQL user and grant privileges to the database:sql
CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON your_database.* TO 'your_username'@'localhost'; FLUSH PRIVILEGES;
- Log in to MySQL:
- Test Your Application:
- Open your web browser and navigate to your domain (e.g.,
http://your-domain.com
). You should see your Laravel application up and running.
- Open your web browser and navigate to your domain (e.g.,
- Set Up SSL Certificate (Optional):
- Follow DigitalOcean’s documentation or use Let’s Encrypt to set up an SSL certificate for your domain to enable HTTPS.
- Monitor and Maintain:
- Regularly monitor your server’s performance and security.
- Perform regular backups of your data to prevent data loss.
That’s it! Your Laravel project is now uploaded and running on a DigitalOcean droplet. You can further customize your server configuration and Laravel application according to your requirements.
Leave a Reply