Starting Apache and MySQL on project startup in PHPStorm [Windows]
Do you want to automatically start some special services in a project when you open PHPStorm? You can!
Set services to a manual start
Don’t close Services as you may use it later for copy/paste exact values into command line.
Start service from your command line
By default you can’t start or stop service from command line if it didn’t started as administrator. To overcome this you need a SubInACL tool as suggested in this StackOverflow answer.
Download SubInACL from Microsoft website and run in command line:
cd C:\Program Files (x86)\Windows Resource Kits\Tools\
subinacl.exe /service MySQL57 /grant=COMPUTER_NAME\user=PTO
MySQL57: Service name should be exact one, check it in the Services → Properties → Service Name.
COMPUTER_NAME\user: this one could be hard to type exactly, so go to Services → Properties → Log On → Browse. Enter part of your user name, hit Check Names and you’ll get full name you need to use in the script.
PTO: this stands for P (Pause/Continue Service), T (Start Service) and O (Stop Service). You can check full list of rights at Microsoft Support Site.
Configure Startup tasks in Project settings at PHPStorm
Go to Settings → Tools → Startup Tasks. Hit +
and select “PHP Web Application”. I use this because it make it possible to run this configuration without any special files with URL only.
Click on +
under Before launch section and add External tools, like this:
Remember to uncheck all boxes to hide this task from other places and to prevent from poping up in console. All we want is to run silently, so it would just work without additional clicks.
Try it!
You’ll love this magic especially on the projects which you touching on rare occasions and often forget start up details.