We are going to set up "stage" (UAT) and "prod" environments, which jobs in our CI/CD pipeline can then target.
We'll put Stage and Prod on the same server, for expediency for the tutorial.
Install Apache2 and change the port to 8008 (since GitLab is listening on 80).
sudo apt-get update; \
sudo apt install -y apache2 php libapache2-mod-php; \
sudo sed -i /etc/apache2/ports.conf -e 's:Listen 80:Listen 8008:'; \
sudo service apache2 start; \
curl http://localhost:8008/ | grep -i welcome --max-count=1
Add stage.example.com
and prod.example.com
to the localhost
record in /etc/hosts
so we can test the vhosts from our lab Linux server. Also add gitlab.example.com
, so that you can copy and paste my git clone
examples later without fiddling with the hostname.
Run:
sudo sed -e 's:^127.0.0.1.*:127.0.0.1 localhost stage.example.com prod.example.com gitlab.example.com:' -i /etc/hosts
sudo mkdir /var/www/stg-html
echo "<?php echo '<p>Stage - Hello World</p>'; ?>" | sudo tee /var/www/stg-html/index.php
Set up httpd config for the "stage" virtual host:
cat <<EOF | sudo tee /etc/apache2/sites-available/001-stg.conf
<VirtualHost *:8008>
ServerName stage.example.com
DocumentRoot /var/www/stg-html
ErrorLog ${APACHE_LOG_DIR}/stg.error.log
CustomLog ${APACHE_LOG_DIR}/stg.access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
EOF
Enable vhost:
sudo ln -s /etc/apache2/sites-available/001-stg.conf /etc/apache2/sites-enabled/
sudo service apache2 reload
Test it, it should say <p>Stage - Hello World</p>
.
curl http://stage.example.com:8008/
Example:
root@ip-172-31-27-145:~# curl http://stage.example.com:8008/
<p>Stage - Hello World</p>root@ip-172-31-27-145:~#
root@ip-172-31-27-145:~#
sudo mkdir /var/www/prod-html
echo "<?php echo '<p>Prod - Hello World</p>'; ?>" | sudo tee /var/www/prod-html/index.php
cat <<EOF | sudo tee /etc/apache2/sites-available/002-prod.conf
<VirtualHost *:8008>
ServerName prod.example.com
DocumentRoot /var/www/prod-html
ErrorLog ${APACHE_LOG_DIR}/prod.error.log
CustomLog ${APACHE_LOG_DIR}/prod.access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
EOF
Enable and activate the new site:
sudo ln -s /etc/apache2/sites-available/002-prod.conf /etc/apache2/sites-enabled/
sudo service apache2 reload
Test it:
curl http://prod.example.com:8008/
You should see <p>Prod - Hello World</p>
.