Skip to main content

Lab 5.6 - Installation of WordPress and GLPI on a Linux Server (Ubuntu 24.04)

Objectives​

By the end of this lab, you will be able to:

  • Install and configure Apache with multiple VirtualHosts
  • Install and configure MariaDB with multiple databases
  • Install WordPress and GLPI on distinct ports
  • Configure permissions and security
  • Use shell scripts to automate installation
  • Manage web services and databases

Prerequisites​

  • Ubuntu 24.04 installed
  • Sudo/root access
  • At least 2 GB of available RAM
  • At least 5 GB of free disk space
  • Internet connection

Overview​

This guide provides instructions and shell scripts to install WordPress and GLPI on a Linux Ubuntu 24.04 server. Both applications will use distinct ports and users to avoid any conflict.

Architecture:

  • WordPress: Port 8080, database wordpressdb, user wordpressuser
  • GLPI: Port 8081, database glpidb, user glpiuser

Part 1: Installing WordPress​

Step 1: Create the installation script​

Create a script file for WordPress:

nano install_wordpress.sh

Step 2: Script content​

Copy the following content into the file:

#!/bin/bash

# Update packages and install necessary components
sudo apt update
sudo apt install -y apache2 php php-{mysql,xml,mbstring,curl,zip,gd} libapache2-mod-php mariadb-server wget

# Secure MariaDB installation
sudo mysql_secure_installation

# Connect to MariaDB and create WordPress database and user
sudo mysql -u root <<EOF
CREATE DATABASE wordpressdb;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'securepassword1';
GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
EOF

# Download and extract WordPress
cd /tmp
wget https://wordpress.org/latest.tar.gz
sudo tar xzvf latest.tar.gz -C /var/www/html/

# Configure permissions
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 775 /var/www/html/wordpress

# Create Apache configuration file for WordPress
sudo bash -c 'cat <<EOT > /etc/apache2/sites-available/wordpress.conf
<VirtualHost *:8080>
ServerName localhost
DocumentRoot /var/www/html/wordpress

<Directory /var/www/html/wordpress>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/wordpress_error.log
CustomLog ${APACHE_LOG_DIR}/wordpress_access.log combined
</VirtualHost>
EOT'

# Configure port 8080
echo "Listen 8080" | sudo tee -a /etc/apache2/ports.conf

# Enable configuration and restart Apache
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

# Instructions for web interface installation
echo "Installation via web interface:"
echo "Open a browser and go to http://127.0.0.1:8080/wordpress"
echo "Follow the installation wizard providing the database information:"
echo "Database name: wordpressdb"
echo "Username: wordpressuser"
echo "Password: securepassword1"
echo "Database host: localhost"

Step 3: Make the script executable and run it​

chmod +x install_wordpress.sh
./install_wordpress.sh

Step 4: Responses to mysql_secure_installation​

During the script execution, you will be prompted to answer questions to secure MariaDB. Here are the recommended responses:

Enter current password for root : [Press Enter]
Switch to unix_socket authentication [Y/n] Y
Change the root password? [Y/n] n
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] n
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Step 5: Installation via web interface​

  1. Open a browser and go to http://127.0.0.1:8080/wordpress

  2. Follow the installation wizard providing the database information:

    • Database name: wordpressdb
    • Username: wordpressuser
    • Password: securepassword1
    • Database host: localhost
  3. Complete the installation by creating a WordPress admin account

Step 6: Verification​

# Verify Apache is listening on port 8080
sudo netstat -tulnp | grep :8080

# Check Apache status
sudo systemctl status apache2

# Check logs
sudo tail -f /var/log/apache2/wordpress_access.log

Part 2: Installing GLPI​

Step 1: Create the installation script​

Create a script file for GLPI:

nano install_glpi.sh

Step 2: Script content​

Copy the following content into the file:

#!/bin/bash

# Update packages and install necessary components
sudo apt update
sudo apt install -y apache2 php php-{apcu,cli,common,curl,gd,imap,ldap,mysql,xmlrpc,xml,mbstring,bcmath,intl,zip,bz2} libapache2-mod-php mariadb-server wget

# Secure MariaDB installation (if not already done)
# sudo mysql_secure_installation

# Connect to MariaDB and create GLPI database and user
sudo mysql -u root <<EOF
CREATE DATABASE glpidb;
CREATE USER 'glpiuser'@'localhost' IDENTIFIED BY 'securepassword2';
GRANT ALL PRIVILEGES ON glpidb.* TO 'glpiuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
EOF

