sudo apachectl start not working - apache

Before I could use terminal to start Apache service as:
sudo apachectl start
But recently it doesn't work, even after I restart my PC. Instead, I can use XAMPP to start Apache easily. Who can tell me why the terminal doesn't work at all?
Besides, since I'm a beginner with command line, I know the statement
ps aux | grep httpd
can show if apache is running. But I don't know the exact meaning of each field, like:
yy 1708 0.0 0.0 2432772 604 s000 R+ 8:05PM 0:00.00 grep httpd
what does those numbers or characters mean? Is anyone can help? Thanks!

Try sudo apachectl configtest to check that nothing prevents Apache from starting like a syntax error in one of its config files.
If it can't start, then it must throw an error in its log, check in var/log/, ususally there's a apache2 or httpd folder there, containing error and access logs.
The numbers of the ps aux command are explained at the top of each column when you run this command without any grep pipe (which strips the header, because nothing matches httpd in the first line).
More info here: https://www.wikiwand.com/en/Ps_(Unix).
In your case, httpd is not obviously not running since you only get your own ps command as a result so the numbers don't really matter ;-)

Related

Docker Centos 7 image running Apache2 "DocumentRoot ... is not readable"

I have a docker container running a Centos 7 image. All it needs to do is run a simple Apache2 server. When the container starts it exits immediately with:
AH00526: Syntax error on line 119 of /etc/httpd/conf/httpd.conf:
DocumentRoot '/var/www/html' is not a directory, or is not readable
I did some basic checks:
Folder exists
Permissions are ```rwx r_x r_x root root```` for each folder /var/www/html
Tried chown -R apache /var/www (no straw shall remain unclutched!)
SELinux is disabled (... or is it?)
When I enter the container with a bash entry point, I can then start apache as root with /sbin/httpd -D FOREGROUND and everything works as expected.
So I think its almost certainly a permissions thing. Googling found many pages with my error e.g.
Apache restart causes DocumentRoot must be a directory, even though it is a directory and there seem to be no privilege issues
This particular page closely describes what I am getting and the solution in almost every page is configure SELinux. However SELinux is disabled. Even in that link there is comment from the OP
My version of linux isn't Security Enhanced Linux, so without understanding I tried it anyway: no effect.
Yet they accepted the solution which was configure SELinux.
I think I am missing something, almost certainly SELinux related, but I can't figure it out. The docker image has the following (distinct lack of) SELinux settings:
/etc/selinux contains only semanage.conf and tmp/ (empty)
/usr/sbin contains no se* executables
rpm -qa | grep selinux
libselinux-2.5-12.el7.x86_64
/etc/sysconfig/selinux does not exist
So in the Dockerfile I tried RUN echo "SELINUX=disabled" > /etc/sysconfig/selinux
doing yum install -y policycoreutils installs sestatus in /usr/sbin. Running sestatus gives
SELinux status: disabled
With or without /etc/sysconfig/selinux
It really looks like SELinux is disabled, yet the error looks so much like it is enabled.
The issue in this case was due to the way the container was launched.
I use docker-compose to launch this particular container but the paths for the volume mapping were incorrect.
I am still not sure why this causes apache to fail to start in the way it does but correcting the paths fixed the issue.

XAMPP apache will not start

I had to reinstall my max with El capitan, and I had XAMPP working with mysql and apache able to start servers. Now my apache server isn't able to start so I can't get to phpmyadmin to do some schoolwork.
I've looked around and saw that it could be a port 80 or 81 issue, so I checked and saw that no applications were currently using the port, either way I still got a no go.
I tried through terminal to see an error message,
Starting XAMPP for Mac OS X 5.6.30-0...
XAMPP: Starting Apache...fail.
XAMPP: Starting diagnose...
XAMPP: Sorry, I've no idea what's going wrong.
XAMPP: Please contact our forum http://www.apachefriends.org/f/
Last 10 lines of "/Applications/XAMPP/xamppfiles/logs/error_log":
tail: /Applications/XAMPP/xamppfiles/logs/error.log: No such file or directory
XAMPP: Starting MySQL...ok.
Contents of "/Applications/XAMPP/xamppfiles/var/proftpd/start.err":
C02L58UUFFT1.corp.proofpoint.com proftpd[1780]: warning: unable to determine IP address of 'C02L58UUFFT1.corp.proofpoint.com'
C02L58UUFFT1.corp.proofpoint.com proftpd[1780]: error: no valid servers configured
C02L58UUFFT1.corp.proofpoint.com proftpd[1780]: Fatal: error processing configuration file '/Applications/XAMPP/xamppfiles/etc/proftpd.conf'
C02L58UUFFT1:~ sblomquist$ lsof -i ':80'
C02L58UUFFT1:~ sblomquist$ lsof -i ':81'
Thought I would post my problem here while I browse around for more possible solutions.
Update your system and install net-tools
On ubuntu, sudo apt update then sudo apt install net-tools -y restart your server

Apachectl looking into wrong directory

I was trying to make apache mysql php and phpmyadmin running together and following this instructions https://echo.co/blog/os-x-1010-yosemite-local-development-environment-apache-php-and-mysql-homebrew I made a big mistake.
When I run on the terminal apachectl configtest or apachectl start, etc It looking into /usr/local/etc/apache2/2.2/httpd.conf and I want to restore to the original location.
I have my apache runnning http://localhost and is 2.4 because when I try http://localhost/test.php ( < ? php phpinfo() ?> ) and it says "Apache Version Apache/2.4.16 (Unix) PHP/5.5.29" but when I want to see the version apachectl -v it says is 2.2 and I know that I had per default 2.4 I want to restore all the changes that I made on apache and get rid of what I did with the other tutorial.
I don't mind if I cant use apachectl anymore but I want to know how can I continue control de apache 2.4 that is on the mac start,restart and stop commands.
I found the solution doing apachectl -V go to the root of config placed on /Cellar and paste the httpd.conf with the original.

httpd does not work (-bash: httpd: command not found)

I am on someone else's linux server (shared hosting). I do not have root access. I have determined that it's a Redhat 4.1.2-46 running as Centos Release 5.9(Final).
I have the database dump for the site and the .php files from public_html as well. What I'm TRYING TO DO is locate the httpd.conf file and get the config for that site.
when I type in
httpd - v
I get -bas: httpd: command not found - even in like the /user/sbin directory - and it's clearly running and there.
Bottom line I can't find the sitedef/conf file for www.thisparticularsite.com - and can't even figure out what version of apache I'm running...
For Apache 2 try apache2ctl -v (or sudo apache2ctl -v if root access is available). I'm on a Raspberry Pi 4B running Debian, just for reference.
The init files of apache are usually located in /etc/init.d the httpd path are found in it. However, You can find out where the httpd.conf file and httpd command directory by doing a ps aux|grep -i http. For example:
ps aux|grep -i http
510 2594 0.0 0.0 77256 1516 ? S Jul02 0:00 **/usr/sbin/httpd-0.0.0.0_80** -k start -f **/etc/httpd/conf/instances/httpd-0.0.0.0_80/httpd.conf**
root 5470 0.0 0.0 77120 872 ? Ss 2013 22:13 **/usr/sbin/httpd-0.0.0.0_80** -k start -f **/etc/httpd/conf/instances/httpd-0.0.0.0_80/httpd.conf**
Conclusion:
httpd.conf file path: **/etc/httpd/conf/instances/httpd-0.0.0.0_80/httpd.conf**
httpd command directory: **/usr/sbin/httpd-0.0.0.0_80**
As mentionned by apache.org, httpd command should not be invoked directly.
see source
If you're trying to find loaded modules, earlier the command was httpd -l. But it'll give you the same error, Command 'httpd' not found,
Nowadays, you can use apache2 -l (tested on Apache/2.4.29).

There are processes named 'apache2' running

help me resolve this error in apache
/etc/init.d/apache2 restart
error:
There are processes named 'apache2' running which do not match your pid file which are left untouched in the name of safety, Please review the situation by hand.
thanks
Kill them.
kill -9 $(ps -e | grep apache2 | awk '{print $1}')
Before killing the process, maybe, you would like to check if the pid file path set in
/etc/apache2/apache2.conf
equals the one stated in APACHE_PID_FILE environment variable exported in the :
/etc/apache2/envvars
file.
Saving a process snapshot before proceeding to kill, would be helpful :
# top -b -n1 > /tmp/process.log
Then get the pid of apache2 with :
pidof apache2
It output the related processes id(s) e.g 4920 4919. Then kill them with :
sudo kill -9 pid
replacing pid with the process id(s) you got from the previous output.
Finally restart Apache 2 server :
sudo /etc/init.d/apache2 restart
Next time would be helpful letting others know basic things about your OS distro etc.
Hope it helps someone.
none of these answers worked.. this did
kill -9 $(pidof apache2)