# Apache2 - nie działa - nie tworzy się serwer

## calif

Witam!

Mam problem z apache2.

/etc/init.d/apache2 start - brak błędów, po chwili zostaje wypisane:

```
 * Starting apache2 ...                                           [ ok ]
```

a gdy wchodzę na localhost wyskakuje błąd, dodatkowo gdy skanuję porty nmap'em:

```
home calif # nmap localhost

Starting Nmap 5.21 ( http://nmap.org ) at 2010-06-20 17:51 CEST

Nmap scan report for localhost (127.0.0.1)

Host is up (0.000051s latency).

All 1000 scanned ports on localhost (127.0.0.1) are closed

Nmap done: 1 IP address (1 host up) scanned in 0.35 seconds

```

Nie został stworzony port z serwerem WWW.

W pliku httpd.conf mam Listen 8080(i różne inne też próbowałem), ponieważ przy Listen 80 wyskakiwał błąd:

```
 * Starting apache2 ...

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80

no listening sockets available, shutting down

Unable to open logs

```

Nie wiem co mam zrobić.

Oto mój plik httpd.conf:

```
ServerRoot "/usr/lib/apache2"

ServerName 127.0.0.1

LoadModule actions_module modules/mod_actions.so

LoadModule alias_module modules/mod_alias.so

LoadModule auth_basic_module modules/mod_auth_basic.so

LoadModule authn_alias_module modules/mod_authn_alias.so

LoadModule authn_anon_module modules/mod_authn_anon.so

LoadModule authn_dbm_module modules/mod_authn_dbm.so

LoadModule authn_default_module modules/mod_authn_default.so

LoadModule authn_file_module modules/mod_authn_file.so

<IfDefine AUTHNZ_LDAP>

LoadModule authnz_ldap_module modules/mod_authnz_ldap.so

</IfDefine>

LoadModule authz_dbm_module modules/mod_authz_dbm.so

LoadModule authz_default_module modules/mod_authz_default.so

LoadModule authz_groupfile_module modules/mod_authz_groupfile.so

LoadModule authz_host_module modules/mod_authz_host.so

LoadModule authz_owner_module modules/mod_authz_owner.so

LoadModule authz_user_module modules/mod_authz_user.so

LoadModule autoindex_module modules/mod_autoindex.so

<IfDefine CACHE>

LoadModule cache_module modules/mod_cache.so

</IfDefine>

LoadModule cgi_module modules/mod_cgi.so

<IfDefine DAV>

LoadModule dav_module modules/mod_dav.so

</IfDefine>

<IfDefine DAV>

LoadModule dav_fs_module modules/mod_dav_fs.so

</IfDefine>

<IfDefine DAV>

LoadModule dav_lock_module modules/mod_dav_lock.so

</IfDefine>

LoadModule deflate_module modules/mod_deflate.so

LoadModule dir_module modules/mod_dir.so

<IfDefine CACHE>

LoadModule disk_cache_module modules/mod_disk_cache.so

</IfDefine>

LoadModule env_module modules/mod_env.so

LoadModule expires_module modules/mod_expires.so

LoadModule ext_filter_module modules/mod_ext_filter.so

<IfDefine CACHE>

LoadModule file_cache_module modules/mod_file_cache.so

</IfDefine>

LoadModule filter_module modules/mod_filter.so

LoadModule headers_module modules/mod_headers.so

LoadModule include_module modules/mod_include.so

<IfDefine INFO>

LoadModule info_module modules/mod_info.so

</IfDefine>

<IfDefine LDAP>

LoadModule ldap_module modules/mod_ldap.so

</IfDefine>

LoadModule log_config_module modules/mod_log_config.so

LoadModule logio_module modules/mod_logio.so

<IfDefine CACHE>

LoadModule mem_cache_module modules/mod_mem_cache.so

</IfDefine>

LoadModule mime_module modules/mod_mime.so

LoadModule mime_magic_module modules/mod_mime_magic.so

LoadModule negotiation_module modules/mod_negotiation.so

LoadModule rewrite_module modules/mod_rewrite.so

LoadModule setenvif_module modules/mod_setenvif.so

LoadModule speling_module modules/mod_speling.so

<IfDefine SSL>

LoadModule ssl_module modules/mod_ssl.so

</IfDefine>

<IfDefine STATUS>

LoadModule status_module modules/mod_status.so

</IfDefine>

LoadModule unique_id_module modules/mod_unique_id.so

<IfDefine USERDIR>

LoadModule userdir_module modules/mod_userdir.so

</IfDefine>

LoadModule usertrack_module modules/mod_usertrack.so

LoadModule vhost_alias_module modules/mod_vhost_alias.so

User apache

Group apache

Listen 80

Include /etc/apache2/modules.d/*.conf

Include /etc/apache2/vhosts.d/*.conf

DocumentRoot "/home/calif/Pulpit/html"
```

