Configure VPS with details & LAMP

  • Essentials:
    Initial setup of Ubuntu 22.04
  • Fail2ban:
    sudo apt-get install fail2ban
  • Disable journal logs:
    Sometimes, if your VPS has problems, journal logs could occupy whole disk space (95%+).
    journalctl --vacuum-size=100M
    nano /etc/systemd/journald.conf –> SystemMaxUse=100M
    – To clear existing cache: (sudo find /var/log/journal -name "*.journal" | xargs sudo rm) && (sudo systemctl restart systemd-journald)
  • Change default SSH port:
    It’s not requirement, but good thing to change from default 22 to your desired, i.e. 12345:
    sudo ufw allow 12345/tcp
    nano /etc/ssh/sshd_config and change Port=22 to12345.
    service ssh restart (or service sshd restart
    – in rare cases, you might also need to amend: /etc/apache/sites-enabled && /etc/apache2/ports.conf
  • Docker:
    install docker (only if you know docker and want to use it)
    Now, instead of the combined articles (i.e. install-lamp-1 or install-lamp-2 ) I advise more specific oriented articles:
    – install apache
    install mysql
    – install php: 1) Install phpbrew  2) try  blog/docker-php-8-zts-apache-swoole-parallel & gmp install 3) might need to add AddType application/x-httpd-php .php in /etc/apache2/mods-available/php.load
  • LetsEncrypt free SSL:
    for apache
    – (if different ports needed: here or here)
  • Firewall:
  • WordPress (with mysql):
    ubuntu tutorial
  • Simple Disk usage:
    sudo apt install ncdu and anytime just run ncdu
  • Set correct permissions for multiple users
    – to rewrite privileges after uploading files automatically: 
    */10 * * * * sudo chown -R www-data:www-data /var/www
  • Increate timeout for SSH client (instead of default 10):
    nano /etc/ssh/sshd_config –>set  ClientAliveInterval 60   and ClientAliveCountMax 5 

== others ==

  • [PHP]:
    – Install Redis Cache
    – Install MBstring : sudo apt-get install php-mbstring php8.1-mbstring php-gettext libapache2-mod-php8.1
  • Add user through SSh
  • Download & unpack file: 
    wget --no-check-certificate --content-disposition -O && unzip -o -d /var/www/path/folder
  • Find file:
    find . -type f -name "*John*"
  • Install & Configure mail: article1 | article2
  • Auto- Restart stopped-service : Github repo 
  • Restrict port to specific IP:
    sudo iptables -A INPUT -p tcp -s YOURRRRRRR_IPPPPPPPPPPP -j ACCEPT
    sudo ufw allow from to any port 22 proto tcp
  • Monitor files/folders changes : 
    inotify-hookable -w path_to_plugin -c "COMMAND_TO_EXECUTE" (i.e. "docker container restart CONTAINER_NAME") 

### MYSQL ###

  • Add/Create user:
    CREATE USER 'myuser1'@'' IDENTIFIED BY 'password123';
    GRANT ALL PRIVILEGES ON dbnamee.* TO 'myuser1'@'';
    FLUSH Privileges;
  • reset root pass;
  • user password change : 
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxxxxxxx';
  • disable mysql-logs : &
    /etc/mysql/my.cnf - >
    max_allowed_packet = 512M
    In mysql: 
    SHOW VARIABLES LIKE 'max_allowed_packet';
    SET @@global.max_allowed_packet = 16777215;
    SHOW VARIABLES LIKE 'max_allowed_packet';

Leave a Comment

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

Puvox - Blog
Scroll to Top