# Download and extract GLPI
cd /tmp
wget https://github.com/glpi-project/glpi/releases/download/10.0.7/glpi-10.0.7.tgz
sudo tar xvf glpi-10.0.7.tgz -C /var/www/html/

# Configure permissions
sudo chown -R www-data:www-data /var/www/html/glpi
sudo chmod -R 775 /var/www/html/glpi

# Create Apache configuration file for GLPI
sudo bash -c 'cat <<EOT > /etc/apache2/sites-available/glpi.conf
<VirtualHost *:8081>
ServerName localhost
DocumentRoot /var/www/html/glpi/public

<Directory /var/www/html/glpi/public>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/glpi_error.log
CustomLog ${APACHE_LOG_DIR}/glpi_access.log combined
</VirtualHost>
EOT'

# Configure port 8081
echo "Listen 8081" | sudo tee -a /etc/apache2/ports.conf

# Enable configuration and restart Apache
sudo a2ensite glpi.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

# Instructions for web interface installation
echo "Installation via web interface:"
echo "Open a browser and go to http://127.0.0.1:8081/glpi"
echo "Follow the installation wizard providing the database information:"
echo "Database name: glpidb"
echo "Username: glpiuser"
echo "Password: securepassword2"
echo "Database host: localhost"

Step 3: Make the script executable and run it​

chmod +x install_glpi.sh
./install_glpi.sh

Step 4: Installation via web interface​

  1. Open a browser and go to http://127.0.0.1:8081/glpi

  2. Follow the installation wizard providing the database information:

    • Database name: glpidb
    • Username: glpiuser
    • Password: securepassword2
    • Database host: localhost
  3. Log in with the default credentials:

    • User: glpi
    • Password: glpi
  4. Important: Immediately change the default passwords

  5. Remove the installation file for security reasons:

sudo rm /var/www/html/glpi/install/install.php

Part 3: Advanced Commands and Securing​

Managing permissions​

# Set file permissions recursively
sudo find /var/www/html/wordpress -type f -exec chmod 644 {} \;
sudo find /var/www/html/glpi -type f -exec chmod 644 {} \;

# Set directory permissions
sudo find /var/www/html/wordpress -type d -exec chmod 755 {} \;
sudo find /var/www/html/glpi -type d -exec chmod 755 {} \;

Firewall configuration (UFW)​

# Allow necessary ports
sudo ufw allow 8080/tcp
sudo ufw allow 8081/tcp

# Check status
sudo ufw status

Real-time monitoring​

# Monitor Apache logs
sudo tail -f /var/log/apache2/access.log
sudo tail -f /var/log/apache2/wordpress_access.log
sudo tail -f /var/log/apache2/glpi_access.log

# Monitor system processes
htop

# Monitor MySQL/MariaDB status
sudo mysqladmin -u root -p status

Part 4: Troubleshooting​

Apache configuration error​

If you encounter an Apache configuration error:

# Check configuration syntax
sudo apache2ctl configtest

# View detailed logs
sudo journalctl -xeu apache2.service

# Check configuration files
sudo nano /etc/apache2/sites-available/wordpress.conf
sudo nano /etc/apache2/sites-available/glpi.conf

Check that ports are free​

# Check listening ports
sudo netstat -tulnp | grep :8080
sudo netstat -tulnp | grep :8081

# Alternative with ss
sudo ss -tulnp | grep :8080
sudo ss -tulnp | grep :8081

Check permissions​

# Check directory permissions
ls -ld /var/www/html/wordpress
ls -ld /var/www/html/glpi

# Check owner
ls -la /var/www/html/

Part 5: Practical Exercises​

Exercise 1: Add comments to scripts​

  1. Open the scripts install_wordpress.sh and install_glpi.sh
  2. Add comments (#) explaining each section of the script
  3. Explain what each important command does

Exercise 2: Change ports​

Modify the ports to use 8080 and 8082 instead of 8080 and 8081:

  1. Modify the Apache configuration files
  2. Modify the ports.conf file
  3. Restart Apache
  4. Test access to the applications

Commands to use:

# Modify port in GLPI configuration
sudo nano /etc/apache2/sites-available/glpi.conf
# Change *:8081 to *:8082

# Add port 8082
echo "Listen 8082" | sudo tee -a /etc/apache2/ports.conf

# Restart Apache
sudo systemctl restart apache2

# Verify
sudo netstat -tulnp | grep :8082

Exercise 3: Monitoring and surveillance​

  1. Use htop to monitor resources during installation
  2. Monitor Apache logs in real-time
  3. Check MariaDB status with mysqladmin

Reflection Questions​

Answer the following questions in a separate document:

  1. What is the importance of configuring separate users and databases for WordPress and GLPI?

    • Explain the security risks if both applications shared the same database
  2. What would happen if WordPress and GLPI both used port 80?

    • Explain the technical implications and possible solutions
  3. Why is it necessary to secure the MariaDB installation during initial setup?

    • Detail the risks if this step is skipped
  4. What is the relationship between the database and the WordPress/GLPI files uploaded to the server?

    • Explain how the two interact
  5. Explain what happens when you access WordPress or GLPI via a browser after installation.

    • Describe the request flow from the browser to the database

Appendix 1: Port Configuration Methods​

# Create a configuration file for the port
sudo bash -c 'echo "Listen 8080" > /etc/apache2/conf-available/port8080.conf'
sudo bash -c 'echo "Listen 8081" > /etc/apache2/conf-available/port8081.conf'

# Enable configurations
sudo a2enconf port8080
sudo a2enconf port8081

# Restart Apache
sudo systemctl restart apache2

Advantages:

  • More modular
  • Facilitates configuration management
  • Does not modify main files

Method 2: Direct addition in ports.conf​

# Directly add in ports.conf
echo "Listen 8080" | sudo tee -a /etc/apache2/ports.conf
echo "Listen 8081" | sudo tee -a /etc/apache2/ports.conf

# Restart Apache
sudo systemctl restart apache2

Advantages:

  • Simple and quick
  • All port configurations in one place

Disadvantages:

  • Modifies the main file
  • Less modular

Difference between tee and bash -c​

echo "Listen 8081" | sudo tee -a /etc/apache2/ports.conf :

  • Directly modifies the main configuration file
  • Simple but less modular
  • All configurations in one place

sudo bash -c 'echo "Listen 8080" > /etc/apache2/conf-available/port8080.conf' :

  • Creates a separate configuration file
  • More modular and structured
  • Allows easy enable/disable
  • Does not modify main files

Appendix 2: Advanced Security​

Remove installation files​

# WordPress (if present)
sudo rm -rf /var/www/html/wordpress/wp-admin/install.php

# GLPI
sudo rm /var/www/html/glpi/install/install.php

Configure strict permissions​

# Permissions for WordPress
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo find /var/www/html/wordpress -type d -exec chmod 755 {} \;
sudo find /var/www/html/wordpress -type f -exec chmod 644 {} \;

# Permissions for GLPI
sudo chown -R www-data:www-data /var/www/html/glpi
sudo find /var/www/html/glpi -type d -exec chmod 755 {} \;
sudo find /var/www/html/glpi -type f -exec chmod 644 {} \;

Configure backups​

# WordPress database backup script
sudo mysqldump -u wordpressuser -p wordpressdb > /backup/wordpress_$(date +%Y%m%d).sql

# GLPI database backup script
sudo mysqldump -u glpiuser -p glpidb > /backup/glpi_$(date +%Y%m%d).sql

Summary of Important Commands​

CommandDescription
sudo systemctl status apache2Check Apache status
sudo systemctl restart apache2Restart Apache
sudo apache2ctl configtestTest Apache configuration
sudo netstat -tulnp | grep :8080Check if port is listening
sudo tail -f /var/log/apache2/access.logMonitor logs in real-time
htopMonitor system processes
sudo mysqladmin -u root -p statusCheck MariaDB status
sudo ufw allow 8080/tcpAllow port in firewall

Final Verification​

Ensure you have successfully:

  • Installed WordPress on port 8080
  • Installed GLPI on port 8081
  • Configured separate databases
  • Accessed both applications via browser
  • Configured the firewall (UFW)
  • Understood the difference between port configuration methods
  • Added comments to scripts
  • Answered reflection questions

Next Steps​

  • Module 7: Networking and Configuration (to deepen network configuration)
  • Module 8: Services and Daemons (to automate with systemd)
  • Module 9: System Security (to further secure installations)

Additional Resources​


Lab created on: December 2024