Apache2 permissions “hack”

(Errors are fixed ^^)

It’s not stupid if [the last part] works, right? Right?

1. We need a new group: website
2. We need a user: frank
3. Simple website where everything is put into /var/www/html/

sudo addgroup website
sudo adduser frank website
sudo adduser frank www-data

Let’s see if Frank belongs to the right groups:

groups frank

The result should look something like

frank : frank cdrom floppy sudo audio dip website www-data video plugdev netdev

Let’s change some ownerships, directory first.

sudo chown -vR :website /var/www/html/

Now set the permissions right.

sudo chmod -vR g+w /var/www/html/

You should do a test now by doing the following:

cd /var/www/html/
echo "My server bring all the boys to the yard" > index.html

If you get an error, enter the following:

newgrp - website

This is, in my experience not permanent though, so if you keep having issues, just yeet it into the bash.bashrc file, at the bottom:

sudo nano /etc/bash.bashrc

add at the bottom:

if [[ -n $SSH_CONNECTION ]] ; then
newgrp - www-data
fi

 

Loading

A working Apache2 server with PHP7.4

I was in need of a server solution that could be quickly deployed as a VM.

      1. Install Debian 11 as a VM with web- and SSH server
      2. Create a USER next to your root account during the installation
      3. Find the IP address of the new installation. The easiest is if you have NoVNC running. Log in as USER and type
        ip a
      4. Time to so the sudo thing
        su

        log in as root

        apt-get update && apt-get install -y sudo
        usermod -aG sudo USER
        exit
        exit

        log back in as USER

      5. Okay, let’s install some more stuff but first we do an update
        sudo apt-get update && sudo apt-get upgrade -y

        Now we want some essentials

        sudo apt-get install -y dirmngr gnupg2 nano wget gpg curl fail2ban ufw software-properties-common

        Preparing the PHP install

        wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
        echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
        sudo apt-get update
        sudo apt-get install -y php7.4 libapache2-mod-php7.4 php7.4-mysql php7.4-curl php7.4-gd php7.4-mbstring php7.4-xml php7.4-xmlrpc php7.4-zip

        And restart the Apache2 Webserver

        sudo systemctl restart apache2
      6. Alright, that’s done. Next step is to test things.
        sudo nano /var/www/html/test.php

        Enter this into the php file and press Control X and type Y to save and exit.

        <?php
        // Show all PHP information
        phpinfo();
        ?>
      7. Go to the IP address of the server you just created and type
        HTTP://IP ADDRESS/test.php
        

        If you see a PHP page with all sorts of data, you’re good. If not, go fix. Don’t ask me, I’m not there yet!

Loading