You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How To Install Nginx, MySQL, PHP, SFTP on an Ubuntu Azure Virtual Machine
This series of documents will configure and setup a Nginx, MySQL, and
PHP (LEMP) server on a basic Standard B1s (1 vcpus, 1 GiB memory) Ubuntu
16.04 or 18.04 LTS Virtual Machine on Microsoft Azure.
This will also install other useful packages and configurations for SFTP
and a fully automated SSL service using certbot for Let's Encrypt.
The B1s is Azure's entry level Linux VM and only comes with 1 GiB memory so
you need to optimise the install and configuration to maximise the server to
your advantage.
These documents take you through each step of the configuration from:
These are a series of specific commands to configure the Ubuntu server for our environment. You may not need to do these.
$ sudo locale-gen en_GB.UTF-8 # fix locales
$ sudo cp /usr/share/zoneinfo/Africa/Johannesburg /etc/localtime # set time
SFTP
$ sudo adduser $(whoami) www-data # add yourself so you can SFTP to overwrite files in /var/www
$ sudo chmod -R g+w /var/www # ensure group can write to www
$ sudo apt install mysql-server mysql-client
$ sudo systemctl start mysql
$ sudo systemctl enable mysql
$ sudo mysql_secure_installation # answer N to validate password plugin
$ sudo mysql
Configure MySQL users
mysql>SELECT user,authentication_string,plugin,host FROMmysql.user;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
mysql> FLUSH PRIVILEGES;
mysql>SELECT user,authentication_string,plugin,host FROMmysql.user;
mysql> exit
cgi.fix_pathinfo=0
post_max_size=256M
upload_max_filesize=256M
date.timezone=Africa/Johannesburg
[opcache]opcache.memory_consumption=256
opcache.max_accelerated_files=10000
opcache.validate_timestamps=120
opcache.error_log=/var/log/opcache-errors.log
[apc]apc.shm_size=128M
apc.stat=1
; Relative to the number of cached files (you may need to watch your stats for; a day or two to find out a good number).apc.num_files_hint=7000
; The number of seconds a cache entry is allowed to idle in a slot before APC; dumps the cache.apc.ttl=7200
apc.user_ttl=7200
apc.include_once_override=0
; Allow 2 seconds after a file is created before it is cached to prevent users; from seeing half-written/weird pages.apc.file_update_protection=2
; Ignore filesapc.filters = "/var/www/html/apc.php"apc.cache_by_default=1
apc.use_request_time=1
apc.slam_defense=0
apc.stat_ctime=0
apc.canonicalize=1
apc.write_lock=1
apc.report_autofilter=0
apc.rfc1867=0
apc.rfc1867_prefix=upload_
apc.rfc1867_name=APC_UPLOAD_PROGRESS
apc.rfc1867_freq=0
apc.rfc1867_ttl=3600
apc.lazy_classes=0
apc.lazy_functions=0
$ sudo apt-get install python-certbot-nginx
$ sudo openssl dhparam -out /etc/nginx/dhparam.pem 2048
$ sudo mkdir -p /var/www/_letsencrypt
$ sudo chown www-data /var/www/_letsencrypt
$ sudo certbot certonly --webroot -d example.com -d www.example.com --email [email protected] -w /var/www/_letsencrypt -n --agree-tos --force-renewalSaving debug log to /var/log/letsencrypt/letsencrypt.logPlugins selected: Authenticator webroot, Installer NoneObtaining a new certificatePerforming the following challenges:http-01 challenge for example.comUsing the webroot path /var/www/_letsencrypt for all unmatched domains.Waiting for verification...Cleaning up challengesIMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2022-02-22. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew"
This uses public/private SSH key for authentication. Your user will only be able to write files in /var/www.
$ sudo apt install ssh
$ sudo addgroup sftp
$ sudo useradd -m FTPUSER -g sftp
$ sudo passwd FTPUSER
$ sudo adduser FTPUSER www-data # add user to group they can write to www folder
$ sudo chmod -R g+w /var/www # set group write permissions
$ sudo mkdir -p /home/FTPUSER/.ssh
$ sudo nano /home/FTPUSER/.ssh/authorized_keys # copy public key from computer and paste here
$ sudo chmod -R go= /home/FTPUSER/.ssh
$ sudo chown -R FTPUSER:sftp /home/FTPUSER/.ssh
$ sudo nano /etc/ssh/sshd_config
PubkeyAuthentication yes
Match group sftp
X11Forwarding no
AllowAgentForwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
$ sudo service ssh restart
Test it out using your private key.
$ sftp -i ~/.ssh/id_rsa [email protected]Connected to 40.88.136.129.sftp> exit
TODO: figure out why ChrootDirectory /var/www/ in /etc/ssh/sshd_config creates a broken_pipe issue when connecting to the SFTP server. This has been disabled until I can solve this! 🙀