Secondary metabolites extract of McB1 endophytic fungi from gelam (Melaleuca cajuputi Powell.) leaves have a high potential antibacterial activity against Escherichia coli ATCC8739 and Staphylococcus aureus ATCC6538 with flavonoids and phenol as bioactive compound. The low production of secondary metabolites extract in the cultivation stage and the high potential antibacterial activity of bioactive compounds produced by McB1 endophytic fungi require special treatment for optimize the secondary metabolites product. This is possibly achieved by optimizing the composition of the cultivation media, where various sources of carbon, nitrogen, and pH produce different amounts and classes of secondary metabolites. The objectives of the research to obtain the optimum interaction between sources of carbon, nitrogen, and pH for the production of secondary metabolite extract using Response Surface Methodology (RSM). The results showed that the highest extract (0.25 g) with the composition of sucrose as carbon source, yeast extract as nitrogen source, and pH 6. Based on the optimization of the medium with a variation of 4.5 gL-1 sucrose, 0.48 gL-1 yeast extract, and pH 6.1 yielded 0.34 g of secondary metabolites extract of McB1 endophytic fungi. The chromatogram profile of the optimized secondary metabolite extract showed the presence of flavonoids, phenols, terpenoids, and tannins.