Add site AWS EC2

User
add new site aws ubuntu ec2
Assistant
To add a new site to your AWS EC2 instance running Ubuntu, you'll need to follow these general steps:

### 1. **SSH into your EC2 Instance**
– Open your terminal (or command prompt) and SSH into your EC2 instance.
– Use the following command:

ssh -i /path/to/your/key.pem ubuntu@ec2-XX-XX-XX-XX.compute-1.amazonaws.com

### 2. **Install Required Software**
– **Apache/Nginx**: You can choose between Apache or Nginx as your web server. Here, we’ll use Apache as an example.
– **PHP** (if applicable): Install PHP if you are running a PHP-based site like Laravel, WordPress, etc.
– **MySQL/MariaDB** (if applicable): If your site requires a database.

To install Apache and PHP, run:

sudo apt update
   sudo apt install apache2 php libapache2-mod-php php-mysql

For database installation (if needed):

sudo apt install mysql-server
   sudo systemctl start mysql
   sudo systemctl enable mysql

### 3. **Set Up a New Directory for Your Site**
– Create a directory for your new site in `/var/www/`:

sudo mkdir /var/www/newsite.com

– Set the correct permissions:

sudo chown -R www-data:www-data /var/www/newsite.com

### 4. **Create a Virtual Host for Your Site (Apache Example)**
– Create a new virtual host configuration file:

sudo nano /etc/apache2/sites-available/newsite.com.conf

– Add the following configuration (replace `newsite.com` with your domain or desired site name):

<VirtualHost *:80>
       ServerAdmin webmaster@newsite.com
       ServerName newsite.com
       DocumentRoot /var/www/newsite.com
       ErrorLog ${APACHE_LOG_DIR}/error.log
       CustomLog ${APACHE_LOG_DIR}/access.log combined
   </VirtualHost>

– Enable the site and reload Apache:

sudo a2ensite newsite.com.conf
   sudo systemctl reload apache2

### 5. **Set Up Your Domain**
– Point your domain (e.g., `newsite.com`) to your EC2 instance's public IP address by updating the A record in your domain's DNS settings.

### 6. **Upload Your Site Files**
– You can use SCP, SFTP, or Git to upload your website files to `/var/www/newsite.com`.
Example using SCP:

scp -i /path/to/your/key.pem /path/to/your/site-files/* ubuntu@ec2-XX-XX-XX-XX.compute-1.amazonaws.com:/var/www/newsite.com/

### 7. **Test the Site**
– Open a web browser and navigate to `http://newsite.com` (or your EC2 public IP if you don't have a domain set up yet).
– You should see your new site loading. If you have any issues, check Apache's logs for errors:

sudo tail -f /var/log/apache2/error.log

If you're using Nginx or another stack, let me know, and I can provide instructions specific to that setup!

Leave a Comment

Your email address will not be published. Required fields are marked *