A to plik /etc/conf.d/apache2:

```
# /etc/conf.d/apache2: config file for /etc/init.d/apache2

# When you install a module it is easy to activate or deactivate the modules

# and other features of apache using the APACHE2_OPTS line. Every module should

# install a configuration in /etc/apache2/modules.d. In that file will have an

# <IfDefine NNN> directive where NNN is the option to enable that module.

#

# Here are the options available in the default configuration:

#

#  AUTH_DIGEST  Enables mod_auth_digest

#  AUTHNZ_LDAP  Enables authentication through mod_ldap (available if USE=ldap)

#  CACHE        Enables mod_cache

#  DAV          Enables mod_dav

#  ERRORDOCS    Enables default error documents for many languages.

#  INFO         Enables mod_info, a useful module for debugging

#  LANGUAGE     Enables content-negotiation based on language and charset.

#  LDAP         Enables mod_ldap (available if USE=ldap)

#  MANUAL       Enables /manual/ to be the apache manual (available if USE=docs)

#  MEM_CACHE    Enables default configuration mod_mem_cache

#  PROXY        Enables mod_proxy

#  SSL          Enables SSL (available if USE=ssl)

#  SUEXEC       Enables running CGI scripts (in USERDIR) through suexec.

#  USERDIR      Enables /~username mapping to /home/username/public_html

#

#

# The following two options provide the default virtual host for the HTTP and

# HTTPS protocol. YOU NEED TO ENABLE AT LEAST ONE OF THEM, otherwise apache

# will not listen for incomming connections on the approriate port.

#

#  DEFAULT_VHOST      Enables name-based virtual hosts, with the default

#                     virtual host being in /var/www/localhost/htdocs

#  SSL_DEFAULT_VHOST  Enables default vhost for SSL (you should enable this

#                     when you enable SSL)

#

APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP5"

# Extended options for advanced uses of Apache ONLY

# You don't need to edit these unless you are doing crazy Apache stuff

# As not having them set correctly, or feeding in an incorrect configuration

# via them will result in Apache failing to start

# YOU HAVE BEEN WARNED.

# PID file

PIDFILE=/var/run/apache2.pid

# timeout for startup/shutdown checks

#TIMEOUT=10

# ServerRoot setting

SERVERROOT=/usr/lib/apache2

# Configuration file location

# - If this does NOT start with a '/', then it is treated relative to

# $SERVERROOT by Apache

CONFIGFILE=/etc/apache2/httpd.conf

# Location to log startup errors to

# They are normally dumped to your terminal.

#STARTUPERRORLOG="/var/log/apache2/startuperror.log"

# A command that outputs a formatted text version of the HTML at the URL

# of the command line. Designed for lynx, however other programs may work.

#LYNX="lynx -dump"

# The URL to your server's mod_status status page.

# Required for status and fullstatus

STATUSURL="http://localhost/server-status"

# Method to use when reloading the server

# Valid options are 'restart' and 'graceful'

# See http://httpd.apache.org/docs/2.2/stopping.html for information on

# what they do and how they differ.

#RELOAD_TYPE="graceful"
```

I na koniec jeszcze emerge --info:

