Miscellaneous
# π Ubuntu Server Setup and Configuration Guide (with PHP, Node.js, MySQL, PM2, and GitLab Runner)
---
## π Timezone & Hostname Configuration
```bash
sudo timedatectl set-timezone Asia/Kolkata
sudo timedatectl set-timezone UTC
sudo hostnamectl set-hostname abc.com
sudo nano /etc/hosts # Map 127.0.0.1 to new hostname
π§Ό Update & Upgrade Systemβ
sudo apt update -y && sudo apt upgrade -y
π Install PHP 8.2β
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update -y
sudo apt install php8.2 -y
π¦ Install PHP-FPM and Extensionsβ
sudo apt-get install -y php8.2-fpm php8.2-cli php8.2-common php8.2-json \
php8.2-opcache php8.2-mysql php8.2-mbstring php8.2-xml php8.2-gd php8.2-curl
β Set Default PHP Versionβ
sudo update-alternatives --set php /usr/bin/php8.2
π§ Increase PHP Upload Limitβ
sudo nano /etc/php/8.2/fpm/php.ini
sudo nano /etc/php/8.2/cli/php.ini
# Set the following values:
upload_max_filesize = 50M
post_max_size = 50M
sudo systemctl restart php8.2-fpm
π¬ Install and Configure MySQLβ
sudo apt install mysql-server -y
sudo mysql_secure_installation
π οΈ Create MySQL Users and Databaseβ
mysql -u root -p
CREATE USER 'admin'@'localhost' IDENTIFIED BY 'password@12345';
CREATE USER 'test-user'@'localhost' IDENTIFIED BY 'password@123';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'test-user'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
CREATE DATABASE abc;
π¦ MySQL Backupβ
mysqldump -u root -p --all-databases > dump.sql
β‘ Install Node.js, npm, and nvmβ
sudo apt install nodejs -y
sudo apt install npm -y
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 18
nvm use 18
nvm alias default 18
npm install -g yarn
npm install -g pm2
π Check PM2 Process Detailsβ
pm2 show 0
π§ More PM2 Useful Commandsβ
pm2 list # List all PM2 processes
pm2 start app.js # Start an app
pm2 restart app_name # Restart by name
pm2 stop all # Stop all processes
pm2 delete all # Delete all processes
pm2 logs # View logs
pm2 monit # Monitor processes live
pm2 save # Save current process list
pm2 startup # Generate startup script
πΌ Install Composerβ
sudo apt install composer -y
composer check-platform-reqs
composer show -p
π Install and Configure NGINXβ
sudo apt remove apache2 -y
sudo systemctl stop apache2
sudo systemctl disable apache2
sudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx
sudo systemctl status nginx
π Install SSL using Certbotβ
sudo snap install --classic certbot
π οΈ Install GitLab Runnerβ
sudo apt update -y
sudo apt install -y curl
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash
sudo apt-get install gitlab-runner -y
sudo gitlab-runner -version
sudo gitlab-runner status
sudo gitlab-runner start
sudo gitlab-runner enable
sudo gitlab-runner verify
# Add sudo permissions
echo "gitlab-runner ALL=(ALL:ALL) ALL" | sudo tee /etc/sudoers.d/sudoers
echo "gitlab-runner ALL=(ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers.d/sudoers
π Install Multiple PHP Versions (Optional)β
sudo apt install -y software-properties-common apt-transport-https lsb-release ca-certificates curl
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
for version in 7.4 8.0 8.1 8.3; do
sudo apt install -y php$version php$version-fpm php$version-mysql
sudo apt install -y php$version-cli php$version-common php$version-curl php$version-mbstring php$version-xml php$version-zip
done
β Youβre all set! Your Ubuntu server is now ready with PHP, MySQL, Node.js, NGINX, SSL, GitLab Runner, and process management using PM2. π§