Ubuntu 18.04 server administration

Install LAMP

sudo apt update 
sudo apt install apache2
sudo apt install mysql-server
sudo mysql_secure_installation
sudo apt install php libapache2-mod-php php-mysql
sudo apt install php-cli
sudo apt-get install fail2ban
sudo systemctl restart apache2
sudo systemctl status apache2

Adding a new user

# Use adduser instead of useradd
adduser [USERNAME]

# Grant sudo privileges to a new user
sudo usermod -aG sudo [USERNAME] # Give permission to new directory sudo chown -R [USERNAME]:www-data /var/www/new/directory/ # Add new user to group sftp sudo usermod -G sftp [USERNAME] # Give yourself ownership sudo chown [USERNAME] /var/www/directory sudo chown [USERNAME]:www-data /var/www/directory # Give yourself ownership recursively sudo chown -R [USERNAME]:www-data /var/www/directory

Give a new user access to /var/www

# Add new user to group www-data
sudo usermod -a -G www-data [USERNAME]
OR
sudo useradd -G www-data [USERNAME]

# Give existing Group write access to directory
sudo chmod -R g+w /var/www/html

Folder permission

# Change group to www-data
sudo chgrp www-data /var/www

# Set group id for subfolders (set the sticky bit for the group)
sudo chmod g+s /var/www/sitename

# Give User, Group, Others rwx permission
sudo chmod -R ugo+rwx /var/folder

# Remove User, Group, Others rwx permission
sudo chmod -R ugo-rwx /var/folder

# Give/Remove Others rwx permission
sudo chmod o+rwx /var/www/sitename
sudo chmod o-rwx /var/www/sitename

# Set 775 to User, Group, Others
sudo chmod -R 775 /var/www

Set all permission to default

# Set 660 for all files recursively including folders
sudo chmod -R 660 '/var/www'

# Set 770 for all folders
find '/var/www/directory' -type d -exec chmod 2770 {} +

Verify user and group permission

# Check user belongs to 
id [USERNAME]

# Check group members
getent group www-data

# Check group members for sudo/www-data
sudo cat /etc/group | grep sudo
sudo cat /etc/group | grep www-data

Help for any command

info command-name
man command-name

Alias

ScriptAlias /xyz/ /usr/lib/cgi-bin/Quarterly-Report/

<Directory "/usr/lib/cgi-bin/Quarterly-Report">
	...
	...
</Directory>

Setup Alias on <VirtualHost *:80>

<VirtualHost *:80>
     Alias /URL /var/www/desired/folder
     ...
</VirtualHost>

Example of Alias

        Alias /disbursement /var/www/disbursement
        <Directory /var/www/disbursement>
                Options -Indexes
        </Directory>

        Alias /quarterly /usr/lib/cgi-bin/Quarterly-Report
        <Directory /usr/lib/cgi-bin/Quarterly-Report>
                Options -Indexes
                Require all granted
                Allow from all
                AddHandler cgi-script .cgi .pl
        </Directory>

For undefined function odbc_connect()

sudo apt-get install php-odbc

Connect directly to MSSQL for Ubuntu 18.04

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -

#Ubuntu 18.04
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql17

Connect PHP to MSSQL via PDO ODBC

sudo apt-get install build-essential
sudo apt-get install tdsodbc
#More info
https://stackoverflow.com/questions/39696838/odbc-connect-sql-error-unixodbcdriver-managerdata-source-name-not-found/39799462#39799462 

Sudo nano /etc/odbc.ini

[SHIPNET]
Server = 192.168.1.9
Port = 1433
Database = SHIPNET
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so

Disable Directory Listing in Apache using Virtual host

### In Apache Virtual Host

<Directory /var/www/public_html>
      Options -Indexes
</Directory>

Disable Directory Listing in Apache using .htaccess

 Options -Indexes

Enable CGI-BIN

sudo apt-get install perl
sudo a2enmod cgi
sudo service apache2 restart

Can’t locate DBI.pm in @INC (you may need to install the DBI module)

### Didn't work
sudo apt-get install libcgi-session-perl

### Worked
sudo cpan
install Date::Manip
sudo apt-get install libdbd-sybase-perl

Change timezone

### List timezones
timedatectl list-timezones

### Set timezone e.g. Singapore
sudo timedatectl set-timezone Asia/Singapore

### Verify changes
timedatectl

VirtualHost DirectoryIndex

        Alias /disbursement /var/www/disbursement
        <Directory /var/www/disbursement>
                DirectoryIndex kim.php
                Options -Indexes
        </Directory>

        Alias /quarterly /usr/lib/cgi-bin/Quarterly-Report
        <Directory /usr/lib/cgi-bin/Quarterly-Report>
                DirectoryIndex kim.pl
                Options -Indexes
                Require all granted
                Allow from all
                AddHandler cgi-script .cgi .pl
        </Directory>

Enable/Disable site.conf

### Enable
a2ensite example.com

### Disable
a2dissite example.com

### Check syntax error
apachectl configtest

### Apply changes
sudo service apache2 restart

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top