Score:0

Trying to install apache for NextCloud, getting an error message

ru flag
invoke-rc.d: initscript apache2, action "restart" failed.
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Wed 2022-02-16 07:12:03 UTC; 8ms ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 638499 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)

Feb 16 07:12:03 server systemd[1]: Starting The Apache HTTP Server...
Feb 16 07:12:03 server apachectl[638502]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
Feb 16 07:12:03 server apachectl[638502]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
Feb 16 07:12:03 server apachectl[638502]: no listening sockets available, shutting down
Feb 16 07:12:03 server apachectl[638502]: AH00015: Unable to open logs
Feb 16 07:12:03 server apachectl[638499]: Action 'start' failed.
Feb 16 07:12:03 server apachectl[638499]: The Apache error log may have more information.
Feb 16 07:12:03 server systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
Feb 16 07:12:03 server systemd[1]: apache2.service: Failed with result 'exit-code'.
Feb 16 07:12:03 server systemd[1]: Failed to start The Apache HTTP Server.
Setting up php8.1 (8.1.2-1+ubuntu20.04.1+deb.sury.org+1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Processing triggers for php8.1-cli (8.1.2-1+ubuntu20.04.1+deb.sury.org+1) ...
Processing triggers for libapache2-mod-php8.1 (8.1.2-1+ubuntu20.04.1+deb.sury.org+1) ...
root@server:~#

I've tried purging and reinstalling apache and php8.1 but I can't get it to work. Am i missing anything? Running sudo apache2ctl -t comes up with OK syntax, and running sudo systemctl restart apache2 gives the following:

Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.

I am on Ubuntu Server 20.04, and I am using OpenSSH. Thanks in advance.

EDIT: NetBat asked for the outputs to some functions, here they are:

zein127@server:~$ sudo sudo service --status-all | grep -i apache
ep -i apache
sudo ps -aux | grep -i apache
ls -l /etc/apache2/sites-enabled
grep -R "80" /etc/apache2 [ - ]  apache-htcacheclean
 [ + ]  apache2
zein127@server:~$ sudo systemctl --type service --all | grep -i apache
  apache2.service                                       loaded    active   running The Apache HTTP Server                                    
● snap.nextcloud.apache.service                         loaded    failed   failed  Service for snap application nextcloud.apache             
zein127@server:~$ sudo ps -ef | grep -i apache
root        1943       1  0 18:24 ?        00:00:00 /usr/sbin/apache2 -k start
www-data    2238    1943  0 18:24 ?        00:00:00 /usr/sbin/apache2 -k start
www-data    2239    1943  0 18:24 ?        00:00:00 /usr/sbin/apache2 -k start
www-data    2240    1943  0 18:24 ?        00:00:00 /usr/sbin/apache2 -k start
www-data    2241    1943  0 18:24 ?        00:00:00 /usr/sbin/apache2 -k start
www-data    2242    1943  0 18:24 ?        00:00:00 /usr/sbin/apache2 -k start
zein127     9072    5247  0 18:25 pts/0    00:00:00 grep --color=auto -i apache
zein127@server:~$ sudo ps -aux | grep -i apache
root        1943  0.0  0.2 199540 18664 ?        Ss   18:24   0:00 /usr/sbin/apache2 -k start
www-data    2238  0.0  0.1 199964  8276 ?        S    18:24   0:00 /usr/sbin/apache2 -k start
www-data    2239  0.0  0.1 199964  8276 ?        S    18:24   0:00 /usr/sbin/apache2 -k start
www-data    2240  0.0  0.1 199964  8276 ?        S    18:24   0:00 /usr/sbin/apache2 -k start
www-data    2241  0.0  0.1 199964  8276 ?        S    18:24   0:00 /usr/sbin/apache2 -k start
www-data    2242  0.0  0.1 199964  8276 ?        S    18:24   0:00 /usr/sbin/apache2 -k start
zein127     9075  0.0  0.0   6432   740 pts/0    S+   18:25   0:00 grep --color=auto -i apache
zein127@server:~$ ls -l /etc/apache2/sites-enabled
total 0
lrwxrwxrwx 1 root root 35 Feb 16 07:05 000-default.conf -> ../sites-available/000-default.conf
zein127@server:~$ grep -R "80" /etc/apache2
/etc/apache2/sites-available/nextcloud.conf:<VirtualHost *:80>
/etc/apache2/sites-available/000-default.conf:<VirtualHost *:80>
/etc/apache2/sites-enabled/000-default.conf:<VirtualHost *:80>
/etc/apache2/magic:1080 string  M.K.            audio/x-mod
/etc/apache2/magic:1080 string  M!K!            audio/x-mod
/etc/apache2/magic:1080 string  FLT4            audio/x-mod
/etc/apache2/magic:1080 string  FLT8            audio/x-mod
/etc/apache2/magic:1080 string  4CHN            audio/x-mod
/etc/apache2/magic:1080 string  6CHN            audio/x-mod
/etc/apache2/magic:1080 string  8CHN            audio/x-mod
/etc/apache2/magic:1080 string  CD81            audio/x-mod
/etc/apache2/magic:1080 string  OKTA            audio/x-mod
/etc/apache2/magic:#>1080       string  >/0             %.2s-channel Fasttracker "oktalyzer" module sound data
/etc/apache2/magic:1080 string  16CN            audio/x-mod
/etc/apache2/magic:1080 string  32CN            audio/x-mod
/etc/apache2/magic:0    lelong&0x8080ffff       0x0000081a      application/x-arc       lzw
/etc/apache2/magic:0    lelong&0x8080ffff       0x0000091a      application/x-arc       squashed
/etc/apache2/magic:0    lelong&0x8080ffff       0x0000021a      application/x-arc       uncompressed
/etc/apache2/magic:0    lelong&0x8080ffff       0x0000031a      application/x-arc       packed
/etc/apache2/magic:0    lelong&0x8080ffff       0x0000041a      application/x-arc       squeezed
/etc/apache2/magic:0    lelong&0x8080ffff       0x0000061a      application/x-arc       crunched
/etc/apache2/magic:2080 string  Microsoft\ Excel\ 5.0\ Worksheet        application/excel
/etc/apache2/magic:2080 string  Microsoft\ Word\ 6.0\ Document  application/msword
/etc/apache2/magic:2080 string  Documento\ Microsoft\ Word\ 6   application/msword
/etc/apache2/magic:0            lelong&0x8080ffff       0x0000081a      application/x-arc
/etc/apache2/magic:0            lelong&0x8080ffff       0x0000091a      application/x-arc
/etc/apache2/magic:0            lelong&0x8080ffff       0x0000021a      application/x-arc
/etc/apache2/magic:0            lelong&0x8080ffff       0x0000031a      application/x-arc
/etc/apache2/magic:0            lelong&0x8080ffff       0x0000041a      application/x-arc
/etc/apache2/magic:0            lelong&0x8080ffff       0x0000061a      application/x-arc
/etc/apache2/magic:# 0x9445366139FA (V 3.80)
/etc/apache2/ports.conf:Listen 80
in flag
From the message, something else may be listening on Port 80 already. Is your server running Node, Nginx, or another web service?
Score:0
br flag

Situation analysis

From your log:

Address already in use: AH00072: make_sock: could not bind to address [::]:80 Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80

no listening sockets available, shutting down

A collision concerning your TCP port 80 occured. There are two possible reasons of problem in your server:

  1. Some application or service on background use the same port TCP 80 as the Apache wishes to use.
  2. Wrong port+address / socket setting is in your Apache config. It is less probable reason than #1.

Solution

Install the net-tools and use netstat to get information what process/application occupies TCP 80 in your system.

sudo apt-get install net-tools
sudo netstat -lntp | grep -e ":80" -e "PID"

Now you see the process number and application name which uses port 80. Disable this application or change application setting to use another port than TCP 80.

Detail process listings usable for searching details about application which is listening on your TCP port:

ps -ef
ps -aux

Search for the process number got from netstat output.

Extended answer after new information in comment

According to your response it looks you have the 2 instances of Apache in collision.

Reboot your server. In "fresh" system use these commands and paste their outputs here to your question.

sudo sudo service --status-all | grep -i apache
sudo systemctl --type service --all | grep -i apache
sudo ps -ef | grep -i apache
sudo ps -aux | grep -i apache
ls -l /etc/apache2/sites-enabled
grep -R "80" /etc/apache2

Edit

(after new data were pasted by InsertRandomString in response to my request)

You already have an Apache instance running and listening on your system. The running Apache service is displayed in new outputs you have attached. There is no need to install any new web server (Apache, Nginx...). Do not install it, but use what is already available.

Verify the Apache functionality by web browser. Put your server IP address into address field of web browser and press Enter. You will see default Apache page confirming server is OK. For instance http://192.168.1.25

Your web server is capable to publish more virtual sites in separate domains simultaneously. Each of them must have its own file in the /etc/apache2/sites-available directory and in /etc/apache2/sites-enabled too. In /etc/sapache2/sites-enabled are only symbolic links of enabled sites.

Do you plan to use more domains and more virtual sites on your server?

  • If yes, create new file for the Nextcloud site in /etc/apache2/sites-available and link it to /etc/apache2/sites-enabled. You need special domain for Nextcloud site and a DNS record must be set too.
  • If no, edit the default site parameters in the /etc/apache2/sites-available/000-default.conf file and set correct values like the name of directory containing all your Nextcloud PHP files etc. It is not necessary (but is possible) to have special domain. The IP address is enough to display your Nextcloud site.

I suppose you know how to set Apache configuration files to publish the Nextcloud site e.g. /var/www/nextcloud instead of default page /var/www/html.

In case you intend use your Nextcloud with public IP address, then it is absolutely necessary to configure SSL, certificates and enable secure HTTPS access too. Otherwise your Nextcloud user names and passwords can be captured and compromised.

My personal note

The Nextcloud is not so simple as it looks. Many PHP modules must be installed, the MySQL database prepared etc. But I very like this service, it is my preferred tool for the data sharing and synchronizing on multiple devices.

InsertRandomString avatar
ru flag
Thanks for the help. After entering the second command, this is what I get: `Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name` `tcp6 0 0 :::80 :::* LISTEN 1505/apache2` I'm not very experienced in linux, but it seems to me that it is the second option you noted. What should I do in this situation?
netbat avatar
br flag
Please do steps I added to extended answer above.
netbat avatar
br flag
Please do steps I added to extended answer above.
InsertRandomString avatar
ru flag
Sorry for not seeing your response earlier, I've edited my question to include the outputs you asked for.
netbat avatar
br flag
See my response I have appended to answer above.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.