Skip to main content

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. πŸ§