This script creates a series of web servers defined in a config file on different ports.
- Copy
cliServers.sh
from below to the root directory in which you have all your php projects (e.g./var/www/ or ~/code/
) - In that directory run
mkdir logs
- Create a file in that directory called
config
and add configuration for each web server as detailed below and exemplified in the config file in this gist. - Run
sh cliServers.sh
when you wish to start your web servers. They will run in the background until their processes are killed (by usingkill
or a reboot).
Format your config file with each line as a web server to start. config
shows an example file.
Each line should then be in the format
port:project-root:web-root
.
For the web root it should be the directory including your front controller
(e.g. public
for laravel or web
for symfony standard edition).
To kill the processes run kill <pid>
where <pid>
is the process ID.
It uses the standard php
binary in your path. If you want a different php binary
(e.g. for a different php version for different projects) then use https://gist.github.com/michaelcullum/65cf1328eef82887affe578b56f62aaf#file-differentphpbinaries-md
Be careful you don't try and create multiple servers on the same port (inc. running the script twice without killing the old processes)
Use at risk, things might break. I don't know what I'm doing. ;)
Ocassionally clear out /logs/. You shouldn't ever get clashing file names but they'll build up (one log file is generated per web server per script run). So run it once a day for 2 months with 10 scripts and you have 600 log files....
I strongly recommend when browsing to these webservers not using the ip of 127.0.0.1:<port>
but instead using dnsmasq to set *.local
to redirect locally. Then for each server just pick a name for it. See https://github.com/michaelcullum/setup-scripts/blob/master/localDomains.sh for how to set that up. You can just navigate then to whateveryoulike.local:<port>
and your project will be there (you don't need to change anything here as using 127.0.0.1
for the web server instead of localhost means it will respond to different domains, so long as the port is correct and it's resolving to 127.0.0.1
(which dnsmasq handles for you).