```
home calif # emerge --info

Portage 2.1.8.3 (default/linux/x86/10.0/desktop, gcc-4.4.3, glibc-2.10.1-r1, 2.6.32-gentoo-r7 i686)

=================================================================

System uname: Linux-2.6.32-gentoo-r7-i686-Intel-R-_Atom-TM-_CPU_N270_@_1.60GHz-with-gentoo-1.12.13

Timestamp of tree: Sun, 06 Jun 2010 13:00:01 +0000

ccache version 2.4 [enabled]

app-shells/bash:     4.0_p37

dev-java/java-config: 2.1.10

dev-lang/python:     2.6.4-r1, 3.1.2-r3

dev-util/ccache:     2.4-r7

dev-util/cmake:      2.6.4-r3

sys-apps/baselayout: 1.12.13

sys-apps/sandbox:    1.6-r2

sys-devel/autoconf:  2.13, 2.65

sys-devel/automake:  1.9.6-r3, 1.10.2, 1.11.1

sys-devel/binutils:  2.18-r3

sys-devel/gcc:       4.4.3-r2

sys-devel/gcc-config: 1.4.1

sys-devel/libtool:   2.2.6b

virtual/os-headers:  2.6.30-r1

ACCEPT_KEYWORDS="x86"

ACCEPT_LICENSE="* -@EULA"

CBUILD="i686-pc-linux-gnu"

CFLAGS="-O2 -march=i686 -pipe"

CHOST="i686-pc-linux-gnu"

CONFIG_PROTECT="/etc /usr/share/X11/xkb /usr/share/config"

CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"

CXXFLAGS="-O2 -march=i686 -pipe"

DISTDIR="/usr/portage/distfiles"

FEATURES="assume-digests ccache distlocks fixpackages news parallel-fetch protect-owned sandbox sfperms strict unmerge-logs unmerge-orphans userfetch"

GENTOO_MIRRORS="http://ftp.vectranet.pl/gentoo/ "

LANG="pl_PL.UTF-8"

LDFLAGS="-Wl,-O1"

MAKEOPTS="-j2"

PKGDIR="/usr/portage/packages"

PORTAGE_CONFIGROOT="/"

PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"

PORTAGE_TMPDIR="/var/tmp"

PORTDIR="/usr/portage"

SYNC="rsync://rsync.gentoo.org/gentoo-portage"

USE="X a52 aac acl acpi alsa apm berkdb bluetooth branding bzip2 cairo cdr cli consolekit cracklib crypt cups cxx dbus dri dts dvd dvdr emboss encode exif fam firefox flac fortran gdbm gif gpm hal iconv ipv6 jpeg kde lcms ldap libnotify lm_sensor mad mikmod mng modules mp3 mp4 mpeg mudflap ncurses nls nptl nptlonly ogg opengl openmp pam pango pcre pdf perl pmu png ppds pppd python qt3 qt3support qt4 readline reflection sdl session spell spl ssl startup-notification svg sysfs tcpd tiff truetype unicode usb vorbis x264 x86 xcb xml xorg xulrunner xv xvid zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1 emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="keyboard mouse evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" RUBY_TARGETS="ruby18" USERLAND="GNU" VIDEO_CARDS="intel" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account" 

Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LC_ALL, LINGUAS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, PORTDIR_OVERLAY

```

Co robić? Czemu serwer nie działa? Proszę o szybką odpowiedź, to bardzo ważne!

calif

PS.

Dodatkowo:

```
home calif # /etc/init.d/apache2 stop

 * Stopping apache2 ...

httpd (no pid file) not running                                   [ ok ]

```

----------

## c0oba

A logi apache'a nic nie mówią?

`netstat -tuna` powie ci co się dzieje z socketem. Powinien być nasłuchujący na 0.0.0.0:8080 w twoim przypadku.

I możesz jeszcze sprawdzić czy w ogóle proces apache'a rusza `ps aux | grep apache`.

----------

## dylon

Jak powiedzial przedmowca, przedewszystkim sprawdz logi systemowe czy wogole apache startuje.

Pozniej sprawdz defaultowa konfiguracje w /etc/apache2/vhosts.d/00_default_vhost.conf lub inne vhosty (o ile takie stworzyles).

[EDIT]

nie definiuj w http.conf defaultow jak listen 80 i document root

od tego jest wlasnie 00_default_vhost   i pewnie dlatego sie gryzie o ten juz uzywany port 80)

[/EDIT]

----------

## calif

