Im new in ubuntu
I got an error when I start the apache2
What I did first was uninstalling the apache2
sudo apt-get purge apache2
then I removed the /usr/sbin/apache2 with sudo rm -rf /usr/sbin/apache2
then install again the apache2
sudo apt-get install apache2
After that I tried to start the apache2 but it was failed to start
this is the error
Related
I made a simple custom docker setup for php development. So far everything works as expected. The only thing that I cannot figure out is why apache2 does not start automatically.
Here is my dockerfile:
FROM ubuntu:latest
RUN apt-get update && apt-get install -y apache2 php libapache2-mod-php php-mcrypt php-mysql php-cli php-curl php-xml php-intl php-mbstring git vim composer curl
COPY . /var/www/example
COPY vhost.conf /etc/apache2/sites-available/example.conf
RUN a2ensite example
RUN chown -R www-data:www-data /var/www/example/logs
RUN service apache2 restart
And here is my docker-compose.yml:
version: '2'
services:
app:
build:
context: .
dockerfile: Dockerfile
image: myexampleapp
ports:
- 8080:80
tty: true
And here is the output docker-compose up command:
me#mydell:~/workspace/mydockercompose$ docker-compose up -d --build
Creating network "mydockercompose_default" with the default driver
Building app
Step 1/7 : FROM ubuntu:latest
---> f975c5035748
Step 2/7 : RUN apt-get update && apt-get install -y apache2 php libapache2-mod-php php-mcrypt php-mysql php-cli php-curl php-xml php-intl php-mbstring git vim composer curl
---> Using cache
---> 148c3a9d928a
Step 3/7 : COPY . /var/www/example
---> 1fbc1dbacf1e
Step 4/7 : COPY vhost.conf /etc/apache2/sites-available/example.conf
---> 9c08947b09e9
Step 5/7 : RUN a2ensite example
---> Running in 1ef64defe747
Enabling site example.
To activate the new configuration, you need to run:
service apache2 reload
Removing intermediate container 1ef64defe747
---> ca1c8e7e80fc
Step 6/7 : RUN chown -R www-data:www-data /var/www/example/logs
---> Running in 57b0214be7a0
Removing intermediate container 57b0214be7a0
---> b3b270a36bf4
Step 7/7 : RUN service apache2 restart
---> Running in 09d2b1d3bd91
* Restarting Apache httpd web server apache2
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
...done.
Removing intermediate container 09d2b1d3bd91
---> 19fa9a90f9de
Successfully built 19fa9a90f9de
Successfully tagged myexampleapp:latest
Creating mydockercompose_app_1
It shows clearly that apache was restarted successfully. However it actually does not:
me#mydell:~/workspace/mydockercompose$ docker exec -i -t 20add8ad9895 service apache2 status
* apache2 is not running
I am new to docker, so all suggestions (even if they are not answering this specific question) to improve what I am doing so far are welcome.
Thanks
Docker services have to be running in the foreground. In your Dockerfile, RUN service apache2 restart will start apache as background process. Hence the container will exit.
To run apache in the foreground, add the following to the Dockerfile.
CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]
FROM ubuntu:latest
RUN apt-get update && apt-get install -y apache2 php libapache2-mod-php php-mcrypt php-mysql php-cli php-curl php-xml php-intl php-mbstring git vim composer curl
COPY . /var/www/example
COPY vhost.conf /etc/apache2/sites-available/example.conf
RUN a2ensite example
RUN chown -R www-data:www-data /var/www/example/logs
CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]
The above answer is probably correct that mentioned that you can start it with:
CMD apachectl -D FOREGROUND
With docker it is sometimes a good idea to use the absolute path to a binary. So for example maybe do this instead:
/usr/sbin/apache2 -D FOREGROUND
I had a look a bit on google to see what other people are doing. I found this example of a dockerfile where the guy mentions a script start.sh:
From here: https://github.com/jacksoncage/apache-docker/blob/master/Dockerfile
EXPOSE 80
ADD start.sh /start.sh
RUN chmod 0755 /start.sh
CMD ["bash", "start.sh"]
Here is the start.sh script: https://github.com/jacksoncage/apache-docker/blob/master/start.sh
Which simply just does:
#!/bin/bash
# Start apache
/usr/sbin/apache2 -D FOREGROUND
Unrelated tip:
Your dockerfile you need to pin the version for Ubuntu.
See: https://nickjanetakis.com/blog/docker-tip-18-please-pin-your-docker-image-versions
Let me know if this helps.
If it help you or anybody, i was preparing working example with complete docker-composer:
https://github.com/marekz/docker-composer-example
FROM ubuntu:18.04
EXPOSE 80
ENV TZ=Europe/Warsaw
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y libapache2-mod-php7.2 php7.2 php7.2-cli php7.2-gd php7.2-intl php7.2-mbstring php7.2-mysql php7.2-xml php7.2-xsl php7.2-bcmath php7.2-zip php-apcu npm lynx
RUN apt-get install -y mysql-client composer screen tmux vim nano iputils-ping
ENTRYPOINT service apache2 restart && bash
By analyzing the statements, I found a solution to my error
File: Dockerfile
FROM debian
RUN apt-get update -qq >/dev/null && apt-get install -y -qq procps telnet apache2 php7.3 -qq >/dev/null
RUN useradd --user-group --create-home --shell /bin/false app
RUN mkdir /data && chown -R app /data && chmod 777 /data
COPY php.conf /etc/apache2/mods-available/php7.3.conf
RUN a2enmod userdir && a2enmod php7.3
Error:
To activate the new configuration, you need to run:
service apache2 reload
Solutions:
FROM debian -> FROM debian:10
The reason was some conflict between the debian system and the php version. The latest version of debian has a newer version of PHP (PHP 7.4 at that time).
I am deploying Flask application in Apache2 server during this i need to run a command for enabling mod_wsgi by using:
sudo a2enmod wsgi
but its showing:
sudo: a2enmod: command not found
please help
thanks
I had the same problem with using Ubuntu 16.04 in AWS. However, installing apache2 along with libapache2-mod-wsgi and python-dev solved the issue.
Try:
sudo apt-get update
sudo apt-get install apache2 libapache2-mod-wsgi python-dev
Then,
sudo a2enmod wsgi
I share this tips because it append to me :
If you enter into the root account with su, the /usr/sbin folder is not in the path and the a2enmod command is not found...
So you have to use su - instead ;)
This can happen if you switch to root user as su root instead of su - on Debian Buster
Installation debugging
For asking about installation debugging, you have to post (and think) about
Architecture (hardware)
OS with version
Host attibution (server, desktop, other)
Procedure followed for installation
Software (apache) version
Anyway
You could try to reinstall your package. If under Ubuntu, you could try:
sudo apt update &&
sudo apt reinstall apache2 libapache2-mod-wsgi
Then rerun:
sudo a2enmod wsgi
I am trying to create a Dockerfile that will start apache automatically. Nothing has worked. But If I log into the container and run service apache2 start it works. Why can I not run that command from my Dockerfile?
FROM ubuntu
# File Author / Maintainer
MAINTAINER rmuktader
# Update the repository sources list
RUN apt-get update
# Install and run apache
RUN apt-get install -y apache2 && apt-get clean
#ENTRYPOINT ["/usr/sbin/apache2", "-k", "start"]
#ENV APACHE_RUN_USER www-data
#ENV APACHE_RUN_GROUP www-data
#ENV APACHE_LOG_DIR /var/log/apache2
EXPOSE 80
CMD service apache2 start
The issue is here: CMD service apache2 start When you execute this command process apache2 will be detached from the shell. But Docker works only while main process is alive.
The solution is to run Apache in the foreground. Dockerfile must look like this: (only last line changed).
FROM ubuntu
# File Author / Maintainer
MAINTAINER rmuktader
# Update the repository sources list
RUN apt-get update
# Install and run apache
RUN apt-get install -y apache2 && apt-get clean
#ENTRYPOINT ["/usr/sbin/apache2", "-k", "start"]
#ENV APACHE_RUN_USER www-data
#ENV APACHE_RUN_GROUP www-data
#ENV APACHE_LOG_DIR /var/log/apache2
EXPOSE 80
CMD apachectl -D FOREGROUND
For me last line with CMD was wrong:
# it helped me
CMD ["apachectl", "-D", "FOREGROUND"]
My project was slightly different where I installed a bunch of other stuff, but the apache start portion matched above. Once I built this image and used it, my server started fine.
FROM ubuntu:latest
#install all the tools you might want to use in your container
RUN apt-get update
RUN apt-get install curl -y
RUN apt-get install vim -y
#the following ARG turns off the questions normally asked for location and timezone for Apache
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get install apache2 -y
#change working directory to root of apache webhost
WORKDIR var/www/html
#copy your files, if you want to copy all use COPY . .
COPY index.html index.html
#now start the server
CMD ["apachectl", "-D", "FOREGROUND"]
FROM ubuntu
RUN apt update
ARG DEBIAN_FRONTEND=noninteractive
RUN apt install apache2 -y && apt-get clean
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
EXPOSE 80
CMD ["apachectl", "-D", "FOREGROUND"]
Adding the ARG DEBIAN_FRONTEND=noninteractive should do the trick.
FROM ubuntu
RUN apt-get update
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get -y install apache2
ADD index.html /var/www/html
CMD ["apachectl", "-D", "FOREGROUND"]
Simple docker file for run ubuntu with apache server
RUN apt-get update
ARG DEBIAN_FRONTEND=noninteractive # for remove time zone
RUN apt-get -y install apache2
ADD . /var/www/html
ENTRYPOINT apachectl -D FOREGROUND
ENV name Vishal # anything you can give
I am trying to provision an ubuntu/trusty64 vagrant box with Apache 2.4 and PHP 7.0 but have not succeeded.
This is my provisions.sh script:
#!/usr/bin/env bash
# Vagrant instance provision script
# Php 7.0
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update
sudo apt-get install php7.0 -y
# Apache 2.4
sudo add-apt-repository ppa:ondrej/apache2 -y
sudo apt-get update
sudo apt-get install apache2 -y
if ! [ -L /var/www ]; then
rm -rf /var/www/html
ln -fs /vagrant /var/www/html
fi
When I vagrant up, apache works fine but PHP does not. However, if I remove the PHP installation line,
sudo apt-get install php7.0 -y
and execute it from the command line after the VM is running, PHP works fine.
Any ideas why this is or how to fix the provisioning of the box so that PHP works from the start?
The initial question already contains the answer. It is the order in which the commands are being executed. If PHP gets installed before Apache is installed, then certain configuration files will not automatically be configured. This can be done manually, but requires certain know-how. I yet have to come across easy tutorials or manuals.
#!/usr/bin/env bash
# Vagrant instance provision script
# Php 7.0
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update
# Apache 2.4
sudo add-apt-repository ppa:ondrej/apache2 -y
sudo apt-get update
sudo apt-get install apache2 -y
if ! [ -L /var/www ]; then
rm -rf /var/www/html
ln -fs /vagrant /var/www/html
fi
# Changed this line
sudo apt-get install php7.0 -y
I too have been facing this issue. So hopefully with this answer I provide some help to others.
I'm trying to recover from a recent problem upgrading to apache2.4 and php 5.5. I've uninstalled apache2 and deleted the /etc/apache2 folder but when I install apache2.2 it's not creating /etc/apache2 folder so doesn't start.
Do as below:
sudo apt-get update
sudo apt-get remove apache2
sudo apt-get purge apache2
sudo apt-get update
sudo apt-get install apache2
Do as following
sudo apt-get remove --purge apache2 apache2-utils
sudo apt-get install --reinstall apache2 apache2-utils