How to start Apache by specifying httpd.conf with systemd (CentOS7, CentOS8)

I will show you how to start * Apache * with * httpd.conf * in * systemd * of * CentOS7 * or * CentOS8 *.

Operation check environment

Start with myhttpd.conf instead of httpd.conf

It is assumed that the configuration file myhttpd.conf that you want to use when starting * Apache * exists under the / etc / httpd / conf directory.

1. Modify httpd.service

Modify the * Apache * * systemd * unit definition file /usr/lib/systemd/system/httpd.service.

The httpd.service before modification is as follows.

/usr/lib/systemd/system/httpd.service (before modification)


[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target

The modified `httpd.service` is as follows.

/usr/lib/systemd/system/httpd.service (after modification)


[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target

The difference of `httpd.service` is as follows.

/usr/lib/systemd/system/httpd.service (difference)


-ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
-ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
+ExecStart=/usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf $OPTIONS -DFOREGROUND
+ExecReload=/usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf $OPTIONS -k graceful

2. Start Apache

Start * Apache * with the unit definition file (httpd.service) modified by the following command. systemctl start httpd

Execution result


[root@CENTOS7 ~]# systemctl start httpd
[root@CENTOS7 ~]#

Check the * Apache (httpd) * process with the following command and make sure it is started in /etc/httpd/conf/myhttpd.conf. ps -ef | grep httpd

Execution result


[root@CENTOS7 ~]# ps -ef | grep httpd
root      1332     1  0 22:20 ?        00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache    1333  1332  0 22:20 ?        00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache    1334  1332  0 22:20 ?        00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache    1335  1332  0 22:20 ?        00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache    1336  1332  0 22:20 ?        00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache    1337  1332  0 22:20 ?        00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
root      1341  1295  0 22:21 pts/0    00:00:00 grep --color=auto httpd
[root@CENTOS7 ~]#

Other

This time, I added -f /etc/httpd/conf/myhttpd.conf directly to ʻExecStart and ʻExecReload of /usr/lib/systemd/system/httpd.service, but make it a variable. You can also. Refer to the following for how to use variables in the unit definition file.

How to use variables in systemd Unit definition file

that's all

Recommended Posts

How to start Apache by specifying httpd.conf with systemd (CentOS7, CentOS8)
How to install Apache (httpd) on CentOS7
How to install Apache (httpd) on CentOS8
How to install python3 with docker centos
[Django] How to get data by specifying SQL.
[CentOS8] How to output Python standard output to systemd log
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
[Automatic test] How to start making automatic test during runtime with Airtest
[Cyberduck] How to exchange files on Linux (CentOS7) started by VirtualBox with mac using GUI
How to update with SQLAlchemy?
How to cast with Theano
How to calculate space background X-ray radiation (CXB) with python by specifying the flux range
How to separate strings with','
How to RDP with Fedora31
How to Delete with SQLAlchemy?
How to start the program
How to batch start a python program created with Jupyter notebook
How to cancel RT with tweepy
Python: How to use async with
How to use virtualenv with PowerShell
How to deal with imbalanced data
How to install python-pip with ubuntu20.04LTS
How to deal with imbalanced data
How to install PyPy on CentOS
How to get started with Python
How to deal with DistributionNotFound errors
How to get started with Django
How to Data Augmentation with PyTorch
How to calculate date with python
How to install mysql-connector with pip3
How to install Maven on CentOS
How to INNER JOIN with SQLAlchemy
How to install Anaconda with pyenv
How to authenticate with Django Part 2
How to authenticate with Django Part 3
To connect to WIFI that is restricted by MAC address with CentOS (NetworkManager).
Build a CentOS Linux 8 environment with Docker and start Apache HTTP Server
Set up reverse proxy to https server with CentOS Linux 8 + Apache mod_ssl
How to sort by specifying a column in the Python Numpy array.
How to deal with old Python versions in Cloud9 made by others
[Blender] How to set shape_key with script
How to title multiple figures with matplotlib
How to get parent id with sqlalchemy
How to add a package with PyCharm
How to install DLIB with 2020 / CUDA enabled
How to use ManyToManyField with Django's Admin
How to use OpenVPN with Ubuntu 18.04.3 LTS
How to use Cmder with PyCharm (Windows)
Searching for properties to start with TensorFlow-Part 1
How to prevent package updates with apt
How to work with BigQuery in Python
How to use Ass / Alembic with HtoA
Install by specifying the version with pip
How to deal with enum compatibility errors
How to do portmanteau test with python
How to search Google Drive with Google Colaboratory
CentOS 6.4 with Python 2.7.3 with Apache with mod_wsgi and Django
How to download youtube videos with youtube-dl
How to use jupyter notebook with ABCI
How to enable SSL (TLS) in Apache
How to switch mouse operations on CentOS