Is there a way to implement a WMS server using only php or python cgi and mysql? I can't use geoserver or mapserver and postgres and any other software as they are not provided by the administrator.
Please check out https://github.com/klokantech/tileserver-php/ might be helpful for you.
If you have tiled map in MBTiles format, you can serve them using ordinary PHP script. All you need is php-sqlite module, which should be included by default. You can try this: mbtiles-php - I'm using similar script in production. With some kind of URL-routing library, you can even simulate standard TMS.
Actually, you also can write your own WMS implementation using PHP or Python and MySQL database as a backend, but the task is tedious, and it is likely that you will get banned for putting too much load on the server. Bear in mind that WMS is very resource-hungry service.
You could also try Mapnik's OGCServer which is apparently a pure python wms server