Let's leave aside whether you can simply change the outbound license of unmodified code, which raises separate issues. I'll assume you're asking about cases, like your example, where some modifications have been made to the original project's code.
The answer depends on the terms of the license of the original project. In some cases, the original license may make it effectively impossible to change (i.e., your modified code will have to be under the original license); this is particularly true of the GPL. In some cases the original license, and the license that is desired for the modified code, may clash in such a way that there is a problem.
The MIT license generally doesn't give rise to such problems, because it is one of the most permissive open source licenses. The MIT license is used by projects that expect the code to be modified (or incorporated in larger works), where the modified code, or the larger work, is licensed under some license that is different from, and more restrictive than, the MIT license. Usually, even highly permissive licenses like the MIT license contain some conditions that must be satisfied - most notably, requirements to preserve the text of the original license.
The Apache License 2.0 is also a very permissive license, but it is more complex and somewhat more restrictive than the MIT license. The two licenses do not conflict: that is, incorporating MIT-licensed code in a project that is globally licensed under the Apache License, or modifying an MIT-licensed source file and licensing the modified source file under the Apache License, creates no licensing problem.
The main thing you have to do is preserve the original MIT license notice in some way that gives users notice that some of the code was based on code originally licensed under the MIT license. In MIT-licensed projects, the MIT license usually appears in individual source files, but sometimes is instead (or additionally) included by the project in a global license file.
The easier case is where you have license notices in individual source files. If you haven't modified a source file, and it has an MIT license notice, just keep it. If you have made some nontrivial modifications to a particular source file with an MIT license notice, you may want to use a license notice in the file like this (here I'm using the boilerplate license notice contained in the Apache License itself):
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This file incorporates code covered by the following terms:
Copyright (c) 2004, Codehaus.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
In this way you are satisfying the MIT license's requirement that "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the software" by preserving verbatim the original notice.
If instead (or additionally) there was a global MIT license file, keep it, but do something to make clear that this is historical licensing information covering some of the code, and that the global license for your project is the Apache License.
You also asked:
Do each of the past contributors or the project need to be notified before changing the license? What if some of the contributors are no longer available?
No. If the license already gives permission to put modified code, or larger works incorporating the original code, under a different, non-conflicting license -- which the MIT license certainly does -- you do not need any further permission, and there is no requirement to give notice. (There are a few borderline open source licenses that have limited upstream notice requirements imposed on distributors, but hopefully you won't encounter those.)
Where it sometimes becomes necessary to contact past contributors is typically where the original license conflicts with how you want to license your downstream work that incorporates or modifies the upstream code - for example, suppose there is some code in a GPL-licensed project and you want to use it in an MIT-licensed project, and you don't want your project to be covered by the GPL. The GPL does not allow this by default, so you'd need to get special permission from the original GPL licensors.
What if I want to change the license included in sources where I am the only person who has contributed code to the project? Or if I get permission from everyone who has contributed to a specific file or project? In that case is it ok to remove the license (LGPL for example) and replace it with a new license (Apache) ?
What if I want to change the license included in sources where I am the only person who has contributed code to the project?
In the simplest case, where you are the only copyright holder of the code in the project, and there are no third-party dependencies of any sort that might constrain the outbound license that you can pick, then you can simply remove the old license information and replace it with the new license information.
Consider two more complicated cases:
a) You are the only individual contributor to the project, but during the period in which you worked on the project, you moved from company A to company B to company C. It is possible that under the circumstances one or more of those employers might have a copyright claim on the code you wrote. That depends on the facts (such as the legal jurisdiction where you live, and the content of your employment agreement). You may need to get permission for the license change from past/present employers who have copyright ownership over your work.
b) Suppose you are the only contributor but you are using a JAR from some other project that that project licensed under "GPLv2 only". Let's say you want to change your project license from "LGPLv2.1-or-later" to the Apache License 2.0. LGPLv2.1-or-later is explicitly compatible with GPLv2, so there's no issue with the old license, but the Apache License is (correctly, in my view) considered incompatible with "GPLv2 only" licensing, at least under some circumstances. So here I'd want to check with the GPL project to make sure they have no problem with your use of their code given your license change (based on whatever theory). Chances are that project won't mind (or, less likely, might have some conditions like your continuing to publish the source code of your project), but it is important to informally check.
Or if I get permission from everyone who has contributed to a specific file or project? In that case is it ok to remove the license (LGPL for example) and replace it with a new license (Apache) ?
If you get appropriate permission from all contributors to your project (bearing in mind that copyright ownership may complicate that task in some cases, and assuming there is no external constraint on how you can change the license) then yes, you can simply replace the old license notices with new ones. (An example that I recall where such an LGPL-to-Apache license change was done in a JBoss context is Netty. In a related case, HornetQ, there were a small number of individual source files that were kept under the LGPL because of difficulties in obtaining relicensing permission from third-party contributors.)