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

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).

Related

Homebrew Apache directories on MacOS Big Sur

I went thru any tutorial I could find to install and configure Apache on Big Sur. Invariably, the tutorial when discussing the config files will point to /usr/local/etc/httpd/httpd.conf that needs to be massaged a bit. The only trouble is that the file doesn't exist when I check that dir. Any idea? Thanks for your help in advance.
EDIT: I did an uninstall and install of httpd per requested and I still don't get the /usr/local/. There must be something different the homebrew configuration.
โžœ ~ brew uninstall httpd
Uninstalling /opt/homebrew/Cellar/httpd/2.4.49... (1,660 files, 31.9MB)
โžœ ~ brew install httpd
==> Downloading https://ghcr.io/v2/homebrew/core/httpd/manifests/2.4.49
Already downloaded: /Users/johnny/Library/Caches/Homebrew/downloads/6c60d66c3915be5c993e144a743960b9e6be26e557efeeb6c61f530c79ffed34--httpd-2.4.49.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/httpd/blobs/sha256:e6ebcb4a1307
Already downloaded: /Users/johnny/Library/Caches/Homebrew/downloads/8506f199d5d7def536481d6fa87aa94c25201b57072d032e97edb8ce78fa86a3--httpd--2.4.49.arm64_big_sur.bottle.tar.gz
==> Pouring httpd--2.4.49.arm64_big_sur.bottle.tar.gz
==> Caveats
DocumentRoot is /opt/homebrew/var/www.
The default ports have been set in /opt/homebrew/etc/httpd/httpd.conf to 8080 and in
/opt/homebrew/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.
To restart httpd after an upgrade:
brew services restart httpd
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND
==> Summary
๐Ÿบ /opt/homebrew/Cellar/httpd/2.4.49: 1,660 files, 31.9MB
โžœ ~
[Edited and updated]
I am using macOS Catalina 10.15.7 / Xcode-select version 2373 and by running $ brew install httpd I can install the Apache service under /usr/local/
Can you please remove and install it again by using the same command and sharing all the output?
These are the important things:
DocumentRoot is /usr/local/var/www.
The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in
/usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.
To start httpd:
brew services start httpd
Or, if you don't want/need a background service you can just run:
/usr/local/opt/httpd/bin/httpd -D FOREGROUND
This is the list of directories.
$ ls -lrt /usr/local/etc/httpd
total 200
drwxr-xr-x 14 user admin 448 Sep 22 23:35 extra
-rw-r--r-- 1 user admin 21222 Sep 22 23:35 httpd.conf
-rw-r--r-- 1 user admin 13064 Sep 22 23:35 magic
-rw-r--r-- 1 user admin 60847 Sep 22 23:35 mime.types
drwxr-xr-x 4 user admin 128 Sep 22 23:35 original
And this is my test showing it is working.
$ curl localhost:8080
<html><body><h1>It works!</h1></body></html>
$ tail -f /usr/local//var/log/httpd/access_log
::1 - - [22/Sep/2021:23:39:35 -0500] "GET / HTTP/1.1" 200 45
Based on your output and the brew documentation I believe you are using Apple Silicon is that correct, can you confirm?
https://docs.brew.sh/Installation
This script installs Homebrew to its preferred prefix (/usr/local for macOS Intel, /opt/homebrew for Apple Silicon, and /home/linuxbrew/.linuxbrew for Linux) so that you donโ€™t need sudo when you brew install. It is a careful script; it can be run even if you have stuff installed in the preferred prefix already. It tells you exactly what it will do before it does it too. You have to confirm everything it will do before it starts.

How do I check the apache config for validity in Red Hat Linux?

