PHP Setup Commands

💻 Platform-Specific Commands

🖥️ Windows Server

Restart Nginx Server

taskkill /F /IM nginx.exe
timeout /t 2
F:\4Born-Server-setup\Setup\nginx-1.25.3\nginx.exe
&
F:\4Born-Server-setup\Setup\nginx-1.25.3\nginx.exe -s reload 

nginx -s reload
            

Restart PHP FastCGI

taskkill /F /IM php-cgi.exe
timeout /t 2
start /B "PHP FastCGI" "F:\4Born-Server-setup\Setup\php-8.3.19\php-cgi.exe" -b 127.0.0.1:9000
            

Terminate Nginx and PHP FastCGI at the Same Time

taskkill /F /IM nginx.exe
taskkill /F /IM php-cgi.exe
            

Port Already Used Problem Solve

netstat -ano | findstr :111 (port)

taskkill /PID  /F
taskkill /PID 12345 /F
            

🐧 Linux Server (Ubuntu)

Restart Nginx Server

sudo systemctl stop nginx
sudo systemctl start nginx

# Or restart in one command:
sudo systemctl restart nginx

# Reload configuration without stopping:
sudo nginx -s reload
            

Restart PHP-FPM

sudo systemctl stop php8.3-fpm
sudo systemctl start php8.3-fpm

# Or restart in one command:
sudo systemctl restart php8.3-fpm

# Check PHP-FPM status:
sudo systemctl status php8.3-fpm
            

Stop Nginx and PHP-FPM at the Same Time

sudo systemctl stop nginx php8.3-fpm

# Or kill processes:
sudo pkill nginx
sudo pkill php-fpm
            

Port Already Used Problem Solve

# Check what's using port 80 (or any port):
sudo netstat -tulpn | grep :80

# Or using ss command:
sudo ss -tulpn | grep :80

# Kill process by PID:
sudo kill -9 
sudo kill -9 12345

# Kill process by name:
sudo pkill nginx
            

⚙️ Nginx Configuration

🖥️ Windows - Steps to Add Another Port in Nginx

If you need to add another application running on a new port in Nginx, follow these steps:

  1. Open the Nginx configuration file located at:
  2. F:\4Born-Server-setup\Setup\nginx-1.25.3\conf\nginx.conf
  3. Add a new server block for the desired port:
  4.     # ✅ PHP Application on Port 5698 (Web) replace web to your directory path 
        server {
            listen 5698;
            server_name localhost;
            root F:/4Born-Server-setup/Time-Tracker/web;
            index index.php index.html index.htm;
    
            location / {
                try_files $uri $uri/ /index.php?$query_string;
            }
    
            location ~ \.php$ {
                include fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME F:/4Born-Server-setup/Time-Tracker/web$fastcgi_script_name;
            }
        }
                    
  5. Save the configuration file.
  6. Restart Nginx using the restart command above.
  7. Test by visiting http://127.0.0.1:5698 in your browser.

🐧 Linux - Steps to Add Another Port in Nginx

  1. Open the Nginx configuration file:
  2. sudo nano /etc/nginx/sites-available/default
    # Or create a new site:
    sudo nano /etc/nginx/sites-available/myapp
  3. Add a new server block:
  4.     # ✅ PHP Application on Port 5698
        server {
            listen 5698;
            server_name localhost;
            root /home/4Born-Server-Setup/Time-Tracker/web;
            index index.php index.html index.htm;
    
            location / {
                try_files $uri $uri/ /index.php?$query_string;
            }
    
            location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
            }
        }
                    
  5. Enable the site (if created new file):
  6. sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
  7. Test configuration and restart:
  8. sudo nginx -t
    sudo systemctl restart nginx
  9. Test by visiting http://127.0.0.1:5698 in your browser.

📁 File Manager Access

🖥️ Windows - Open File Manager

explorer F:\4Born-Server-setup
            

🐧 Linux - Navigate to Directory

cd /home/4Born-Server-Setup

# Open file manager:
nautilus /home/4Born-Server-Setup

# List directory contents:
ls -la /home/4Born-Server-Setup
            

🗄️ MySQL Commands

Note: MySQL commands are identical on both Windows and Linux systems.

mysql -u root -p
SHOW DATABASES;
USE your_database;
SHOW TABLES;
DESCRIBE table_name;
SELECT * FROM table_name LIMIT 10;
            

🔧 Additional Linux PHP Commands

PHP Installation & Management

# Install PHP and extensions:
sudo apt update
sudo apt install php8.3 php8.3-fpm php8.3-mysql php8.3-curl php8.3-gd php8.3-mbstring

# Check PHP version:
php -v

# Check PHP-FPM configuration:
sudo php-fpm8.3 -t

# View PHP configuration:
php --ini
            

Log Files

# View Nginx error logs:
sudo tail -f /var/log/nginx/error.log

# View PHP-FPM logs:
sudo tail -f /var/log/php8.3-fpm.log

# View system logs:
sudo journalctl -u nginx -f
sudo journalctl -u php8.3-fpm -f