OnlyOffice PHP示例API无法查看/编辑Office文件问题求助
Hey there, since you’ve already got the GUI up and running and can upload files successfully, we can rule out basic deployment issues. Let’s dive into the most likely culprits that are blocking the document view/edit functionality:
1. Double-Check config.php Settings
First, let’s make sure your configuration points the PHP demo to the document server correctly. Open up your config.php file and verify these key values:
$GLOBALS['DOCUMENT_SERVER_PUBLIC_URL']: Should be set tohttp://192.168.131.132/web-apps/apps/api/documents/api.js(this is the public endpoint for the document editor scripts)$GLOBALS['DOCUMENT_SERVER_INTERNAL_URL']: Use the same URL as above unless you have a private network setup—since both services are on the same server, no need for a different internal URL here$GLOBALS['EXAMPLE_URL']: Must behttp://192.168.131.132:81(your PHP demo’s full URL) to ensure the document server can send callback requests back to the demo.
Small typos or missing slashes here are super common, so triple-check every character!
2. Fix CORS Issues (Different Ports = Different Origins)
Your document server is on port 80, and the PHP demo is on port 81—browsers treat these as separate origins, which can block script loading. Here’s how to fix it:
- On your document server, edit the config file at
/etc/onlyoffice/documentserver/default.json - Find the
services.CoAuthoring.filter.allowOriginssection, add"http://192.168.131.132:81"to the list of allowed origins - Save the file and restart the document server with
sudo systemctl restart onlyoffice-documentserver
3. Verify File Permissions for Storage
If the PHP demo can’t read the uploaded files (or the document server can’t access them), you’ll get this error. Fix permissions with these commands:
- Set the correct owner for the storage directory (replace
/path/to/your/php-demowith the actual path):sudo chown -R www-data:www-data /path/to/your/php-demo/storage/ - Set proper read/write permissions:
sudo chmod -R 755 /path/to/your/php-demo/storage/
4. Check Browser Console for Clues
Open your browser’s dev tools (press F12) and go to the Console tab. Look for:
- CORS error messages (like "No 'Access-Control-Allow-Origin' header present")—this confirms the CORS fix above is needed
- 404 errors when loading the document editor scripts—points to a wrong URL in
config.php - Failed API requests to the document server—tells you exactly where the communication is breaking
5. Test Document Server Reachability
Make sure the document server is running and reachable:
- From your browser, visit
http://192.168.131.132/web-apps/apps/api/documents/api.js—you should see a JavaScript file, not an error page - On the server, run
sudo systemctl status onlyoffice-documentserverto confirm the service is active and running
6. Ensure Callback URL is Accessible
The document server needs to send status updates to the PHP demo. Log into your server via SSH and run:
curl http://192.168.131.132:81
If you don’t get the PHP demo’s homepage HTML, check:
- Firewall rules blocking port 81
- Your web server (Apache/Nginx) is properly configured to listen on port 81
- No reverse proxy or routing issues between the two services
Start with these steps—they cover 90% of the cases where upload works but view/edit doesn’t. Let me know if you hit any specific errors during troubleshooting!
内容的提问来源于stack exchange,提问作者ThanhLam112358




