banner



How To Install Apache On Ubuntu 17.10

In this guide we will install and configure the Apache web server on Ubuntu 16.04 / 17.x. You can use this guide for a unmarried domain website or multiple domains using Virtual Hosts.

Prerequisites

You should utilise a non-root user business relationship with sudo privileges. Please run across Initial server setup for Ubuntu 16.04 / 17.x for more details.

one. Install Apache

Let'due south begin by updating the listing of available packages and installing Apache.

          sudo apt-become update        
          sudo apt-get install apache2        

ii. Configure Firewall (optional)

It is highly recommended that you lot configure a firewall for added security. If you don't desire to ready a firewall, skip to Step 3.

Firstly, add a firewall rule for SSH so yous don't go disconnected. Yous may have already done this in the our Initial server setup for Ubuntu 16.04 / 17.10 guide, but it's no harm calculation it again to be sure.

          sudo ufw allow OpenSSH        
          sudo ufw allow in "Apache Full"        

Now enable the firewall if information technology isn't already.

          sudo ufw enable        

Press y if y'all see a bulletin "Command may disrupt existing ssh connections".

Now check the firewall status.

          sudo ufw status        
                      Status: agile            To                         Action      From --                         ------      ---- OpenSSH                    Allow       Anywhere            Apache Full                Permit       Anywhere            OpenSSH (v6)               Let       Anywhere (v6)            Apache Full (v6)           Permit       Anywhere (v6)                  

Above we tin can see the firewall is agile and has ii new rules for Apache.

3. Test Apache

We can now cheque to encounter if the Apache service is running correctly.

          sudo systemctl status apache2        
                                  apache2.service - LSB: Apache2 spider web server    Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)   Drop-In: /lib/systemd/system/apache2.service.d            └─apache2-systemd.conf    Active:            active (running)            since Fri 2022-01-26 11:03:xvi UTC; 44min ago      Docs: man:systemd-sysv-generator(8)    CGroup: /organization.slice/apache2.service            ├─14763 /usr/sbin/apache2 -k start            ├─14766 /usr/sbin/apache2 -k start            └─14767 /usr/sbin/apache2 -yard offset  Jan 26 11:03:15 myserver systemd[ane]: Starting LSB: Apache2 web server... Jan 26 11:03:fifteen myserver apache2[14739]:  * Starting Apache httpd spider web server apache2 Jan 26 eleven:03:15 myserver apache2[14739]: AH00558: apache2: Could not reliably determine the server'due south fully qualified domain name, using 127.0.ane.one. Ready Jan 26 11:03:16 myserver apache2[14739]:  * Jan 26 eleven:03:xvi myserver systemd[ane]: Started LSB: Apache2 web server.        

If you come across "agile (running)" in greenish, all should exist working correctly. Press CTRL + C to exit.

Apache should at present be serving the default web page. Go to your browser and enter your IP address.

If yous don't know your IP, you can find out with:

          ip addr show eth0 | grep inet | awk '{ impress $2; }' | sed 's/\/.*$//'        

You're all set! Yous can find this Apache default welcome page in the binder /var/www/html. To edit this file:

          sudo nano /var/www/html/index.html        

Press CTRL + X to go out the nano text editor.

If you would like to host more than one domain with Apache, keep to Stride 4.

4. Ready Virtual Hosts (optional)

If you wish to host multiple domains on Apache, y'all should at present prepare your directory structures and Virtual Hosts. Even if yous but want to host one domain, it's a good thought to set up up a directory and Virtual Host now considering if you ever need to add a new domain later, it will makes things a lot easier for yous.

For the purposes of this guide, we will make a virtual host for test1.com and another for test2.com. You tin can substitute these with your ain domains.

If yous don't have whatever domains yet, you can still follow this guide and add test1.com and test2.com to your hosts file to play a trick on your Os into resolving these domains in the browser. Delight see stop of guide on how to do this.

iv.1. Create Directories and Set Permissions

We are going to create two new directories in the /var/www/ directory for our two domains.

          sudo mkdir -p /var/www/test1.com/public_html        
          sudo mkdir -p /var/www/test2.com/public_html        

If we want our regular not-root user to exist able to modify files in these directories, we must alter the ownership.

          sudo chown -R $(whoami):$(whoami) /var/www/test1.com/public_html        
          sudo chown -R $(whoami):$(whoami) /var/www/test2.com/public_html        

The $(whoami) variable will take the value of the user you are currently logged in as.

We must likewise alter the permissions for the general web directory /var/www and its contents so that pages can be served correctly.

          sudo chmod -R 755 /var/www        

4.2. Create Test Spider web Pages

We'll now create a simple index.html web page for each domain using the nano editor.

Don't forget to replace test1.com with your own domain.

          sudo nano /var/world wide web/test1.com/public_html/index.html        

Once nano editor is open up, re-create and paste in the html below. To paste into nano, employ the right mouse button.

