Linux 从 bash 启动 apachectl
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9348204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
starting apachectl from bash
提问by Behnam Safari
I am writing a bash file. I need to start apachectl
from my bash file. so i wrote:
我正在写一个 bash 文件。我需要apachectl
从我的 bash 文件开始。所以我写道:
apachectl start
When I run it with root, an error occurred:
当我用 root 运行它时,发生了一个错误:
apachectl: command not found
I searched and I found that, I should be super userwith su -
not su
我搜索并发现,我应该是超级用户而su -
不是su
Now, I want to know:
现在,我想知道:
why this error occurred?
How could i run it with
su
?
为什么会出现这个错误?
我怎么能运行它
su
?
采纳答案by Resorath
The command not found error is because "apachectl" is not in your path. Simply use the full path of the command, e.g.
命令未找到错误是因为“apachectl”不在您的路径中。只需使用命令的完整路径,例如
/etc/init.d/apachectl start
/etc/init.d/apachectl start
If you get a permission denied error, then you need to run as a different user. That is a different problem though.
如果您收到权限被拒绝错误,则您需要以其他用户身份运行。不过,这是一个不同的问题。
回答by taro
In shell scripts you should use full paths in order to execute command unless directory with executable already in $PATH. For instance, find where apachectl binary is located:
在 shell 脚本中,您应该使用完整路径来执行命令,除非 $PATH 中已经存在可执行文件的目录。例如,找到 apachectl 二进制文件所在的位置:
which apachectl
or
或者
whereis apachectl
and you will get something like:
你会得到类似的东西:
/usr/local/sbin/apachectl
So, use that.
所以,用那个。
回答by Mithrandir
It seems, that the command apachectl
is not in your environments path. Locate the directory, where apachectl
resides and add this to your PATH
or start it with the full path. Most modern distributions use sudo
to allow users gain elevated rights, so you should use sudo
, if available to you.
看来,该命令apachectl
不在您的环境路径中。找到apachectl
所在的目录并将其添加到您的PATH
或使用完整路径启动它。大多数现代发行版都sudo
用于允许用户获得更高的权限,因此您应该使用sudo
,如果您可以使用。
回答by Jayden Lawson
Use the find command to first locate apachecetl
使用find命令首先定位apachecetl
find / -name apachectl
Then you can test it by running the status command (assuming this is the location from the find command)
然后你可以通过运行 status 命令来测试它(假设这是来自 find 命令的位置)
/usr/local/sbin/apachectl status
Then you may need to restart apache if there's an issue
如果出现问题,您可能需要重新启动 apache
/usr/local/apache/bin/apachectl restart
回答by diegohsi
First kill all httpd service using...
首先使用...杀死所有httpd服务
sudo killall -9 httpd
Second, find apachectl. Press ctrl+r into terminal enter a "apachectl" word To find the path of "apachectl".
其次,找到apachectl。按ctrl+r进入终端输入“apachectl”字样来查找“apachectl”的路径。
After select:
选择后:
sudo <path>/apachectl stop|start
回答by sudheerchamarthi
Below command worked for me:
以下命令对我有用:
sudo /usr/sbin/apachectl -kstart
须藤/usr/sbin/apachectl -kstart
回答by Sergio Arce Barrera
well, it happens why you port be used now other service. for you know that
好吧,这就是为什么您现在使用其他服务的端口。因为你知道
service is use write next comand of netstat:
服务是使用写netstat的下一个命令:
- sudo netstat -tanp.
- 须藤 netstat -tanp。
if you wanna to know of port 8080 use next comand:
如果你想知道端口 8080 使用下一个命令:
- trong textsudo ss -ntlp 'sport = 80'.
- trong textsudo ss -ntlp 'sport = 80'。
in my case was run lighttpd so apply next comand:
在我的情况下运行 lighttpd 所以应用下一个命令:
- sudo apt-get remove lighttpd.
- sudo apt-get 删除 lighttpd。