Skip to content

Instantly share code, notes, and snippets.

@md-riaz
Last active September 2, 2023 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save md-riaz/5c0a54b9c5dfcf066c1795ddb5329d2d to your computer and use it in GitHub Desktop.
Save md-riaz/5c0a54b9c5dfcf066c1795ddb5329d2d to your computer and use it in GitHub Desktop.

Here's how you can do it:

  1. Create a New Server Block Configuration File: First, create a new Nginx server block configuration file for your subdomain. You can create this file in the /etc/nginx/sites-available/ directory. Replace subdomain.example.com with your actual subdomain:

    sudo nano /etc/nginx/sites-available/subdomain.example.com
  2. Configure the Server Block: Inside the new server block configuration file, define the configuration for your subdomain. Here's a simplified example:

    server {
        listen 80;
        server_name subdomain.example.com;
    
        root /var/www/subdomain.example.com;  # Change this to the appropriate directory
    
        index index.php index.html index.htm;
    
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;  # Adjust the path accordingly
        }
    }

    Modify the server_name, root, and FastCGI settings as needed for your setup.

  3. Create a Symbolic Link: Create a symbolic link to the sites-enabled directory to enable the new site:

    sudo ln -s /etc/nginx/sites-available/subdomain.example.com /etc/nginx/sites-enabled/

    To remove the symbolic link, you can use this command:

    sudo rm /etc/nginx/sites-enabled/subdomain.example.com
  4. Test Configuration and Restart Nginx: Test the Nginx configuration for syntax errors:

    sudo nginx -t

    If the test is successful, restart Nginx to apply the changes:

    sudo systemctl restart nginx
  5. Upload Website Files: Upload your new PHP website files to the directory specified in the root directive of your new server block.

  6. DNS Configuration: Ensure that the DNS records for your subdomain point to your server's IP address.

  7. Permissions and Ownership: Set appropriate permissions and ownership for the new website's files so that the web server can access them. This might involve using the chown and chmod commands.

  8. Testing: Access the new subdomain in your browser to ensure that the new PHP website is being served correctly.

By following these steps, you'll be able to add a new PHP website under a subdomain on your server alongside your existing FusionPBX installation. Just make sure that the new server block's server_name and port settings do not conflict with your existing configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment