Host Multiple Sites on a Single Amazon EC2 Instance

How you should run multiple sites with a single ec2 instance which has a single IP.

In our case, we have taken WordPress installation on a single IP.

Well, the first question comes what is the need?

Let's say you are running multiple static websites which work is to display only information or less responsive websites, in all those cases you don't have to set up or buy a different server for each website, you can connect and manage all the websites form a single IP and a single console window.

This will help the startups or the testers that do not understand what and how the user will respond.

Thus they will create a small, informative website and see how their customer behave.

Prerequisite knowledge:-

You don't need much knowledge just the basics command of Linux so we can do the installations.

How does It work?

Here I am going to show you how you can run two websites from a single IP. Now you have different WordPress admin panels for different websites you can configure each of accordingly, the best possible way I suggest that you can assign different domains name initially for free. 

Here is the code of the Linux terminal.

************************************************************** ************************************************************** 1. Create AWS EC2 instance ************************************************************** #Connect to console using puTTy 2. sudo apt update 3. sudo apt-get update ************************************************************** #Install LAMP 4. sudo apt-get install apache2 5. sudo apt-get install mysql-server 6. sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql 7. sudo service apache2 start 8. cd /var/www/html 9. sudo nano /etc/apache2/sites-available/000-default.conf 10. sudo systemctl restart apache2 11. sudo nano info.php echo "this is a test"; ************************************************************** #Make different dir for different WordPress 8. sudo mkdir /site1/public -p 9. sudo mkdir /site2/public -p ************************************************************** #Copy and configure 10. sudo cp html/info.php site1/index.php 11. sudo cp html/info.php site2/index.php 12. sudo cp /etc/apache2/sites-available/000default.conf /etc/apache2/sites-available/site1.conf 13. sudo nano /etc/apache2/sites-available/site1.conf add ServerName and ServerAlias and Directory 14. Repeat step 13 for site 2 15. sudo a2ensite site1.conf 16. sudo a2ensite site2.conf 17. sudo systemctl reload apache2 ************************************************************** #Download WordPress 18 sudo wget 19 sudo unzip -d site1/public/ 20 sudo unzip -d site2/public/ 21 remove index.php file in public for both site1 and site2 rm index.php ************************************************************** #Move WP file to the current directory for both site1 and site2 22. sudo mv wordpress/* ./ ************************************************************** #CREATE MYSQL DATABASE in var/www/ 23. mysql -u root -p 24. >> CREATE DATABASE site1; 25. >> GRANT ALL PRIVILEGES ON site1.* TO 'site1'@'localhost' IDENTIFIED BY 'site1123'; 26. REPEAT STEPS 24-25 for site2 ************************************************************** #Change permission for public dir #4->Read 2->Write 1->Execute #7=4+2+1 #5=4+1 #6=4+2 #7 5 5 #(user)(group)(public) 27.chmod 755 public -R 28. chown www-data public -R 29. Repeat 27-28 for site2 ************************************************************** RELOAD SITE1 and SITE2 and install WP ************************************************************** # In the public folder of both websites 30.sudo nano .htaccess 31. sudo nano /etc/apache2/sites-available/site1.conf Options Indexes FollowSymLinks AllowOverride All Require all granted

32. Repeat both steps for site1 and site2

33. sudo systemctl reload apache2


New to AWS, we got you covered, click here to know that how you can launch an ec2 , machine.

Here the comments are shown as#

If you have any problem comment down below

If you like this post it will your great support to share this on social media...


Recent Posts

See All