How to Point Domain and Host Laravel Project on Apache Web Server VPS Hosting
Table Of Content
How to Point Domain and Host Laravel Project on Apache Web Server VPS Hosting
Step 1: Configure Domain Settings
-
Login to Your Domain Provider Website:
- Access your domain provider’s website and log in to your account.
-
Navigate to Manage DNS:
- Find and navigate to the DNS management section.
-
Add DNS Records:
-
Add the following DNS records to point your domain to your VPS:
Type Host/Name Value A @ Your Remote Server IP A www Your Remote Server IP AAAA @ Your Remote Server IPv6 AAAA www Your Remote Server IPv6
-
Step 2: Copy Laravel Project to Remote Server
-
Copy Project Zip File to Remote Server:
-
On your local Windows machine, zip your Laravel project folder.
-
Use SCP to copy the zip file to your remote server:
scp -P Port_number Source_File_Path Destination_Path
Example:
scp -P 22 osmsProject.zip root@216.32.44.12:/var/www
-
-
Access Remote Server via SSH:
-
SSH into your remote server:
ssh -p PORT USERNAME@HOSTIP
Example:
ssh -p 22 root@216.32.44.12
-
-
Unzip Project:
-
Navigate to the destination path where you copied the zip file.
-
Unzip the copied zip file:
unzip zip_file_name
Example:
unzip osmsProject.zip
-
Step 3: Verify Software Installation and Apache Configuration
-
Verify Required Software:
-
Check if all necessary software is installed:
apache2 -v mysql php -v composer -v
-
-
Verify Apache2 is Active:
-
Check the status of Apache:
service apache2 status
-
-
Verify Web Server Ports and Firewall:
-
Check the status of ports and firewall rules:
ufw status verbose
-
Step 4: Configure Virtual Host for Laravel Project
-
Create Virtual Host File:
-
Create a virtual host configuration file for your domain:
nano /etc/apache2/sites-available/your_domain.conf
-
Add necessary configuration details for Apache.
-
-
Enable Virtual Host and Mod Rewrite:
-
Enable the virtual host:
a2ensite your_domain.conf
-
Enable the Apache mod_rewrite module:
a2enmod rewrite
-
-
Restart Apache:
-
Restart Apache to apply changes:
service apache2 restart
-
Step 5: Configure Laravel Environment and Permissions
-
Generate Application Key:
-
Generate a unique application key for Laravel:
php artisan key:generate
-
-
Install Dependencies and Set Permissions:
-
Install Composer dependencies and optimize autoloader:
composer install --optimize-autoloader --no-dev
-
Set appropriate permissions for storage and bootstrap/cache directories:
sudo chown -R www-data:www-data storage bootstrap/cache
-
-
Database Configuration:
- Open the
.env
file and configure the database settings.
- Open the
-
Create Database Tables:
-
Run database migrations to create tables:
php artisan migrate
-
-
Create Symbolic Link for Storage:
-
Create a symbolic link at
public/storage
pointing tostorage/app/public
:php artisan storage:link
-
Step 6: Finalize Deployment and Maintenance
-
Clear Cache and Enable Maintenance Mode:
-
Clear cache and enable maintenance mode if needed:
php artisan cache:clear php artisan config:clear php artisan route:cache # Optional php artisan config:cache # Optional php artisan view:cache # Optional php artisan down # Enable maintenance mode
-
-
Deploy Your Laravel Project:
- Your Laravel project should now be accessible via your domain. Continue to develop and maintain your project on the live server.
By following these steps, you can successfully host your Laravel project on an Apache web server using VPS hosting. Remember to keep your dependencies up to date and ensure proper security measures are in place for your production environment.