amazon-web-servicesdebianapache2

AWS Debian apache2 web install


So i want to create an apache2 webserver on debian using aws. I'm in needed to what to write so with the codes to make me see everything in order.

I tried installing apache2 and succeeded, but i do not know how to make the self signed certificate, but using the codes from the debian wiki didn't work.


Solution

  • You can set up an Apache2 web server on AWS Debian with SSL.

    1. First, update your system and install Apache2:
    sudo apt update
    sudo apt upgrade -y
    sudo apt install apache2 -y
    
    1. Enable required Apache modules:
    sudo a2enmod ssl
    sudo a2enmod rewrite
    
    1. Install SSL tools:
    sudo apt install openssl -y
    
    1. Create a directory for SSL certificates:
    sudo mkdir -p /etc/apache2/ssl
    cd /etc/apache2/ssl
    
    1. Generate a self-signed SSL certificate (you'll be prompted to enter information):
    sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
    -keyout /etc/apache2/ssl/apache.key \
    -out /etc/apache2/ssl/apache.crt
    
    1. Create a new Apache configuration file:
    sudo nano /etc/apache2/sites-available/default-ssl.conf
    
    1. Add this configuration (replace your-domain with your domain or IP):
    <IfModule mod_ssl.c>
        <VirtualHost *:443>
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html
            
            SSLEngine on
            SSLCertificateFile /etc/apache2/ssl/apache.crt
            SSLCertificateKeyFile /etc/apache2/ssl/apache.key
            
            <Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
            </Directory>
            
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
        </VirtualHost>
    </IfModule>
    
    1. Enable the SSL site:
    sudo a2ensite default-ssl.conf
    
    1. Create a redirect from HTTP to HTTPS (optional):
    sudo nano /etc/apache2/sites-available/000-default.conf
    

    Add this configuration:

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        Redirect permanent / https://your-domain-or-ip/
    </VirtualHost>
    
    1. Set proper permissions for web directory:
    sudo chown -R www-data:www-data /var/www/html
    sudo chmod -R 755 /var/www/html
    
    1. Test Apache configuration:
    sudo apache2ctl configtest
    
    1. Restart Apache:
    sudo systemctl restart apache2
    
    1. Check Apache status:
    sudo systemctl status apache2