Latest

How to install Apache for Ubuntu 20.04 LTS

Pinterest LinkedIn Tumblr

How to install Apache for Ubuntu 20.04 LTS

How to install Apache on the Ubuntu Linux Server 20.04 LTS

The Apache web server (also known as HTTPD) is one of the most popular web servers for maintaining dynamic and static websites. It is free and open source software released under an Apache 2.0 license. Let’s see how to install Apache on the Ubuntu 20.04 LTS Linux server.

 

How to install Apache on Ubuntu 20.04 LTS

Make sure your system is updated and repaired. To do so, enter the following command apt:
sudo apt update
sudo apt upgrade
How to install Apache for Ubuntu 20.04 LTS

Step 1 – Installing the Apache 2 Server

Now that the system has been updated with the latest patches, it is time to install the Apache 2 software. In other words, type the following command and press [Enter]:
sudo apt install apache2
How to install Apache for Ubuntu 20.04 LTS

Step 2 – Make sure that the Apache service is started when theversion is loaded.

To enable apache2.service, we use the systemctl command as follows:
sudo systemctl enabled apache2.service
If not enabled, enable it, start:
sudo systemctl enabled apache2.service

Managing the Apache 2 Service on the Ubuntu Cloud Server

Use the following commands to start, stop, restart and then recognise the maintenance status again.

Starting up the Apache2 Server

sudo systemctl start apache2.service

Stopping the Apache2 Server

sudo systemctl stop apache2.service

Rebooting the Apache2 Server

sudo systemctl restart apache2.service

Reboot the Apache2 server for free

sudo systemctl restart apache2.service

Finding the status of the Apache2 server

sudo systemctl apache2.service status

* apache2.service – Apache HTTP Server
Loaded: loaded (/lib/system/apache2.service; enabled; vendor default: enabled)
Active: active (running) since March 2020-05 19:49:41 UTC; 7 minutes ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 1766 (apache2)
Tasks: 54 (limit: 4915)
memory : 6.5MCGroup: /system.slice/apache2.service??1766 /usr/sbin/apache2 -k start??1767 /usr/sbin/apache2 -k start??1768 /usr/sbin/apache2 -k start.

05. May 19:49:41 db-host systemd [1] : Starting the Apache HTTP Server…
05 May 19:49:41 db-host apachectl [1765] : AH00558: Apache2 : Cannot determine the full domain name of the server reliably with 127.0.1.1 Set the ServerName guideline globally to delete this message
May 05 19:49:41 db-host systemd [1] : The Apache HTTP server is running.

* apache2.service – The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-05-05 19:49:41 UTC; 7min ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 1766 (apache2)
Tasks: 54 (limit: 4915)
Memory: 6.5M
CGroup: /system.slice/apache2.service
??1766 /usr/sbin/apache2 -k start
??1767 /usr/sbin/apache2 -k start
??1768 /usr/sbin/apache2 -k start
May 05 19:49:41 db-host systemd[1]: Starting The Apache HTTP Server…
May 05 19:49:41 db-host apachectl[1765]: AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message
May 05 19:49:41 db-host systemd[1]: Started The Apache HTTP Server.

Step 3 – Open Apache ports 80 and 443 with the UFWfirewall .

Run the following command ufw on TCP ports 80 and 443 for all sudo ufw
accepting comment 80/tcp Apache from
sudo ufw accepting comment 443/tcp HTTPS connections from
Check:
sudo ufw status
sample output :

Status: active

For action
—–
10.105.28.158 22/tcp PERMIT 192.168.2.0/24
80/tcp PERMIT Anywhere # accept Apache
443 /tcp PERMIT Anywhere # accept HTTPS connections
80/tcp (v6) PERMIT Anywhere (v6) # accept Apache
443 /tcp (v6) PERMIT Anywhere (v6) # accept HTTPS connections

For more information, see How to configure a UFW firewall on Ubuntu 20.04 LTS.

Step 4 – Find the IP address of your Ubuntu 20.04 LTSserver

Execute one of the following commands: Host name
-I
ip a
ip a s eth0
My IP Address :

10.105.28.158

You can also use the dig/host command to find your public IPv4/IPv6 address via the CLI:
dig +short myip.opendns.com @resolver1.opendns.com
For more information about a Linux, see How to find my public IP address from the command line on a Linux.

Step 5 – Test your Apache 2 installation on Ubuntu.

At this point you can use the curl command as follows:
curl -I http://10.105.28.158
Example output:

HTTP/1.1 200 OK
Date : Thu, 05 May 2020 20:08:32 GMT
Server : Apache/2.4.41 (Ubuntu)
Last modified : Thu, 05 May 2020 19:49:22 GMT
ETag: 2aaa6-5a4ebf1b4b8bf
Reception area : Bytes
Length of contents: 10918
varieties : Acceptance –
Decoding point content : Text/html

Another option is to start a web browser such as Chrome or Firefox and enter the URL as follows:
http://your-server-ip
http://10.105.28.158
How to install Apache for Ubuntu 20.04 LTS web server.

Basic configuration