My operating system is Red Hat Enterprise Linux 7. This isn't working...
# httpd -t
bash: httpd: command not found
In case it helps, this is the command I run to restart apache on this box...
# systemctl restart httpd24-httpd
But this doesn't work...
# httpd24-httpd -t
bash: httpd24-httpd: command not found
This doesn't work either...
# apachectl -t
bash: apachetl: command not found
Nor does this work...
# apachectl configtest
bash: apachetl: command not found
I know this is a couple months old but ended up here. I ran into the same issue initially, hence why I am here. I found that the location for the new httpd24-httpd wasn't in my env path to execute. While I could added it there, I found the command location and was able to execute.
How I found the command:
sudo find / -name apachectl
The output of the command:
/opt/rh/httpd24/root/usr/sbin/apachectl
Executed the command:
sudo /opt/rh/httpd24/root/usr/sbin/apachectl
Turns out I have to fix my configuration.
httpd: Syntax error on line 56 of /opt/rh/httpd24/root/etc/httpd/conf/httpd.conf: Syntax error on line 40 of /opt/rh/httpd24/root/etc/httpd/conf.modules.d/00-base.conf: Cannot load modules/mod_http2.so into server: libnghttp2-httpd24.so.14: cannot open shared object file: No such file or directory
Interesting that this came up for me, as I've not done anything with the configuration in this regard.
Here's the version I am running.
sudo /opt/rh/httpd24/root/usr/sbin/apachectl -v
Server version: Apache/2.4.34 (Red Hat)
Server built: Mar 17 2020 09:34:59
All the best!
Found something more for this as well from an old bug submitted to Redhat
Bug 1329639
Comment 10
scl enable httpd24 -- /opt/rh/httpd24/root/usr/sbin/apachectl configtest

httpd (apache) centos fail to open stream: Permission denied

i'm facing the next error in a centos 7 server
I take a look to similar questions saying that is because SELinux doesn't allow to httpd to write in my /home folder, i've tried changing the owner of the folder without success; try changing the context (chcon) to httpd_sys_rw_content_t of my /home with the same error; try disabling SELinux and the error persists; and in the file httpd.conf change the User and Group from apache to test this didn't work either. My server is:
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.4.1708 (Core)
Release: 7.4.1708
Codename: Core
and
Linux localhost 3.10.0-693.17.1.el7.x86_64 #1 SMP Thu Jan 25 20:13:58 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
When I execute move_uploaded_file() from php -a as user test it works normally, i see that the issue is with the user apache
TLDR:
Do not run setenforce 0 command, this will disable SELinux! You should not disable SELinux for security reasons.
The solution:
You should update policy to make SELinux allow read and write on specific directories:
To allow apcahe to read and write.
chcon -R -t httpd_sys_rw_content_t /path/your_writabl_dir
For read only directories:
chcon -R -t httpd_sys_content_t /path/yourdir
For example you can make your public (document root) directory read only and only allow write on directories that you allow you app to write on:
# Make all read only
chcon -R -t httpd_sys_content_t /var/www/myapp
# Only allow write on uploads dir for example
chcon -R -t httpd_sys_rw_content_t /var/www/myapp/public/uploads

sudo apachectl start not working

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 ;-)

Apache server is running but httpd is not running

