Yes, you can do a Ph.D. at the age of 40; most of the person who does this are mostly in the education sector. The only problem that comes up is that not all programs will be open for you.