Edit /etc/apache2/apache2.conf, execute:
sudo nano /etc/apache2/apache2.conf
Set at least the server name 127.0.0.1 or the real name, such as your compass or server IP address
Server name 10.105.28.9
Save and close the file. Next, edit the /etc/apache2/ports.conf file, which contains the list of ports to be monitored in the Ubuntu box:
sudo nano /etc/apache2/ports.conf
By default, Apache version 2 monitors Apache on Ubuntu Linux TCP ports 80 (HTTP) and 443 (HTTPS). However, there is no need to adjust them. If you manage many sites in Linux containers, we adjust the ports as follows:

##########################################################################
Обычно Вам не нужно менять по умолчанию. Предназначены для заблаговременного использования / пользователей ##
###############################################################################
# Изменить HTTP–порт 80 на 86
Lists 86

# Change HTTPS port 443 to 449

Listen 449

Listen to 449.

########################################################################################
## Typically you don’t have to change the defaults. These are for advance usage/users ##
########################################################################################
# Change HTTP port 80 to 86
Listen 86
# Change HTTPS port 443 to 449

Listen 449

Listen 449

You must customize the virtual host/virtual domain configuration to the port number specified in ports.conf.

Step 6 – Configuring Apache 2 Virtual Hosts

Create a configuration file for your domain as follows:
sudo nano /etc/apache2/sites-available/my-domain-name.conf
Add the following configuration file:

# Replace my domain name with a valid domain name like cyberciti.biz #

ServerAdmin [email protected] here
ServerName my-domain-name here
ServerAlias www.my-domain-name here
DocumentRoot /home/my-domain-name here/html
Directory index.html
ErrorLog ${APACHE_LOG_DIR}/my-domain-name.log
CustomLog ${APACHE_LOG_DIR}/my-domain-name.log combined

Options Indexes FollowSymLinks
AllowOverride None
All information is required.

# Replace my-domain-name-here with actual domain name such as cyberciti.biz #

ServerAdmin [email protected]
ServerName my-domain-name-here
ServerAlias www.my-domain-name-here
DocumentRoot /home/my-domain-name-here/html
DirectoryIndex index.html
ErrorLog ${APACHE_LOG_DIR}/my-domain-name-here-error.log
CustomLog ${APACHE_LOG_DIR}/my-domain-name-here-access.log combined

Options Indexes FollowSymLinks
AllowOverride None
Require all granted

Create a new Ubuntu user for the website

Type the following custom command
sudo useradd -d /home/my domain-namee-here -m -k /dev/null -s /usr/sbin/nologin usernamehere
True,

  • -d /home/ my last name somewhere: Install the home directory for your new document safe account.
  • -m : Make sure we have set the user’s home directory to -d.
  • -k /dev/null : Avoid creating dot files for the virtual Apache DocumentRoot domain that can reveal sensory information using /dev/null as another skeletal directory.
  • -s /usr/sbin/nologin : Install the login shell for the new account in /usr/sbin/nologin so that a web server user cannot login to our system using ssh or any other method. It’s also a safety feature.
  • Username : The username under which the files are stored in our virtual domain.

Lock the Linux user account, type:
sudo passwd -l username
Create an html folder with the command mkdir:
sudo mkdir -pv /home/my-domain-name.here/html
Create an example html page as follows:
sudo nano /home/my-domain-name/html/index.html

 

 

www.cyberciti.biz

It’s a test page:

  • Ubuntu Linux 20.04 LTS
  • Apache 2.x

[email protected]

 

www.cyberciti.biz

It’s a test page:

  • Ubuntu Linux 20.04 LTS
  • Apache 2.x

[email protected]

Set the permissions with the chown command:
sudo -R chown username:username/here /home/my-domainname
Activate the newly created virtual domain, execute:
sudo a2ensite my-domainname.conf
sudo a2dissite 000-default.conf
Example output :

Including my-domain-name.conf
To activate the new configuration, you will need:
systemctl restart apache2.

Test configuration:
sudo apache2ctl conf configtest
You must receive an OK syntax message and then reboot the Apache server on Ubuntu Linux:
sudo systemctl reboot apache2
Install the A and AAAAAA rules of your domains on the server’s public IPv4/IPv6 address and test them:
http://my-domain-name-here
http://www.cyberciti.biz
How to install Apache for Ubuntu 20.04 LTS

Conclusion

You have now installed the Apache 2 webserver on Ubuntu Linux 20.04 LTS. You can configure PHP/Python applications or install TLS/SSL certificates to ensure traffic safety. I strongly advise you to read the Apache 2.4 documents here.

RECOMMENDATIONS

Published: Vivek gears

The author is the creator of nixCraft and an experienced system administrator, DevOps engineer and Linux/Unix shell script trainer. Receive the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly by email.ubuntu 20 install apache,job for apache2.service failed because the control process exited with error code.,install php on apache,apache ubuntu 20,install php 5.6 ubuntu 18.04 digitalocean,ubuntu 20.04 php,ubuntu 20 install lamp,install php 7.1 ubuntu digitalocean