What would be the best way to script create an Apache vhost file.
-
So I finally setup Observium on CentOS & this evening.
At one point, the instructions state that you need to setup the vhost settings for Apache.
Well this is easy enough, but I want something that I can copy/paste or even eventually put into a one liner with semicolons.
I know I can use sed to replace pieces in an existing text file.
#replace the default username and password as just setup sed -i 's/USERNAME/someuser/' /opt/observium/config.php sed -i 's/PASSWORD/somepassword/' /opt/observium/config.php
I know I can use touch to create a new file.
#create vhost file for website sudo touch /etc/httpd/conf.d/observium.conf
Now I need to get this information into observium.conf
<VirtualHost *:80> DocumentRoot /opt/observium/html/ ServerName observium.domain.com CustomLog /opt/observium/logs/access_log combined ErrorLog /opt/observium/logs/error_log <Directory "/opt/observium/html/"> AllowOverride All Options FollowSymLinks MultiViews Require all granted </Directory> </VirtualHost>
What would be the best way to handle that? Obviously I can open vi or nano and paste it in, but I don't want to do that.
-
If you have a block of pre-existing text ready to go in a script that you want to get into a file you generally do it using an cat command.
-
Like this...
cat > observium.conf <<'_EOF' <VirtualHost *:80> DocumentRoot /opt/observium/html/ ServerName observium.domain.com CustomLog /opt/observium/logs/access_log combined ErrorLog /opt/observium/logs/error_log <Directory "/opt/observium/html/"> AllowOverride All Options FollowSymLinks MultiViews Require all granted </Directory> </VirtualHost> _EOF