{"id":1,"date":"2025-05-01T20:24:59","date_gmt":"2025-05-01T20:24:59","guid":{"rendered":"http:\/\/www.khhtech.com\/?p=1"},"modified":"2025-05-23T13:01:25","modified_gmt":"2025-05-23T19:01:25","slug":"install-apache2-web-server-on-ubuntu-24-04","status":"publish","type":"post","link":"http:\/\/www.khhtech.com\/index.php\/2025\/05\/01\/install-apache2-web-server-on-ubuntu-24-04\/","title":{"rendered":"Install Apache 2.4 Web Server on Ubuntu 24.04 LTS Server"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I needed a development Web Server on my in-house network for website development. This Web Server will not be visible to the outside Internet, only to computers logged on through the local network. These are the steps I used to install and configure the Apache 2.4 Web Server on a in-house Ubuntu 24.04 LTS server.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color has-fira-code-font-family has-x-large-font-size wp-elements-3d26c8f5dfeff0977b4404d92c202c45 wp-block-paragraph\" style=\"color:#812d13\"><strong>Prerequisites:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before installing any new applications, confirm that you system is up to date. Open your terminal window by pressing the Ctl, Alt and &#8216;T&#8217; keys simultaneously. Enter the following command on the terminal.<\/p>\n\n\n\n<pre class=\"wp-block-code has-contrast-color has-text-color has-background has-link-color has-small-font-size wp-elements-ec3b88fade2b6ff7ee450e9319268adb\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>$ sudo apt update &amp;&amp; sudo apt upgrade<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Install mySQL and PHP before continuing with the Apache2 Web Server installation.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color has-fira-code-font-family has-x-large-font-size wp-elements-29765096d8a9e068fbb0d8d97a762bb6 wp-block-paragraph\" style=\"color:#812d13\"><strong>Install Apache 2.4<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To install the Apache2 Web Server, enter the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code has-contrast-color has-text-color has-background has-link-color has-small-font-size wp-elements-3f8f5da6e2eebec552fc8c9214a4059b\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>$ sudo apt install apache2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Start the service and confirm the installation.<\/p>\n\n\n\n<pre class=\"wp-block-code has-contrast-color has-text-color has-background has-link-color has-small-font-size wp-elements-c15dbf3364094512c5dfdd8f755b6a24\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>$ sudo systemctl start apache2\n$ sudo systemctl status apache2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The status command will display the following results, indicating the the Apache2 service is running.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full has-custom-border\"><img decoding=\"async\" src=\"http:\/\/dev-khhtech.com\/wp-content\/uploads\/2025\/05\/StatusScreen.png\" alt=\"\" class=\"wp-image-175\" style=\"border-radius:15px\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Another way to test that the Apache2 Web Server is active is by viewing the default Apache2 web page. Open a browser on the Ubuntu Server, where Apache2 is installed, and type <strong>http:\/\/localhost\/<\/strong> in the browser&#8217;s address line. This page will display on the browser showing that Apache2 is working correctly.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"http:\/\/dev-khhtech.com\/wp-content\/uploads\/2025\/05\/Apache2DefaultPage.png\" alt=\"\" class=\"wp-image-186\"\/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color has-fira-code-font-family has-x-large-font-size wp-elements-faecce629f0145567bfb54948910c376 wp-block-paragraph\" style=\"color:#812d13\"><strong>Open Listening Ports:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you have an active firewall on Ubuntu Server you will need to open the necessary ports for communication. Apache, by default, listens on port 80 (HTTP) and port 443 (HTTPS). The command below will open these ports on the Ubuntu Server. If you have configured Apache2 to use ports other than 80 and 443, you will need to adjust this command to open the correct ports.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>$ sudo ufw allow 'Apache Full'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can confirm the change with this commend.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>$ sudo ufw status<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The output will show that HTTP and HTTPS traffic is allowed.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>Status: active\n\nTo                         Action      From\n--                         ------      ----\nApache Full                ALLOW       Anywhere\nOpenSSH                    ALLOW       Anywhere\nApache Full (v6)           Allow       Anywhere (v6)\nOpenSSH (v6)               ALLOW       Anywhere (v6)<\/code><\/pre>\n\n\n\n<p class=\"has-text-color has-link-color has-fira-code-font-family has-x-large-font-size wp-elements-480d1a2ef33053d4b31d0c8577f15d97 wp-block-paragraph\" style=\"color:#812d13\"><strong>Create Website Directory:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now create a directory for the development website files and folders. By default Apache2&#8217;s web root is located in \/var\/www\/html. But a new website directory can be located anywhere. For this development website I created it at \/var\/www\/ and called it example.com using the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>$ sudo mkdir \/var\/www\/example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then below the example.com directory I create a \/public_html\/ directory. This is where all the website files and folders will be created.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>$ sudo mkdir \/var\/www\/example.com\/public_html<\/code><\/pre>\n\n\n\n<p class=\"has-text-color has-link-color has-fira-code-font-family has-x-large-font-size wp-elements-b92a2bae81eec8db24b9c27ef5f471cb wp-block-paragraph\" style=\"color:#812d13\"><strong>Set Directory Permissions:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set ownership of the directory to your Ubuntu username, to avoid permission issues, when creating files.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>$ sudo chown -R $USER:$USER \/var\/www\/example.com\/public_html\n$ sudo chmod -R 755 \/var\/www\/example.com\/public_html<\/code><\/pre>\n\n\n\n<p class=\"has-text-color has-link-color has-fira-code-font-family has-x-large-font-size wp-elements-28beb2c72cdab3a0947cd2661b1c5573 wp-block-paragraph\" style=\"color:#812d13\"><strong>Configure Virtual Host:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To allow the Apache2 Web Server to serve this web app, using a domain name of your choice, you will add it to a virtual host file in the \/etc\/apache2\/sites-available\/ directory. There is already a virtual host file, named 000-default.conf, located in this folder. This is the virtual host file that Apache2 is using to server the default web page. You can use the 000-default.conf file for your new web app. But it is best to create an new file, with a name that has a meaning for you, for the new virtual host. In my case I decided on using the file name <strong>vhosts.conf<\/strong>. Change directories to the \/etc\/apache2\/sites-available\/ directory. Using the VI text editor, I created a vhosts.conf file.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>$ cd \/etc\/apache2\/sites-available\n$ sudo vi vhosts.conf<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Within this file I entered and saved the following block.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>&lt;VirtualHost *:80&gt;\n    ServerAdmin webmaster@example.com\n    ServerName example.com\n    ServerAlias www.example.com\n    DocumentRoot \/var\/www\/example.com\/public_html\n    ErrorLog ${APACHE_LOG_DIR}\/error.log\n    CustomLog ${APACHE_LOG_DIR}\/access.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enable the vhosts.conf file with the <strong>a2ensite<\/strong> tool.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>$ sudo a2ensite vhosts.conf<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">But before Apache2 will serve this new web app, you will need to disable the 000-default.conf file. Do this with the <strong>a2dissite<\/strong> tool.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>$ sudo a2dissite 000-default.conf<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then, test for configuration errors in the virtual host file.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>$ sudo apache2ctl configtest<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The following output will indicate no errors in the virtual host file.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>Output\nSyntax OK<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Restart Apache2 to apply the changes.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>$ sudo systemctl restart apache2<\/code><\/pre>\n\n\n\n<p class=\"has-text-color has-link-color has-fira-code-font-family has-x-large-font-size wp-elements-250a82e5099f1043e00f77b4468e8896 wp-block-paragraph\" style=\"color:#812d13\"><strong>Create a Test Web Page:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a simple <strong>index.html<\/strong> page for the example.com web app. Using a text editor open a file in the \/var\/www\/example.com\/public_html directory<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>$ sudo vi \/var\/www\/example.com\/public_html\/index.html<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following html code to the index.html file and save the file.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n   &lt;title&gt;Test example.com Web Page&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n   &lt;h1&gt;Welcome the the EXAMPLE.COM Web Page!&lt;\/h1&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-text-color has-link-color has-x-large-font-size wp-elements-1a86a6121d629e02c90b47b5e6aafe1f wp-block-paragraph\" style=\"color:#812d14\"><strong>Modify the Hosts file to resolve domain:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Modifying the DNS Server is the preferred way to resolve domain names. But for small development environments, the Hosts files on the Ubuntu Server, and each computer needing to access the domain, can be modified. To configure the Ubuntu Server&#8217;s Hosts file, open the Hosts file with a text editor &#8211; such a notepad &#8211; enter the URL you will use for the web site on the same line as the localhost, each seperated by a space.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Ubuntu Server&#8217;s Hosts file will look like this.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>127.0.0.1          localhost <mark style=\"background-color:rgba(0, 0, 0, 0);color:#812d13\" class=\"has-inline-color\"><strong>example.com www.example.com<\/strong><\/mark>\n127.0.1.1          ubuntu-server-name<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To configure the individual&#8217;s computer Hosts file, open its Hosts file and, on a new line, enter the Ubuntu Server&#8217;s IP Address, followed by the URL you will use for the web site. Below is an example of what the Hosts file may like with the website URL added.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background has-small-font-size\" style=\"border-radius:15px;background-color:#d5d5d5\"><code>127.0.0.1          localhost\n127.0.1.1          ubuntu-server-name \n<strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#812d13\" class=\"has-inline-color\">192.168.1.2        www.example.com<\/mark><\/strong> <mark style=\"background-color:rgba(0, 0, 0, 0);color:#812d13\" class=\"has-inline-color\"><strong>example.com<\/strong><\/mark><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Apache2 should now be serving the example.com domain name. Test it by opening a browser and entering the URL http:\/\/www.example.com in the address line.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Install Apache 2.4.Web Server on Ubuntu 24.04 LTS Server<\/p>\n<p>I needed a development Web Server on my in-house network for website development. This Web Server will not visible to the outside Internet, only to computers logged on to the local network. These are the steps I used to install and configure the Apache 2.4 Web Server on a in-house Ubuntu 24.04 LTS server.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,7],"tags":[],"class_list":["post-1","post","type-post","status-publish","format-standard","hentry","category-apache2","category-ubuntu"],"_links":{"self":[{"href":"http:\/\/www.khhtech.com\/index.php\/wp-json\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.khhtech.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.khhtech.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.khhtech.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.khhtech.com\/index.php\/wp-json\/wp\/v2\/comments?post=1"}],"version-history":[{"count":48,"href":"http:\/\/www.khhtech.com\/index.php\/wp-json\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":260,"href":"http:\/\/www.khhtech.com\/index.php\/wp-json\/wp\/v2\/posts\/1\/revisions\/260"}],"wp:attachment":[{"href":"http:\/\/www.khhtech.com\/index.php\/wp-json\/wp\/v2\/media?parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.khhtech.com\/index.php\/wp-json\/wp\/v2\/categories?post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.khhtech.com\/index.php\/wp-json\/wp\/v2\/tags?post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}