```
home vhosts.d # netstat -tuna

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address           Foreign Address         State      

tcp        0      0 95.40.89.193:35227      193.17.41.53:443        ESTABLISHED

tcp        0      1 95.40.89.193:51036      204.187.15.12:80        LAST_ACK   

tcp        0      1 95.40.89.193:51038      204.187.15.12:80        LAST_ACK   

tcp        0      0 95.40.89.193:42492      212.91.9.39:80          ESTABLISHED

tcp        0      1 95.40.89.193:51030      204.187.15.12:80        LAST_ACK   

tcp        0      0 95.40.89.193:51205      91.214.237.45:443       ESTABLISHED

tcp        0      1 95.40.89.193:51032      204.187.15.12:80        LAST_ACK   

tcp        0      1 95.40.89.193:51031      204.187.15.12:80        LAST_ACK   

tcp        0      1 95.40.89.193:51037      204.187.15.12:80        LAST_ACK   
```

i

```
home vhosts.d # ps aux | grep apache

root     13538  0.0  0.0   2348   728 pts/0    S+   22:40   0:00 grep --colour=auto apache

```

i plik 00_default_vhost.conf

```
home vhosts.d # cat 00_default_vhost.conf

# Virtual Hosts

#

# If you want to maintain multiple domains/hostnames on your

# machine you can setup VirtualHost containers for them. Most configurations

# use only name-based virtual hosts so the server doesn't need to worry about

# IP addresses. This is indicated by the asterisks in the directives below.

#

# Please see the documentation at

# <URL:http://httpd.apache.org/docs/2.2/vhosts/>

# for further details before you try to setup virtual hosts.

#

# You may use the command line option '-S' to verify your virtual host

# configuration.

<IfDefine DEFAULT_VHOST>

# see bug #178966 why this is in here

# Listen: Allows you to bind Apache to specific IP addresses and/or

# ports, instead of the default. See also the <VirtualHost>

# directive.

#

# Change this to Listen on specific IP addresses as shown below to

# prevent Apache from glomming onto all bound IP addresses.

#

#Listen 12.34.56.78:80

Listen 80

# Use name-based virtual hosting.

NameVirtualHost *:80

# When virtual hosts are enabled, the main host defined in the default

# httpd.conf configuration will go away. We redefine it here so that it is

# still available.

#

# If you disable this vhost by removing -D DEFAULT_VHOST from

# /etc/conf.d/apache2, the first defined virtual host elsewhere will be

# the default.

<VirtualHost *:80>

        ServerName localhost

        Include /etc/apache2/vhosts.d/default_vhost.include

        <IfModule mpm_peruser_module>

                ServerEnvironment apache apache

        </IfModule>

</VirtualHost>

</IfDefine>

# vim: ts=4 filetype=apache
```

Co teraz? Nadal nie działa (usunąłem to co napisał przedmówca z pliku httpd.conf)

----------

## dylon

Pokaz wynik:

netstat -tulpn| grep :80

a po drugie upewnij sie,ze w http.con nie masz "Listen ...."

W katalogu /etc/apache2 wykonaj : 

```
 find . | xargs grep "80" 
```

   bedziesz wiedzial gdzie masz odwolania do tego portu

----------

## SlashBeast

Odpal apache z palca, wtedy bedzie bardziej wymowny, pewnie dowiesz sie co go boli.

Pozatym, widze, ze moda na irracjonalne uwielbienie apache sie nie konczy...

// SlashBeast, the nginx lover.

----------

## c0oba

Z tego co pamiętam to apache się ładnie pluje przy odpalaniu ze skryptów startowych, a ten tutaj ginie po cichu nic nikomu nie mówiąc, chyba że coś jest w logach. Jeśli nie, to ustaw najwyższy stopień logowania i sprawdź. Wtedy już musi coś napisać.

----------

## calif

netstat -tulpn| grep :80 

nic

find . | xargs grep "80" :

```
home apache2 #  find . | xargs grep "80" 

./vhosts.d/00_default_vhost.conf:#Listen 12.34.56.78:80

./vhosts.d/00_default_vhost.conf:Listen 80

./vhosts.d/00_default_vhost.conf:NameVirtualHost *:80

./vhosts.d/00_default_vhost.conf:<VirtualHost *:80>

./modules.d/00_default_settings.conf:# For security reasons this is turned off by default. (bug #240680)

./modules.d/00_mpm.conf:        ExpireTimeout           1800

```

Z palca, tzn. jak?

Nginx działał, ale coś z php było nietak.

----------

## Jacekalex

 *calif wrote:*   

> ...
> 
> Z palca, tzn. jak?
> 
> ....

 

A na przykład tak:

```
 ~ # apache2 -t
```

To by było na tyle

 :Cool: 

----------

