0

I have manually extracted and installed Apache server on my machine i.e. CentOs 7
Now I want to write a service script to start ,stop, etc Apache Server [ httpd ] for systemd.

How do I do that ?

What I have installed:

  1. apr-1.5.1.tar.gz
  2. apr-util-1.5.3.tar.gz
  3. pcre-8.35.tar
  4. openssl-1.0.2a.tar.gz
  5. httpd-2.4.9.tar.gz

Default httpd service Script is as :

.include /usr/lib/systemd/system/httpd.service

[Service]
Environment=KRB5CCNAME=/var/run/httpd/ipa/krbcache/krb5ccache
Environment=KDCPROXY_CONFIG=/etc/ipa/kdcproxy/kdcproxy.conf
ExecStartPre=/usr/libexec/ipa/ipa-httpd-kdcproxy
ExecStopPost=-/usr/bin/kdestroy -A
  • 2
    Please elaborate, what have you tried? Did you check the systemd man pages? They have quite a lot of information. You could also check the unit file that is shipped by CentOS with the default httpd package. Perhaps you could also explain why you can't or don't want to use the default packages as most of the packages you list appear to be available in the default repos. – Bram May 5 '17 at 11:23
4

It's not clear what you are asking. Usually you just install from repositories and it is all created for you, but if you need to do all the work manually you should bear in mind that you probably want to use the command apachectl.

You should be able to achieve whatever it is you want to achieve just by reading the content of my /usr/lib/systemd/system/httpd.service file:

[Unit]
Description=Apache Web Server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/httpd/httpd.pid
ExecStart=/usr/sbin/apachectl start
ExecStop=/usr/sbin/apachectl graceful-stop
ExecReload=/usr/sbin/apachectl graceful
PrivateTmp=true
LimitNOFILE=infinity

[Install]
WantedBy=multi-user.target
  • thanks, I think this is default service I have to changed path to my apache installed directory, – shantaram May 6 '17 at 5:18
  • 1
    Beware on Centos7 with Apache httpd 2.4 installed from the repos (yum, dnf), that apachectl no longer directly starts httpd, but instead is just a wrapper that makes systemctl calls. The httpd.service systemd unit file that gets installed by default with the RPM actually starts httpd directly. Under this configuration, if you wrote a unit file that called apachectl, it would simply loop. Ref lists.fedoraproject.org/pipermail/scm-commits/2012-January/… & pkgs.fedoraproject.org/cgit/rpms/httpd.git/commit/… – Joshua Huber Oct 19 '17 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.