{"id":477,"date":"2024-02-13T12:53:14","date_gmt":"2024-02-13T10:53:14","guid":{"rendered":"https:\/\/www.microfusion.org\/blog\/?p=477"},"modified":"2024-02-15T14:00:09","modified_gmt":"2024-02-15T12:00:09","slug":"setting-up-a-simple-apache-web-server-on-linux-ubuntu","status":"publish","type":"post","link":"https:\/\/www.microfusion.org\/blog\/setting-up-a-simple-apache-web-server-on-linux-ubuntu\/","title":{"rendered":"Setting up a simple Apache web server on Linux Ubuntu"},"content":{"rendered":"\n<p>Setting up a simple Apache web server on Linux Ubuntu giving you an in-depth look into how web servers work. It&#8217;s also very useful for web developers to have a platform to test websites on or for hosting your own. <\/p>\n\n\n\n<p>Lets talk about Apache web servers and Linux Ubuntu. In the world of web servers, you get some mainstream choices, such as Apache, NGINX, Lighttpd but in this tutorial we will be looking at setting up a simple production Apache web server. Apache has been around for decades and powers a good portion of the Web as we know it today&#8230;<\/p>\n\n\n\n<p> We will also be installing PHP and MariaDB to work alongside the Apache Web server.<\/p>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-7505880210632883\" crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-7505880210632883\" data-ad-slot=\"6291301981\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<div style=\"height:32px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Things you will need to setup the Apache web server on Linux Ubuntu<\/h2>\n\n\n\n<p><strong>A static IP, also known as a public IP address. <\/strong> most of the time, home users might not be able to host a web server from home either because their ISP (Internet service Provider) does not allow it or your IP address is dynamic, meaning it changes every 6 to 12 hours. Servers need a fixed IP that can be routed to the internet so that your domain name that points to the IP is always the same. A static IP never changes therefore DNS (Domain name Services) will always point to your Apache web servers address.<\/p>\n\n\n\n<p><strong>A Domain Name<\/strong>. This is crucial for a Apache web server to function, If you plan to use the server on your local network only then you can create your own DNS records that point to the Apache web server but the internet wont be able to make use of this server. <\/p>\n\n\n\n<p><strong>A Server PC running Linux Ubuntu<\/strong>. You can use pretty much any Linux distribution but we will be using Linux Ubuntu Server 22.04 LTS for this tutorial. Linux Ubuntu server edition does not have a Graphical Interface and we will be using the Command line for everything. You can however always install a GUI if you like but for the most part its not needed as you will see. <\/p>\n\n\n\n<p><strong>A Router that will allow for port forwarding<\/strong>, In order for the internet traffic to reach your Apache Web server you will need to be able to setup and forward a few ports, such as port 80, 8080 and 443. These ports are used by Apache and most common web servers to allow traffic to be redirected to the server once it enters your network. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Lets start by downloading Linux Ubuntu and installing it.<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">Step #1 &#8211; Downloading Ubuntu and Rufus<\/h4>\n\n\n\n<p><a href=\"https:\/\/ubuntu.com\/download\" target=\"_blank\" rel=\"noopener nofollow\" title=\"\">Download Linux Ubuntu 22.04 LTS<\/a> <strong>Server<\/strong> iso from Canonical here<\/p>\n\n\n\n<p>On the Canonical Website select <strong><em>Option 1 &#8211; Manual Server Installation<\/em><\/strong> then, <strong><em>Select Download Ubuntu Server<\/em><\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"aioseo-step-2-preparing-linux-ubuntu-installation-medium-via-flash-drive\">Step #2 &#8211; Preparing Linux Ubuntu installation medium via flash drive<\/h4>\n\n\n\n<p>First we need to prepare Ubuntu for installation using a flash drive. Plug in your flash drive on a windows PC not on the Web server PC then, using Rufus select the USB flash drive and the Ubuntu Server ISO image you downloaded as shown below. Then press start to copy the ISO files to the flash drive and make it bootable. <\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-style-default\"><img fetchpriority=\"high\" decoding=\"async\" width=\"474\" height=\"580\" src=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2023\/01\/Rufus1.jpg\" alt=\"Rufus Configuration for Linux Ubuntu Apache Web Server\" class=\"wp-image-75\" srcset=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2023\/01\/Rufus1.jpg 474w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2023\/01\/Rufus1-245x300.jpg 245w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><figcaption class=\"wp-element-caption\">Rufus Configuration for Linux Ubuntu 22.04 LTS<\/figcaption><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"aioseo-step-3-installing-the-linux-ubuntu-operating-system-from-the-flash-drive-on-our-nas-server\">Step #3 &#8211; Installing the Linux Ubuntu operating system from the flash drive on our Apache Web server<\/h4>\n\n\n\n<p>Once Rufus is done we can move over to the Web server an load its operating system. Plug the flash drive into the USB port and power on the Apache Web server PC.<\/p>\n\n\n\n<p>We will need to boot from the flash drive and to do so I&#8217;d highly advice consulting your motherboard manufacturer documentation. Most PC&#8217;s will have a shortcut key such as F2, F9, F10 or F12 to bring up a boot menu. Else you will need to configure the <em>BIOS<\/em> or <em>UEFI<\/em> to boot from flash drive. If you are using a <em>UEFI<\/em> bios, disable secure boot first to be able to boot from a flash drive&#8230;<\/p>\n\n\n\n<p>You will know you have successfully booted to the Linux Ubuntu Instraller when you reach the Ubuntu Installer screen<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized is-style-default\"><img decoding=\"async\" width=\"722\" height=\"408\" src=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Ubuntu-server-boot.jpg\" alt=\"Ubuntu Server boot splash screen\n\" class=\"wp-image-480\" srcset=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Ubuntu-server-boot.jpg 722w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Ubuntu-server-boot-300x170.jpg 300w\" sizes=\"(max-width: 722px) 100vw, 722px\" \/><figcaption class=\"wp-element-caption\">Ubuntu Grub Boot screen<\/figcaption><\/figure>\n\n\n\n<p>After selecting your Language the Installer will ask you which installer to use, the old one or the new one. <strong>We went with the new one. <\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img decoding=\"async\" width=\"799\" height=\"601\" src=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Ubuntu-Server-Installer.jpg\" alt=\"Ubuntu Legacy Installer\" class=\"wp-image-481\" srcset=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Ubuntu-Server-Installer.jpg 799w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Ubuntu-Server-Installer-300x226.jpg 300w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Ubuntu-Server-Installer-768x578.jpg 768w\" sizes=\"(max-width: 799px) 100vw, 799px\" \/><figcaption class=\"wp-element-caption\">Ubuntu Installer<\/figcaption><\/figure>\n\n\n\n<p>From there follow the Ubuntu installer to install the Ubuntu OS on the Apache server PC. It&#8217;s pretty straight forward and will only take about 20~30 minutes depending on your internet connection and Web server&#8217;s hardware.<\/p>\n\n\n\n<p><strong>Settings to pay attention too<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\" style=\"margin-right:0;margin-left:0;padding-right:var(--wp--preset--spacing--60);padding-left:var(--wp--preset--spacing--60)\">\n<li>Use the <strong>Default install for the Ubuntu server<\/strong>. For this tutorial we will be also using that option in the Ubuntu server setup <\/li>\n\n\n\n<li>You can skip setting up <strong>LVM and Disk Encryption<\/strong>. it&#8217;s optional. <\/li>\n\n\n\n<li>Set your Apache web servers name to <strong>server <\/strong>in the field<strong>. <\/strong>As indicated below. <\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"603\" src=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/usersetup.jpg\" alt=\"Ubuntu server Users setup and Apache web server name\n\" class=\"wp-image-482\" srcset=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/usersetup.jpg 800w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/usersetup-300x226.jpg 300w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/usersetup-768x579.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\" style=\"padding-top:0;padding-right:var(--wp--preset--spacing--60);padding-bottom:0;padding-left:var(--wp--preset--spacing--60)\">\n<li>Skip Ubuntu Pro, it&#8217;s a paid service.<\/li>\n\n\n\n<li>Do <strong>install OpenSSH<\/strong>, useful  to access the server from another computer.<\/li>\n\n\n\n<li>Skip <strong>Automatic server roll and features snaps<\/strong>.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"799\" height=\"597\" src=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/skipautopackages.jpg\" alt=\"Skip installing server snaps on Apache web server\" class=\"wp-image-483\" srcset=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/skipautopackages.jpg 799w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/skipautopackages-300x224.jpg 300w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/skipautopackages-768x574.jpg 768w\" sizes=\"(max-width: 799px) 100vw, 799px\" \/><\/figure>\n\n\n\n<p> When you reach the end of the installation you will be greeted with this screen as shown below. Restart the system and remove the USB flash drive. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"799\" height=\"602\" src=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/done.jpg\" alt=\"Ubuntu server install completed\" class=\"wp-image-484\" srcset=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/done.jpg 799w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/done-300x226.jpg 300w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/done-768x579.jpg 768w\" sizes=\"(max-width: 799px) 100vw, 799px\" \/><figcaption class=\"wp-element-caption\">Ubuntu Installation completed<\/figcaption><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"aioseo-step-4-getting-the-linux-ubuntu-operating-system-ready-to-be-a-nas-server\">Step #4 &#8211; Getting the Linux Ubuntu operating system ready to be an Apache Web Server<\/h4>\n\n\n\n<p>The very first thing we want to do after installing Ubuntu is update the system. This will ensure that any software we install is the latest versions and will help with security and stability of the overall Apache Web server. To update Ubuntu server and it&#8217;s software packages type in the following command or copy and paste it then hit enter. <\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-ast-global-color-8-background-color has-text-color has-background\"><code>sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"aioseo-step-5-setting-up-a-static-ip-address-on-ubuntu-22-04-lts-nas\">Step #5 &#8211; Setting up a static IP Local address on Ubuntu 22.04 Apache Web Server<\/h4>\n\n\n\n<p>Next we need to configure a static IP address for the server, By default the IP will be most likely come from your internet router and this will change which will cause issues down the line. By assigning a static IP address to the Web server we tell the router not to hand out an IP address and instead that the Apache web server will provide its own IP address that will not change automatically. Let&#8217;s setup a static IP now. Type in and run the following commands<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background\"><code>nmcli connection show<\/code><\/pre>\n\n\n\n<p>Take note of the <strong><em>DEVICE<\/em><\/strong> name that gets listed. next we will need to edit the following file. This is applicable to <strong><em>Ubuntu 22.04 LTS<\/em><\/strong> as of this writing, older versions of Ubuntu and future version might implement different ways of assigning static IP addresses.<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background\"><code>sudo nano \/etc\/netplan\/01-network-manager-all.yaml<\/code><\/pre>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-7505880210632883\" crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-7505880210632883\" data-ad-slot=\"6291301981\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<div style=\"height:32px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Make the following changes to the file as shown below. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step #6 &#8211; Configure Netplan on the Linux Ubuntu Apache Web Server<\/h4>\n\n\n\n<p>Be sure to mind the indentation, <strong><a href=\"https:\/\/netplan.io\/\" target=\"_blank\" rel=\"noopener nofollow\" title=\"Netplan\">Netplan<\/a><\/strong> is actually terrible to work with and if your tab spacing in the configuration file is incorrect it will not work.<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background\"><code>network:\n  renderer: <mark style=\"background-color:rgba(0, 0, 0, 0);color:#009000\" class=\"has-inline-color\">networkd<\/mark>\n  ethernets:\n    enp0s3:\n      addresses:\n        - 192.168.10.200\/24\n      nameservers:\n        addresses: &#91;192.168.10.1, 8.8.8.8]\n      routes:\n        - to: default\n          via: 192.168.10.1\n  version: 2\n<\/code><\/pre>\n\n\n\n<div style=\"height:32px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Take note for <em>Ubuntu Desktop<\/em> we set the renderer to <strong>NetworkManager<\/strong> and on Ubuntu Server we set the renderer to <strong>networkd<\/strong>. <\/p>\n\n\n\n<p>If you are using Ubuntu desktop you can get more information <a href=\"https:\/\/www.microfusion.org\/blog\/setting-up-a-simple-nas-server-on-linux-ubuntu\/\" target=\"_blank\" rel=\"noopener\" title=\"Setting up a simple NAS server on Linux Ubuntu\">Setting up a simple NAS server on Linux Ubuntu<\/a> and <a href=\"https:\/\/www.microfusion.org\/blog\/how-to-setup-a-home-network\/\" target=\"_blank\" rel=\"noopener\" title=\"How to Setup a home network\">How to Setup a home network<\/a><\/p>\n\n\n\n<p>In the above file we have used following configurations<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>enp0s3 is the interface name (yours might differ so check with <strong>nmcli connection show<\/strong> command )<\/li>\n\n\n\n<li>addresses are used to set the static ipv4 and the <strong><em>\/24<\/em><\/strong> is the netmask.<\/li>\n\n\n\n<li>nameservers used to specify the DNS server IP address&#8217;s<\/li>\n\n\n\n<li>routes used to specify the default gateway (this is your router&#8217;s IP most of the time)<\/li>\n<\/ul>\n\n\n\n<div style=\"height:32px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0);color:#88ff00\" class=\"has-inline-color\">Note:<\/mark> Please change the IP addresses and interface name as per your environment For this Example I am using the following values that you need to change<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>192.168.10.200 as my Static IPv4<\/li>\n\n\n\n<li><strong>\/24<\/strong> as my netmask, this one most likely will be the same for you as well. <\/li>\n\n\n\n<li>Name Server addresses DNS 192.168.10.1 (My routers DNS) and 8.8.8.8 (Google DNS) as a fallback<\/li>\n\n\n\n<li>Route needs to be set as your routers IP. in my case its 192.168.10.1<\/li>\n<\/ul>\n\n\n\n<div style=\"height:32px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Save the file by pressing <strong><em>CTRL+X<\/em><\/strong> then <strong><em>y<\/em><\/strong> and finally press <strong>enter<\/strong><\/p>\n\n\n\n<p>Apply the changes by running the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background\"><code>sudo netplan apply<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step #7 &#8211; Testing your network settings<\/h4>\n\n\n\n<p>Verify that you have internet and that everything is working. you can ping google using the following command in terminal.<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background\"><code>ping -c 4 www.google.com<\/code><\/pre>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-7505880210632883\" crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-7505880210632883\" data-ad-slot=\"6291301981\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<div style=\"height:32px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background\"><code>PING www.google.com (172.217.170.36) 56(84) bytes of data.\n64 bytes from jnb02s03-in-f4.1e100.net (172.217.170.36): icmp_seq=1 ttl=119 time=7.19 ms\n64 bytes from jnb02s03-in-f4.1e100.net (172.217.170.36): icmp_seq=2 ttl=119 time=5.88 ms\n64 bytes from jnb02s03-in-f4.1e100.net (172.217.170.36): icmp_seq=3 ttl=119 time=16.6 ms\n64 bytes from jnb02s03-in-f4.1e100.net (172.217.170.36): icmp_seq=4 ttl=119 time=5.34 ms\n\n--- www.google.com ping statistics ---\n4 packets transmitted, <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#31ff00\" class=\"has-inline-color\">4 received, 0% packet loss<\/mark><\/strong>, time 3030ms\nrtt min\/avg\/max\/mdev = 5.337\/8.741\/16.558\/4.562 ms\n<\/code><\/pre>\n\n\n\n<div style=\"height:32px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Look for the number of packets that was received which should be and <strong>0% loss<\/strong> which is good. At this point networking should be done.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step #8 &#8211; Mapping local IP addresses to DNS names in the hosts file<\/h4>\n\n\n\n<p>Apache will need to reference Websites and their names on the Web Server, We will need to add a few entries in the hosts file. The hosts file holds Local DNS records that maps IP addresses to domain names. In your console open the hosts file for editing<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-dabd25c72f172c83be960108abc15587\"><code>sudo nano \/etc\/hosts<\/code><\/pre>\n\n\n\n<p>You should see the file content as such:<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-e5cf8db23477a861fdae34a939dfd442\"><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-0-color\"># The following lines are desirable for IPv6 capable hosts<\/mark>\n::1     ip6-localhost ip6-loopback\nfe00::0 ip6-localnet\nff00::0 ip6-mcastprefix\nff02::1 ip6-allnodes\nff02::2 ip6-allrouters<\/code><\/pre>\n\n\n\n<p>At the very top above the comment we will make some changes. We need to insert our servers Local IP address and point it to the server name we picked. in this case <strong>server.demodomain.com<\/strong>, Replace <strong><em>demodomain.com<\/em><\/strong> with your own domain.<\/p>\n\n\n\n<p>We will also need to add a friendlier name for our website, such as<strong> www.demodomain.com<\/strong>. Later we will setup apache to use virtual Servers and one of them will be www.demodomain.com as we want people to access our website with <em>www.demodomain.com<\/em> and not <em>server.demodomain.com<\/em><\/p>\n\n\n\n<p>For a FQDN make sure you set the first entry in this file  to the servers name plus the domain name E.g. <mark style=\"background-color:rgba(0, 0, 0, 0);color:#ff0000\" class=\"has-inline-color\"><strong>server.demodomain.com<\/strong><\/mark><\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-f5c7f8d22ccc91123d5b8947fa453c7b\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3aff00\" class=\"has-inline-color\">127.0.0.1       <\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#ff0000\" class=\"has-inline-color\">server.demodomain.com<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3aff00\" class=\"has-inline-color\"> www.<mark style=\"background-color:rgba(0, 0, 0, 0);color:#3aff00\" class=\"has-inline-color\">demodomain.com <mark style=\"background-color:rgba(0, 0, 0, 0);color:#3aff00\" class=\"has-inline-color\">demodomain.com <mark style=\"background-color:rgba(0, 0, 0, 0);color:#3aff00\" class=\"has-inline-color\">localhost<\/mark><\/mark><\/mark> server\n192.168.10.200  <\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#ff0000\" class=\"has-inline-color\">server.demodomain.com<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3aff00\" class=\"has-inline-color\"> www.demodomain.com demodomain.com<\/mark>\n\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-0-color\"># The following lines are desirable for IPv6 capable hosts<\/mark>\n::1     ip6-localhost ip6-loopback\nfe00::0 ip6-localnet\nff00::0 ip6-mcastprefix\nff02::1 ip6-allnodes\nff02::2 ip6-allrouters<\/code><\/pre>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Lets also make sure that the host name for our Apache Web server is setup correctly. in the console type in:<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-74d71bd17a38cfd3a05115ea72be3bb6\"><code>hostname -f<\/code><\/pre>\n\n\n\n<p>You should see a single line that is your servers name followed by the domain name. This is also called a FQDM or Fully qualified domain name, in this case its <em>server<\/em>.demodomain.com Yours should match your domain name. If its incorrect you can edit the <em>hostname<\/em> file with the following command. <\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-92715c3d90b5961c2e75e6e48ba48248\"><code>sudo nano \/etc\/hostname<\/code><\/pre>\n\n\n\n<p>And made sure you set your Apache web server&#8217;s name to server in the host file then double check the \/etc\/hosts file and make sure the first entries are set to use <em>server.demodomain.com<\/em>, remember to replace the domain here with your actual domain name. <\/p>\n\n\n\n<p>After making changes re-run <strong><em>hostname -f<\/em><\/strong> to make sure it is setup correctly. This is a crucial step to ensure that your Apache web server will function correctly. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step #9 &#8211; Installing Apache, PHP and MariaDB on the Apache web server<\/h4>\n\n\n\n<p>Its time to install the software packages we need to turn this Ubuntu install into a Apache Web server. Thus we install the required software packages as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-96e2166d272ab143e25998853f585d27\"><code>sudo apt install apache2 php php-mysql mariadb-server<\/code><\/pre>\n\n\n\n<p><strong>Lets break down the packages we are installing for the Apache Web server<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>apache2<\/strong> is the actual Apache webserver package<\/li>\n\n\n\n<li><strong>PHP<\/strong> is a server side script that is widely used by many websites<\/li>\n\n\n\n<li><strong>php-mysql<\/strong> makes sure that PHP can use a database service in this case mariaDB which is the opensource alternitive to MySQL but you can use MySQL if you choose <\/li>\n\n\n\n<li> maria-db-server is a database service that is used by the webserver and more advances websites to store and serve information such as user accounts and other information.<\/li>\n<\/ul>\n\n\n\n<p>After installing and restarting the server you can open up a browser window and navigate to the Apache Web Server&#8217;s IP address, this will be the local LAN (Local area network) IP address, if all went well you should see the following basic website pop up. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"707\" src=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-13-at-10-45-07-Apache2-Ubuntu-Default-Page-It-works.png\" alt=\"Apache Web Server Ubuntu\" class=\"wp-image-486\" srcset=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-13-at-10-45-07-Apache2-Ubuntu-Default-Page-It-works.png 800w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-13-at-10-45-07-Apache2-Ubuntu-Default-Page-It-works-300x265.png 300w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-13-at-10-45-07-Apache2-Ubuntu-Default-Page-It-works-768x679.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Step #10 &#8211; Setting up the first website on the Apache web Server<\/h4>\n\n\n\n<p>by Default on Ubuntu servers Apache stores the website files int he \/var\/www\/html folder. This folder is only writable to users belonging to the Apache group. to make things simple we will add our user account to that group so we can make changes to the website files. The following command will ad your Username to the www-data group, www-data is the group used on Unbuntu servers and distro&#8217;s for Apache. <\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-1b5c4ce110039d363997a30bbed7908e\"><code> sudo usermod -a -G www-data $USER\n sudo chown -R $USER:www-data \/var\/www\/html\/<\/code><\/pre>\n\n\n\n<p>To verify you belong to the group you can then type into the console <strong>groups $USER<\/strong> or <strong>groups &lt;Username&gt;<\/strong> where <em>&lt;Username&gt;<\/em> is your actual user name. In the list returned you should see the www-data along with others like sudo and cdrom etc. <\/p>\n\n\n\n<p>You can now write and place website files into that directory. <\/p>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-7505880210632883\" crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-7505880210632883\" data-ad-slot=\"6291301981\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<div style=\"height:32px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Now, if you only plan on using the web server for a single website then you are almost there. You can use the directory <strong>\/var\/www\/html<\/strong> to host your files. However if you want a more robust server that will host multiple websites you will need to make use of <a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/vhosts\/\" target=\"_blank\" rel=\"noopener nofollow\" title=\"virtual hosts\"><strong>virtual hosts<\/strong><\/a> provided by Apache web server. You can view our Virtual Hosts tutorial here <strong><a href=\"https:\/\/www.microfusion.org\/blog\/setting-up-apache-virtual-hosts-on-linux-ubuntu-server\/\" target=\"_blank\" rel=\"noopener\" title=\"Setting up Apache virtual hosts on Linux Ubuntu server\">Setting up Apache virtual hosts on Linux Ubuntu server<\/a><\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step #11 Testing php on the Apache web server<\/h4>\n\n\n\n<p>Lets test and make sure php is working with apache. To do this, navigate to the apache web directory where the website files are located. <\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-f9f4d1fc3ddf3523d447b4781083dc94\"><code>cd \/var\/www\/html<\/code><\/pre>\n\n\n\n<p>Next, create a new file called info.php in that directroy using the following command<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-6b866601b652b7298d9195dbdcddf325\"><code>touch test.php &amp;&amp; nano info.php<\/code><\/pre>\n\n\n\n<p>We will now write a simple php server script to get all the information about the current php installation on the server. Copy or write the following line of code and save the info.php file. <\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-0dc711c8f6178249900778cc48d9114d\"><code>&lt;?php echo phpinfo(); ?&gt;<\/code><\/pre>\n\n\n\n<p>Save and close the file. Using nano <strong>press ctrl + x then y followed by enter<\/strong> to accept and save the file.<\/p>\n\n\n\n<p>In your browser on a different computer as before navigate to the Apache Web server&#8217;s address flollowed by the \/info.php to call that page. E.g<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-68f66fef08f22d107e34739b0494a7d9\"><code>http:&#47;&#47;192.168.10.200\/info.php<\/code><\/pre>\n\n\n\n<p>if you have done this correctly you will be greated by the PHP information page which looks something like this.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"933\" height=\"859\" src=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-13-at-11-19-51-PHP-8.1.2-1ubuntu2.14-phpinfo.png\" alt=\"Apache Web server PHP information\" class=\"wp-image-487\" srcset=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-13-at-11-19-51-PHP-8.1.2-1ubuntu2.14-phpinfo.png 933w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-13-at-11-19-51-PHP-8.1.2-1ubuntu2.14-phpinfo-300x276.png 300w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-13-at-11-19-51-PHP-8.1.2-1ubuntu2.14-phpinfo-768x707.png 768w\" sizes=\"(max-width: 933px) 100vw, 933px\" \/><\/figure>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-7505880210632883\" crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-7505880210632883\" data-ad-slot=\"6291301981\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Step #12 Setting up mariaDB on the Apache web server<\/h4>\n\n\n\n<p>Before we do anything we need to first set a MySQL username and password. In terminal run the following command <\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-f483fea2aa39f760a935c34c6ad5378f\"><code>sudo myssql -u root -p<\/code><\/pre>\n\n\n\n<p>After getting ot the MySQL command prompt setup a new user with a password making sure you take note of the passwork and username you use here. For this example i will be using admin and the username on localhost and a good strong password. Remember this password though as we will need it later.<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-a07a78490586df14f51cbe4aff9eccc5\"><code><code>CREATE USER 'admin'@'localhost' IDENTIFIED BY 'some_very_complex_password';<\/code><\/code><\/pre>\n\n\n\n<p>next we need to grand all priviladged for this user, to do that while still in the MySQL console execute the following commands line by line.<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-9c8bde75a995ff9886322178eb8f0648\"><code>GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;\nFLUSH PRIVILEGES;\nexit<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step #13 Making it easier to manage MySQL\/MariaDB on the Apache web server<\/h4>\n\n\n\n<p>To make things easier to maintain, manage and work with MySQL \/ MariaDB we will be installing <strong><a href=\"https:\/\/www.phpmyadmin.net\/\" target=\"_blank\" rel=\"noopener nofollow\" title=\"phpmyadmin\">phpmyadmin<\/a><\/strong>. Its a web based front end used to easily create, manage and work on databases for your webserver. To install phpmyadmin run the following command<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-72cab4bca5c8a0451187b72c46943b61\"><code>sudo apt install phpmyadmin<\/code><\/pre>\n\n\n\n<p>During the installation you will be asked to provide which web server you are using. Make sure you select the apache option using &lt;space bar&gt; to tick an asterix next the apache option then &lt;tab&gt; to navigate to ok then again &lt;space bar&gt; to continue the instalation of phpmyadmin<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"757\" height=\"225\" src=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/phpmyadmin.jpg\" alt=\"Apache server selected for phpmyadmin\" class=\"wp-image-489\" srcset=\"https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/phpmyadmin.jpg 757w, https:\/\/www.microfusion.org\/blog\/wp-content\/uploads\/2024\/02\/phpmyadmin-300x89.jpg 300w\" sizes=\"(max-width: 757px) 100vw, 757px\" \/><\/figure>\n\n\n\n<p>When phpmyadmin asked to configure a default database press ok to have it do so. Next you will need to setup a SQL password for phpmyadnin to use. when promted to do so, enter your MySQL password for the admin account you created earlier and continue. Confirm the password one last time and then finish the installation. <\/p>\n\n\n\n<p>Now you can again using your browser navigate to the servers IP followed by \/phpmyadmin to access the web dashboard E.g<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-6-color has-ast-global-color-8-background-color has-text-color has-background has-link-color wp-elements-30d84b2fcc50a741548f6837d12fd326\"><code>http:&#47;&#47;192.168.10.200\/phpmyadmin\/<\/code><\/pre>\n\n\n\n<p>Using your MySQL Credentials you can now login and manage databases. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Getting the apache web server onto the Internet<\/h2>\n\n\n\n<p>At this point you have a basic webserver setup.  To give it access to the internet and have people visit it,  you will need to point your domain (DNS) A record to your public static IP provided by your ISP and then forward your apache server&#8217;s port 80 TCP, 8080 (Optinal TCP) and 443 (TCP) to your web servers internal Static IP address. <\/p>\n\n\n\n<p>In this case that would be 192.168.10.200 as per this tutorial. <strong>This we will cover in another tutorial as it can become really complicated really quick.<\/strong><\/p>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-7505880210632883\" crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-7505880210632883\" data-ad-slot=\"6291301981\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<div style=\"height:32px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Some things to take into consideration when messing with web servers.<\/h2>\n\n\n\n<p>Though this tutorial provides you with the basics of setting up a Ubuntu Apache web server it is risky business to make it availble to the Internet. Proper security and precausions need to be in place before you attempt to do that. Additionally SSL needs to be implemented as well as good firewall, and other implementations.<\/p>\n\n\n\n<p>Web servers are fun to play with and can help you if you are a web developer to develop and test the sites in house without making it avalible to the Internet by simulating a production level server. But to manage and run your own internet facing server is a lot of work and requires good knowlege of networking, Linux systems and cyber security practices&#8230; Most of the time it&#8217;s best to rather just rent a server from a provider and have them deal with the technicalities on your behalve.<\/p>\n\n\n\n<p>You can also look at something like <strong><a href=\"https:\/\/www.apachefriends.org\/\" target=\"_blank\" rel=\"noopener nofollow\" title=\"XAMPP\">XAMPP<\/a><\/strong><\/p>\n\n\n\n<p>XXAMPP is a opensource project used to deploy a simple weserver on a Windows PC for use as a developer to test and use. It makes use of tools we used in this tutorail as well such as phpmyadmin. It might be easier to get going with that if you quickly need a local webserver. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setting up a simple Apache web server on Linux Ubuntu giving you an in-depth look into how web servers work. It&#8217;s also very useful for web developers to have a platform to test websites on or for hosting your own. <\/p>\n","protected":false},"author":1,"featured_media":491,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[3,24],"tags":[19,10,12],"class_list":["post-477","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general","category-linux","tag-how-to","tag-linux","tag-servers"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.microfusion.org\/blog\/wp-json\/wp\/v2\/posts\/477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.microfusion.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.microfusion.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.microfusion.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.microfusion.org\/blog\/wp-json\/wp\/v2\/comments?post=477"}],"version-history":[{"count":7,"href":"https:\/\/www.microfusion.org\/blog\/wp-json\/wp\/v2\/posts\/477\/revisions"}],"predecessor-version":[{"id":501,"href":"https:\/\/www.microfusion.org\/blog\/wp-json\/wp\/v2\/posts\/477\/revisions\/501"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.microfusion.org\/blog\/wp-json\/wp\/v2\/media\/491"}],"wp:attachment":[{"href":"https:\/\/www.microfusion.org\/blog\/wp-json\/wp\/v2\/media?parent=477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.microfusion.org\/blog\/wp-json\/wp\/v2\/categories?post=477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.microfusion.org\/blog\/wp-json\/wp\/v2\/tags?post=477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}