I have been hosting PHP websites on Windows Server IIS and Linux for many years. This page bundles my PHP guides: running PHP on IIS, tuning OPcache and realpath_cache_size, connecting to MySQL and SQL Server, fixing errors after PHP upgrades, and PHP security. Database tuning itself is in my MySQL guides.
PHP on Windows Server and IIS
- PHP with WinCache on IIS: install and set up PHP with the Windows Cache Extension.
- The WinCache effect: Save with object caching: how the WinCache object cache cut database queries per page.
- PHP on IIS: "No input file specified": fix the error for non-existing .php files with Request Restrictions.
- How to install Microsoft's SQL Server Driver for PHP: install the SQLSRV extension for PHP on IIS.
- Connect to MS SQL Server with PHP 5.3+: connect to SQL Server with the SQLSRV API.
- Set or remove the read-only attribute assigned to files with PHP chmod: make files read-only on IIS with PHP
chmod. - Custom PHP version on IIS Express and WebMatrix 3: run your own PHP version in IIS Express.
Performance and caching
- How to set a good PHP realpath_cache_size: check and set
realpath_cache_size. - Optimize PHP OPcache configuration: fine-tune OPcache after realpath_cache_size.
- Clear PHP opcode caches before WordPress Updates: ease the updating process: clear OPcache, WinCache or APC before WordPress updates.
- Optimize(d) WordPress hosting (9+ practical tips): 9+ practical tips for WordPress and other PHP applications.
- 8 Tips to improve Joomla performance: caching, gzip, sessions and MySQL tips for Joomla on IIS.
- Magento maintenance script for IIS: clear Magento log tables and cache on a schedule.
- Create your own PHP based Origin Pull CDN: build your own Origin Pull CDN with a few lines of PHP.
PHP and databases
- How to use SSL in PHP Data Objects (PDO) mysql: connect to MySQL with PDO over SSL.
- Convert PHP ext/mysql to MySQLi: convert ext/mysql code to MySQLi, with a list of equivalents.
- Optimize all MySQL tables with PHP/MySQLi multi_query: optimize all MySQL tables with one
multi_query(). - Connect to multiple MySQL servers in a for and foreach loop: loop over several MySQL servers.
- Calculate MySQL database size with PHP (off the old shelf): calculate the size of a MySQL database.
Configuration, upgrades and errors
- Don't turn off CURLOPT_SSL_VERIFYPEER and fix your PHP configuration: fix certificate validation in php.ini instead of disabling it.
- PHP 5.6 default_charset change may break HTML output: when the new
default_charsetbreaks your HTML. - Always_populate_raw_post_data setting in PHP 5.6 & Magento 2.0: fix Magento 2.0 upgrades on PHP 5.6 and 7+.
- Fatal error: Uncaught Error: [] operator not supported for strings - PHP 7.1: fix "[] operator not supported for strings" in PHP 7.1+.
- Increase WordPress' memory limit WP_MEMORY_LIMIT properly in wp-config.php: set
WP_MEMORY_LIMITand PHPmemory_limitthe right way.
PHP security
- Exploit PHP's mail() to get remote code execution: how the 5th
mail()parameter leads to remote code execution. - Validate MIME types with PHP Fileinfo: secure file uploads by checking the real MIME type.
- Cracking PHP rand(): why
rand()must not be used for security tokens. - MySQL sleep() attacks: unvalidated input and MySQL
sleep()injection. - "How we broke PHP, hacked Pornhub and earned $20,000": two use-after-free bugs in PHP and a $20,000 bug bounty.
Handy PHP scripts
- Check website availability with PHP and cURL: check if your website is up with PHP and cURL.
- Use authenticated SMTP over TLS encrypted connections, in PHP, ASP and ASP.NET: send mail over authenticated SMTP with TLS.
- Send authenticated SMTP email over TLS from WordPress: override
wp_mail()for secure SMTP in WordPress. - Redirect old URL to new URL or send 404 page with PHP: 301 redirect old URLs or send a 404.
- Asynchronous PHP calls with XMLHttpRequest: call PHP asynchronously from JavaScript.