I'm facing a weird problem. When I access the web-accessible directory of my server via domain linked to it. It says:-
Not Found
The requested URL / was not found on this server.
When I run this command on my server (via putty), it displays few processes ids demonstrating that Apache web server is running (correct me).
root#...:~# pgrep apache
4733
13505
13506
13507
13508
13686
14199
17672
But when I run this command, it says that httpd: unrecognized service
root#...:~# service httpd status
httpd: unrecognized service
Some other commands output:-
root#...:~# ps aux|grep -i http
root 29401 0.0 0.0 6460 792 pts/0 S+ 02:21 0:00 grep --color=auto -i http
How can I fix this?
Update:-
root#...:~# chkconfig --list | grep httpd
-bash: chkconfig: command not found
root#...:~# find / -name httpd*
/var/www/vhosts/lvps5-35-241-230.dedicated.hosteurope.de/httpdocs
/var/www/vhosts/.skel/0/httpdocs
/opt/psa/var/httpd_restart
/usr/lib/apache2/modules/httpd.exp
/usr/share/doc/apache2-doc/manual/fr/programs/httpd.html
/usr/share/doc/apache2-doc/manual/pt-br/programs/httpd.html
/usr/share/doc/apache2-doc/manual/da/programs/httpd.html
/usr/share/doc/apache2-doc/manual/zh-cn/programs/httpd.html
/usr/share/doc/apache2-doc/manual/tr/programs/httpd.html
/usr/share/doc/apache2-doc/manual/en/programs/httpd.html
/usr/share/doc/apache2-doc/manual/ja/programs/httpd.html
/usr/share/doc/apache2-doc/manual/ko/programs/httpd.html
/usr/share/doc/apache2-doc/manual/de/programs/httpd.html
/usr/share/doc/apache2-doc/manual/es/programs/httpd.html
/usr/share/doc/apache2-doc/examples/apache2/original/httpd.conf.gz
/usr/share/doc/apache2-doc/examples/apache2/original/extra/httpd-autoindex.conf
/usr/share/doc/apache2-doc/examples/apache2/original/extra/httpd-manual.conf
/usr/share/doc/apache2-doc/examples/apache2/original/extra/httpd-userdir.conf
/usr/share/doc/apache2-doc/examples/apache2/original/extra/httpd-vhosts.conf
/usr/share/doc/apache2-doc/examples/apache2/original/extra/httpd-languages.conf.gz
/usr/share/doc/apache2-doc/examples/apache2/original/extra/httpd-ssl.conf.gz
/usr/share/doc/apache2-doc/examples/apache2/original/extra/httpd-mpm.conf.gz
/usr/share/doc/apache2-doc/examples/apache2/original/extra/httpd-multilang-errordoc.conf
/usr/share/doc/apache2-doc/examples/apache2/original/extra/httpd-default.conf
/usr/share/doc/apache2-doc/examples/apache2/original/extra/httpd-dav.conf
/usr/share/doc/apache2-doc/examples/apache2/original/extra/httpd-info.conf
/usr/share/doc/apache2-doc/examples/apache2/extra/httpd-autoindex.conf
/usr/share/doc/apache2-doc/examples/apache2/extra/httpd-manual.conf
/usr/share/doc/apache2-doc/examples/apache2/extra/httpd-userdir.conf
/usr/share/doc/apache2-doc/examples/apache2/extra/httpd-vhosts.conf
/usr/share/doc/apache2-doc/examples/apache2/extra/httpd-languages.conf.gz
/usr/share/doc/apache2-doc/examples/apache2/extra/httpd-ssl.conf.gz
/usr/share/doc/apache2-doc/examples/apache2/extra/httpd-mpm.conf.gz
/usr/share/doc/apache2-doc/examples/apache2/extra/httpd-multilang-errordoc.conf
/usr/share/doc/apache2-doc/examples/apache2/extra/httpd-default.conf
/usr/share/doc/apache2-doc/examples/apache2/extra/httpd-dav.conf
/usr/share/doc/apache2-doc/examples/apache2/extra/httpd-info.conf
/etc/apache2/httpd.conf
/etc/apache2/httpd.pem
root#...:~# whereis httpd
httpd:
root#...:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.5 LTS
Release: 12.04
Codename: precise
root#...:~# ls /etc/init.d
README hostname network-interface-container plymouth-upstart-bridge rc spamassassin udevtrigger
apache2 hwclock network-interface-security portmap rc.local ssh umountfs
bind9 hwclock-save networking portmap-wait rcS stop-bootlogd umountnfs.sh
bluetooth keymap.sh ondemand postfix reboot stop-bootlogd-single umountroot
bootlogd killprocs passwd procps rpcbind-boot sudo unattended-upgrades
console-screen.sh klogd pc-remote psa rsync sw-cp-server urandom
courier-imap module-init-tools plymouth psa-firewall saslauthd sysklogd wide-dhcpv6-client
cron modules_dep.sh plymouth-log psa-firewall-forward screen-cleanup udev x11-common
dbus mongodb plymouth-ready psa-spamassassin sendsigs udev-fallback-graphics xinetd
fetchmail mysql plymouth-splash quota single udev-finish
halt network-interface plymouth-stop quotarpc skeleton udevmonitor
root#...:~# ls /etc/xinetd.d
chargen daytime discard echo ftp_psa poppassd_psa time
Is httpd listed in your /etc/xinetd, /etc/xinet.d, /etc/xinitd.d, or /etc/init.d directory? Also use chkconfig to see if httpd is listed.
# chkconfig --list | grep httpd
If it's not:
# find / -name httpd*
or
# whereis httpd
to find where it might be installed at. Then I'd make a symbolic link to it in (depending on you linux / unix flavor) /etc/xinetd, /etc/xinet.d, /etc/xinitd.d, or /etc/init.d.