In this tutorial, you will learn how to install Apache 2.4 on Amazon EC2 Ubuntu 18.04.
If you are planning to setup a dedicated web hosting server for your web application site or WordPress website, this guide will show you how to properly install your Apache2 web server.
Apache is an open-source web server software most widely used in many IT developers and community around the world. Apache has a wide range of feature integrations for extension and modules.
What will you do
- Installing Apache2 Web Server
- Testing Apache2 Web Server
- Manage Apache2 Commands
- Manage Apache2 Logs
- Apache2 Configuration Files
Requirements
- AWS Account. Create your own AWS Account
- Ubuntu 18.04. Learn to deploy EC2 Ubuntu instance on AWS Console
- A user with sudo privilege command.
To get started, this guide shows you through step process on how to install Apache2 web server on Ubuntu 18.04 using Amazon EC2 instance.
Step 1. Installing Apache2 Web Server
First, SSH remote into your EC2 instance using your great Linux terminal console and add the Apache2 system packages below, type command:
sudo add-apt-repository ppa:ondrej/apache2
Then press Enter
on the screen to continue.
Update the packages currently installed on the system, type command:
sudo apt update
Now install Apache2 Web Server, type command:
sudo apt-get install apache2 -y
After installation completed, verify the Apache2 version.
sudo apache2ctl -v
The output looks like this:
Server version: Apache/2.4.41 (Ubuntu) Server built: 2019-04-02T20:30:26
Step 2. Testing Apache2 Web Server
After the installation process, the Apache2 service will runs automatically. To make sure the Apache2 is active (Running
) online, type command:
sudo service apache2 status
The output looks like this:
ubuntu@ip-172-XX-XX-XX:~$ sudo service apache2 status ● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: Active: active (running) since Tue 2019-04-30 05:44:14 UTC; 19min ago Docs: https://httpd.apache.org/docs/2.4/ Main PID: 14045 (apache2) Tasks: 55 (limit: 1152) CGroup: /system.slice/apache2.service ├─14045 /usr/sbin/apache2 -k start ├─14047 /usr/sbin/apache2 -k start └─14048 /usr/sbin/apache2 -k start Apr 30 05:44:14 ip-172-31-58-56 systemd[1]: Starting The Apache HTTP Server… Apr 30 05:44:14 ip-172-31-58-56 systemd[1]: Started The Apache HTTP Server.
We assume that Apache2 is already install and active. Next, You need to verify the default Apache2 landing page in the web browser if the Apache2 web server is working properly.
Note: Make sure HTTP Port 80 is publicly allowed from the incoming traffic in security group on your EC2 instance.
To get the public IP address on your server, type command:
curl http://169.254.169.254/latest/meta-data/public-ipv4
The output looks like this:
52.XX.XX.XX
Open your web browser and paste your public IP address.
http://52.XX.XX.XX
The output looks like this:
Step 3. Apache2 Commands
You can manage your Apache2 web server common commands:
# Start Apache service sudo service apache2 start # Stop Apache service sudo service apache2 stop # Restart Apache service sudo service apache2 restart # Reload Apache service without dropping connections sudo service apache2 reload # Enable Apache service on startup boot sudo systemctl enable apache2 # Disable Apache service sudo systemctl disable apache2
Step 4. Manage Apache2 Logs
If you want to display the real-time request of Apache access logs and monitor the realtime log request, type command:
sudo tail -f /var/log/apache2/access.log
If you want to check your Apache2 error logs, type command:
sudo tail -f /var/log/apache2/error.log
You can limit the number of lines to display from your logs (e.g 100), use the command -n option.
You can limit the number of lines to display from your Apache logs request and using the command -n option.
sudo tail -n 100 /var/log/apache2/access.log
Note: The logs view starts at the end of the line and is printed to the standard output.
Step 5. Apache2 Configuration Files
If you want to know your default Apache2 configuration file, use the following commands:
# This is the main Apache server configuration file. sudo vim /etc/apache2/apache2.conf # If you just change the port or add more ports here sudo vim /etc/apache2/port.conf # Default Apache virtualhost sudo vim /etc/apache2/site-available/default.conf
To validate your Apache2 configuration, type command:
sudo apache2ctl configtest
Please read on this guide for more information of Apache2 directives.
See: https://httpd.apache.org/docs/2.4/mod/directives.html
That’s all.
If you are planning to install a firewall to secure your (web applications or WordPress website from Bad bots attack, DDoS prevention, SQL injection, Scripting attacks. This guide will be useful:
See: Learn how to install Modsecurity for Apache2 on Ubuntu server
I hope this tutorial helped you and feel free to comment section below for more suggestions.
Tags: apache2, aws, ec2, linux, ubuntu, ubuntu 18.04