<\/span><\/h2>\n\n\n\nTo install the Apache Web server execute the following command:<\/p>\n\n\n\n
sudo apt install apache2 -y<\/pre>\n\n\n\nOnce installed, start and enable the service.<\/p>\n\n\n\n
sudo systemctl enable apache2 && sudo systemctl start apache2<\/pre>\n\n\n\nCheck if the service is up and running:<\/p>\n\n\n\n
sudo systemctl status apache2<\/pre>\n\n\n\nYou should receive the following output:<\/p>\n\n\n\n
root@host:~# sudo systemctl status apache2\n\u25cf apache2.service - The Apache HTTP Server\n Loaded: loaded (\/lib\/systemd\/system\/apache2.service; enabled; vendor preset: enabled)\n Active: active (running) since Thu 2023-04-06 15:12:46 CDT; 10s ago\n Docs: https:\/\/httpd.apache.org\/docs\/2.4\/\n Main PID: 794 (apache2)\n Tasks: 7 (limit: 4571)\n Memory: 23.8M\n CPU: 16.059s\n CGroup: \/system.slice\/apache2.service\n<\/pre>\n\n\n\n<\/span>Step 3. Install Java<\/span><\/h2>\n\n\n\nTo install Java OpenJDK 11, execute the following command:<\/p>\n\n\n\n
sudo apt install openjdk-11-jdk -y<\/pre>\n\n\n\nTo check the installed Java version, execute the following command:<\/p>\n\n\n\n
java --version<\/pre>\n\n\n\nYou should receive the following output:<\/p>\n\n\n\n
root@host:~# java --version\nopenjdk 11.0.18 2023-01-17\nOpenJDK Runtime Environment (build 11.0.18+10-post-Ubuntu-0ubuntu122.04)\nOpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)\n<\/pre>\n\n\n\n<\/span>Step 4. Install Jenkins<\/span><\/h2>\n\n\n\nFirst, we will add the Jenkins repository and Key since they are not added by default in Ubuntu 22.04:<\/p>\n\n\n\n
curl -fsSL https:\/\/pkg.jenkins.io\/debian-stable\/jenkins.io-2023.key | sudo tee \\\n \/usr\/share\/keyrings\/jenkins-keyring.asc > \/dev\/null\n\necho deb [signed-by=\/usr\/share\/keyrings\/jenkins-keyring.asc] \\\n https:\/\/pkg.jenkins.io\/debian-stable binary\/ | sudo tee \\\n \/etc\/apt\/sources.list.d\/jenkins.list > \/dev\/null\n<\/pre>\n\n\n\nUpdate the system and install Jenkins:<\/p>\n\n\n\n
sudo apt update -y\n\nsudo apt install jenkins -y\n\n<\/pre>\n\n\n\nOnce installed, start and enable the Jenkins service:<\/p>\n\n\n\n
sudo systemctl start jenkins && sudo systemctl enable jenkins<\/pre>\n\n\n\nTo check the status of the service:<\/p>\n\n\n\n
sudo systemctl status jenkins<\/pre>\n\n\n\nYou should get the following output:<\/p>\n\n\n\n
root@host:~# sudo systemctl status jenkins\n\u25cf jenkins.service - Jenkins Continuous Integration Server\n Loaded: loaded (\/lib\/systemd\/system\/jenkins.service; enabled; vendor preset: enabled)\n Active: active (running) since Thu 2023-04-06 15:17:46 CDT; 4min 1s ago\n Main PID: 22232 (java)\n Tasks: 45 (limit: 4571)\n Memory: 1.2G\n CPU: 1min 32.203s\n CGroup: \/system.slice\/jenkins.service\n \u2514\u250022232 \/usr\/bin\/java -Djava.awt.headless=true -jar \/usr\/share\/java\/jenkins.war --webroot=\/var\/cache\/jenkins\/war --httpPort=8080\n<\/pre>\n\n\n\n<\/span>Step 5. Setting up Apache as a Reverse Proxy<\/span><\/h2>\n\n\n\nTo access Jenkins installation via domain, we need to configure the Apache as a Reverse Proxy:<\/p>\n\n\n\n
Since Apache is already installed in the previous steps, you need to create the jenkins.conf<\/b> configuration file:<\/p>\n\n\n\ncd \/etc\/apache2\/sites-available\/\nsudo nano jenkins.conf\n<\/pre>\n\n\n\nPaste the following lines of code, save and close the file.<\/p>\n\n\n\n
<Virtualhost *:80>\n ServerName yourdomain.com<\/b>\n ProxyRequests Off\n ProxyPreserveHost On\n AllowEncodedSlashes NoDecode\n\n <Proxy http:\/\/localhost:8080\/*>\n Order deny,allow\n Allow from all\n <\/Proxy>\n\n ProxyPass \/ http:\/\/localhost:8080\/ nocanon\n ProxyPassReverse \/ http:\/\/localhost:8080\/\n ProxyPassReverse \/ http:\/\/yourdomain.com\/<\/b>\n<\/Virtualhost><\/pre>\n\n\n\nOnce you save and close the file, you need to execute the following commands:<\/p>\n\n\n\n
sudo a2ensite jenkins\nsudo a2enmod proxy\nsudo a2enmod proxy_http\nsudo a2enmod headers\nsudo systemctl restart apache2\n<\/pre>\n\n\n\nAfter enabling the Apache configuration and restarting the Apache service, you will be able to access your Jenkins via your domain.<\/p>\n\n\n\n