ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    What would be the best way to script create an Apache vhost file.

    IT Discussion
    linux apache vhost scripting bash because im lazy
    2
    3
    1.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JaredBuschJ
      JaredBusch
      last edited by

      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.

      1 Reply Last reply Reply Quote 1
      • scottalanmillerS
        scottalanmiller
        last edited by scottalanmiller

        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.

        1 Reply Last reply Reply Quote 0
        • scottalanmillerS
          scottalanmiller
          last edited by scottalanmiller

          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
          
          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post