"Install and configure Apache2 server with reverse proxy and tomcat application server in ubuntu"
- Anu Solanki

- Sep 20, 2023
- 2 min read

[1] Install and configure Apache2
step 1:
Launch AWS EC2 instance and connect through the SSH in your terminal !
step 2:
Update your Ec2 instance with this command
sudo apt-get update step 3:
Install apache2 on ubuntu
sudo apt-get install apache2enable and start the apache2 service
sudo systemctl enable apache2 sudo systemctl start apache2check the status of apache2 service
sudo systemctl status apache2Adjusting Firewall
sudo ufw app listsudo ufw allow 'Apache'sudo ufw status[2] Install and configure Tomcat 10
Step 1: Installing Tomcat
Create a separate user and set appropriate permissions for it:
sudo useradd -m -d /opt/tomcat -U -s /bin/false tomcatUpdate and upgrade the package list:
sudo apt update
sudo apt upgradeInstall the default JDK (Java Development Kit):
sudo apt install default-jdkNavigate to the temporary directory:
cd /tmpDownload the Apache Tomcat archive using wget:
note: in some case this link is not work then download from this link:
wget https://dlcdn.apache.org/tomcat/tomcat- 10/v10.1.13/bin/apache-tomcat-10.1.13.tar.gzExtract the downloaded archive to the /opt/tomcat directory:
sudo tar xzvf apache-tomcat-10*tar.gz -C /opt/tomcat --strip-components=1Set ownership and execute permissions for the Tomcat installation directory:
sudo chown -R tomcat:tomcat /opt/tomcat/
sudo chmod -R u+x /opt/tomcat/binStep 2: Configure Admin Users
Edit the tomcat-users.xml file to define Tomcat users:
sudo nano /opt/tomcat/conf/tomcat-users.xmlAdd the following lines within the <tomcat-users> section:
<role rolename="manager-gui" /><user username="manager" password="manager_password" roles="manager-gui" />
<role rolename="admin-gui" /><user username="admin" password="admin_password" roles="manager-gui,admin-gui" />Remove the restriction for the Manager page by editing its configuration file:
sudo nano /opt/tomcat/webapps/manager/META-INF/context.xmlComment out the <Valve> definition within the <Context> tag, like this:
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->Repeat the same process for the Host Manager:
sudo nano /opt/tomcat/webapps/host-manager/META-INF/context.xmlStep 3: Creating a systemd Service
Find the Java location:
sudo update-java-alternatives -lCreate the tomcat.service file for systemd:
sudo nano /etc/systemd/system/tomcat.serviceAdd the following content:
[Unit]
Description=Tomcat
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.targetReload the systemd daemon to recognize the new service:
sudo systemctl daemon-reloadStart the Tomcat service and check its status:
sudo systemctl start tomcat
sudo systemctl status tomcatEnable Tomcat to start with the system:
sudo systemctl enable tomcatStep 4: Accessing the Web Interface
Allow traffic on port 8080 for Tomcat:
sudo ufw allow 8080[3] configure as a reverse proxy
Navigate to the directory /etc/apache2/sites-enabled:
cd /etc/nginx/sites-enabledOpen 000-default.conf file using the nano text editor:
nano 000-default.conf In the 000-default.conf file, insert the following configuration:
# CustomLog ${APACHE_LOG_DIR}/access.log combined
#put this two line in that file
ProxyPass / http://127.0.0.1:8080/
ServerName loaclhost
To check the apache2 configuration for any syntax errors, run the following command:
systemctl status apache2Once you've created the 000-default.conf file and confirmed that the apache2 configuration is error-free, you can proceed to reload apache2 to apply the new configuration:
sudo systemctl reload apache2This will activate the apache2 configuration changes.







Comments