/var/www/test1.com/public_html/index.html

          <html>   <head>     <title>test1.com test folio</title>   </caput>   <body>     <h1>Welcome to test1.com!</h1>   </body> </html>        

Salvage and shut nano (Press CTRL + X and so press y and ENTER to save changes)

We can at present indistinguishable this webpage and copy information technology practice the test2 directory. Don't forget to replace test1.com and test2.com with your own domains.

          sudo cp /var/www/test1.com/public_html/alphabetize.html /var/www/test2.com/public_html/index.html        

Now edit this 2nd html file and change it as you wish.

          sudo nano /var/world wide web/test2.com/public_html/index.html        

Example:

/var/www/test2.com/public_html/index.html

          <html>   <caput>     <title>test2.com test page</title>   </head>   <torso>     <h1>Welcome to test2.com!</h1>   </torso> </html>        

Save and close nano (Press CTRL + Ten and then press y and ENTER to save changes)

4.3. Create New Virtual Host Files

The Virtual Host files located in /etc/apache2/sites-available/ are used to tell the Apache web server how to answer to diverse domain requests.

Let's create a new virtual host file for our test1.com domain.

          sudo nano /etc/apache2/sites-bachelor/test1.com.conf        

In nano, paste in the cake below. To paste into nano, press the correct mouse button.

/etc/apache2/sites-available/test1.com.conf

          <VirtualHost *:lxxx>     ServerAdmin webmaster@test1.com            ServerName            test1.com            ServerAlias www.test1.com            DocumentRoot /var/www/test1.com/public_html     ErrorLog ${APACHE_LOG_DIR}/error.log     CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>        

Be sure to modify all instances of test1.com to your own domain.

Save and close nano (Press CTRL + 10 and then press y and ENTER to save changes)

We tin can now repeat the above process for test2.com.

          sudo nano /etc/apache2/sites-available/test2.com.conf        

In nano, paste in the block beneath. To paste into nano, printing the right mouse button.

/etc/apache2/sites-available/test1.com.conf

          <VirtualHost *:80>     ServerAdmin webmaster@test2.com            ServerName            test2.com            ServerAlias world wide web.test2.com            DocumentRoot /var/world wide web/test2.com/public_html     ErrorLog ${APACHE_LOG_DIR}/error.log     CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>        

Be certain to alter all instances of test2.com to your own domain.

Save and close nano (Press CTRL + 10 and and then printing y and ENTER to save changes)

four.4. Enable the New Virtual Host Files

At present that we accept our 2 virtual host files in place, we demand to use the a2ensite tool to enable them.

Remember again to replace test1.com and test2.com with your own domains.

          sudo a2ensite test1.com.conf        
          sudo a2ensite test2.com.conf        

Almost done! Yous must now restart Apache to make these changes take effect.

          sudo service apache2 restart        

Bold you have already configured DNS on your domain registrar to betoken your domains to the IP of your Apache server, yous should now be able to view these test webpages in the web browser.

four.v Edit Hosts file (optional)

If you do not have whatever domains registered and instead just want to load test1.com and test2.com as a test, you lot can edit the hosts file in your Bone to point these domains to your server.

To edit hosts file in Linux or Mac, run sudo nano /etc/hosts. In Windows, follow this guide to edit hosts. Once hosts files is open, enter two new lines

hosts

          10.10.10.x test1.com x.ten.x.x test2.com        

Supervene upon x.10.ten.x with your server'southward IP.

If you don't know your IP, you can find out with:

          ip addr show eth0 | grep inet | awk '{ print $ii; }' | sed 'due south/\/.*$//'        

5. Configure Apache (Optional)

At present that you have Apache up and running, at that place may exist some common configuration changes that will be useful to you.

5.ane. Enable AllowOverride

You will find that .htaccess volition exist ignored by default in Apache. If this is something you will demand, nosotros can enable it past altering the Apache configuration file.

Firstly, backup the configuration file.

          sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak        

Open the config file.

          sudo nano /etc/apache2/apache2.conf        

Scroll down the the post-obit section.

/etc/apache2/apache2.conf

          <Directory /var/www/>         Options Indexes FollowSymLinks         AllowOverride None         Crave all granted </Directory>        

AllowOverride None means that .htaccess will be ignored. Modify it to AllowOverride All.

/etc/apache2/apache2.conf

          <Directory /var/www/>         Options Indexes FollowSymLinks            AllowOverride All            Require all granted </Directory>        

Relieve and exit (press CTRL + X, press Y so press ENTER)

Restart Apache.

          sudo systemctl restart apache2        

5.2. Enable mod_rewrite

If you lot want to later configure some rules in .htaccess, you will most likely demand to enable mod_rewrite.

          sudo a2enmod rewrite        

Restart Apache.

          sudo systemctl restart apache2        

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my Ezoic review to find out how.

Source: https://devanswers.co/installing-apache-ubuntu-16-04-17-10/

Posted by: guestthisidiever87.blogspot.com

0 Response to "How To Install Apache On Ubuntu 17.10"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel