Is it possible to set up a proper web server with a domain name on an iPhone or on iOS?
Yes, it is indeed possible. You can use any web server software on the iPhone - and from there the configuration is exactly like having a web server with a domain name on any other computer/server:
You need to buy the domain name
You need to set up DNS service for the domain name
You need to set up an A-record in DNS for the static IP of the iphone, or alternatively setup DynDNS if your iPhone has a dynamic IP
However, in practice it is not worth while having a web server on an iPhone. You'll run into problems with the web server app being put in the background, the iPhone sleeping/turned off, the battery being worn out too quickly, possible connectivity problems with WiFi, too low throughput, etc. Some of these can be mitigated by using for example a cabled ethernet connection and having a charger permanently connected, but it is not going to be practical.
In addition to those problems, you'll find that the webserving software is limited in what kind of extensions/plugins you can install (usually none), and you'll usually only be able to host static content (i.e. no ASP/PHP scripts, etc.).
Take a look at for example DraftCode, if you want to run PHP scripts on the phone:
If you just want to run a simple web server without dynamic content, you could take a look at for example "Easy File Sharing Web Server App":
If you are a developer, you can make your own web server app using frameworks/libraries such as Criollo or GCDWebServer: