a nerd enjoying life
professional -> software development
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
/*
Write a program that takes two numeric arguments
and displays their sum.
*/
#include <stdio.h>
#include <stdlib.h> //needed for exit()
void main(int argc, char *argv[]) {
if (argc != 3) exit(1);
printf("The sum of the two arguments (%s, %s) is %d\n", argv[1], argv[2], (atoi(argv[1]) + atoi(argv[2])));
}
Adding a new website to the server. In these examples we are going to set up a website called website.com
sudo mkdir -p /var/www/html/website.com
sudo chown -R $USER:$USER /var/www/html/website.com
sudo chmod -R 755 /var/www/html
sudo vi /var/www/html/website.com/index.html
Lets create a blank index.html page for the website.
sudo vi /var/www/html/website.com/index.html
You just need some simple details for the site for now, so the contents of the html file will be:
<html>
<head>
<title>website.com</title>
</head>
<body>
<h1>Welcome to website.com</h1>
</body>
</html>
This tells apache how to deal with requests for a website, and where to redirect it on the server.
First of all we need to copy the default file, and open it up for editing.
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/website.com.conf
sudo vi /etc/apache2/sites-available/website.com.conf
Below is the typical contents of this file (ignoring the commented out sections that are present), and the details added, in red.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/website.com
ServerName website.com
ServerAlias www.website.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Once all of the .conf files have been set up for each of the websites the a2ensite needs to be enabled for each site. Plus the default .conf file needs to be disabled before relaoding the server.
sudo a2ensite website.com.conf
sudo a2dissite 000-default.conf
Now you can restart the server
sudo systemctl restart apache2
An A record with website.com pointing to your server’s public IP address.
An A record with www.website.com pointing to your server’s public IP address.
~ sudo apt install certbot python3-certbot-apache
~ sudo nano /etc/apache2/sites-available/website.com.conf
Need to check what traffic is allowed to the site
~ sudo ufw status
Note: the ufw might conflict with server service provider security settings. So in that case you will want to deactivate the ufw.
~ sudo systemctl stop ufw
~ sudo ufw status
Status: inactive
~ sudo certbot --apache
~ sudo systemctl status certbot.timer
To test what will happen on a certificate renewal you can process a dry run.
~ sudo certbot renew --dry-run
The output from this will look something similar to:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/website.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Simulating renewal of an existing certificate for website.com and 1 more domain
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded:
/etc/letsencrypt/live/2fatokens.com/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
~ sudo apt update
~ sudo apt install --no-install-recommends php8.1
The --no-install-recommends just means that php8.1 is installed and no other packages that it may try to install, such as apache.
To make sure that php is installed, and view the version just type:
~ php -v
The resulting output will look like:
PHP 8.1.2-1ubuntu2.19 (cli) (built: Sep 30 2024 16:25:25) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2-1ubuntu2.19, Copyright (c), by Zend Technologies
To see what modules are installed, so you can determine which ones you may need, type the following:
~ php -m
The output will look something like this:
[PHP Modules]
bcmath
calendar
...
zip
zlibrary
Depending on what type of php code is to be executed additional modules might need to be installed
The full list of modules that can be installed on php can be found at https://www.php.net/manual/en/extensions.alphabetical.php
To install a module use the module name, for example mysql, in the following way:
~ sudo apt-get install -y php8.1-mysql