Problem Description
When installing WordPress 3.8 or later in an LNMP environment, the "Appearance" → "Themes" page in the admin dashboard may only show one theme and prevent switching or adding new themes.
Root Cause
This issue is typically caused by the scandir() function being disabled in the PHP configuration. WordPress relies on scandir() to scan the themes directory and list available themes. When this function is disabled, WordPress cannot detect or display the theme list properly.
Solution
Modify the PHP configuration file (php.ini) to remove scandir() from the disabled functions list, then restart the PHP service.
Step 1: Connect to Your Server
Use an SSH client (e.g., PuTTY, Terminal) to connect to your VPS or server.
Step 2: Edit the PHP Configuration File
Open the PHP configuration file with a text editor like vi or nano. Common paths include:
vi /usr/local/php/etc/php.ini
Other possible paths:
/etc/php.ini/etc/php/7.x/fpm/php.ini(for PHP 7.x)/usr/local/php7/etc/php.ini
Step 3: Locate the Disabled Functions List
In vi command mode, search for the disable_functions directive:
/disable_functions
You will find a line similar to:
disable_functions = scandir,passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
Step 4: Remove the scandir Function
- Move the cursor to that line.
- Press
ito enter insert mode. - Delete
scandir,(including the comma). Ensure the list remains correctly formatted without extra commas. - Press
Escto exit insert mode.
Step 5: Save and Exit
In command mode, save the file and exit vi:
:wq
Step 6: Restart the PHP Service
Restart the service based on your LNMP setup:
- For PHP-FPM:
/etc/init.d/php-fpm restartor
systemctl restart php-fpm - For Apache:
/etc/init.d/httpd restartor
systemctl restart apache2 - For Nginx + PHP-FPM: Usually, restarting PHP-FPM is sufficient.
Step 7: Verify the Result
After restarting, refresh the WordPress admin "Appearance" → "Themes" page. All themes should now display correctly, and you should be able to switch or add themes.
Notes and Additional Information
- Configuration File Path: If the above paths are incorrect, find your php.ini location with:
php --ini | grep 'Loaded Configuration File' - Security Consideration: The
scandir()function is relatively low-risk, but the disabled functions list is often set for security. Consult your server administrator if you are on shared hosting or have strict security requirements. - WordPress Version: This solution applies to WordPress 3.8 and later, including modern versions (5.x, 6.x).
- Alternative: If you cannot modify php.ini (e.g., on shared hosting), try overriding the setting in your site's
.htaccessfile (Apache) or Nginx configuration (if allowed):php_value disable_functions ""Or, more precisely, remove only scandir:
php_admin_value disable_functions "passthru,exec,system,..." # List all other functions except scandir
After completing these steps, WordPress theme management should function normally.