This tutorial will show you how to set up a local unix web server on your Windows computer without headaches
Some requirements for the steps ahead
Enable the WSL (Windows Subsystem for Linux) option in Windows Optional Features panel. Open PowerShell as Administrator and run
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestartOpen de Microsoft Store, choose Ubuntu Linux distribuition and install it
Some commands for use in the VI text editor
| CMD | Description |
|---|---|
| :wq | Save and quit |
| :q | Quit |
| /string | Find a string in the text |
| INSERT | Insert enable \ disable |
With WSL shell openned, update the distro's packages
sudo apt update && sudo apt -y upgrade && sudo apt -y dist-upgradeRemove sudo password requests creating one sudoers profile file and adding <USERNAME> ALL=(ALL) NOPASSWD:ALL
sudo vi /etc/sudoers.d/<USERNAME>To install MySQL type it:
sudo apt install mysql-server
sudo mysql_secure_installationTo install PostgreSQL type it:
sudo apt install postgresql postgresql-contrib
sudo passwd postgres
sudo -u postgres psql
alter role postgres with password 'postgres'
\q
sudo service postgresql startInstall PHP and extensions with apt install php-<entension-name> command
sudo apt install php7.4-fpm php7.4-pgsql php7.4-mbstring php7.4-gd php7.4-curl php7.4-dom php7.4-soap php7.4-zip php7.4-bcmath php7.4-xml php7.4-json php7.4-gmpTo avoid a PHP's security problem it is necessary to adjust one value in the /etc/php/[php-version]/fpm/php.ini file, open the same
sudo vi /etc/php/7.4/fpm/php.iniFind ;cgi.fix_pathinfo=1 directive. Adjust to cgi.fix_pathinfo=0 and save the file. After this, restart the php7.4-fpm service
sudo service php7.4-fpm startcurl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composerTo install the nginx type
sudo apt install nginxCopy the default server block conifiguration file to example.com and open the same
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com
sudo vi /etc/nginx/sites-available/example.comConfigure the server block to the example.com project (See the example.com file)
Enable the example.com by creating a symbolic link from example.com configuration file to the /etc/nginx/sites-enabled/ directory
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/To avoid a possible hash bucket memory problem that can arise from adding more server names, it is necessary to adjust a single value in the /etc/nginx/nginx.conf file. Open the file
sudo vi /etc/nginx/nginx.confCheck the syntax of the nginx.conf file typping
sudo nginx -tRestart the nginx service
sudo service nginx restartInstall the xDebug and open the /etc/php/7.2/mods-available/xdebug.ini file to modify zend_extension directive
sudo apt install php-xdebug
sudo vi /etc/php/7.4/mods-available/xdebug.iniUpdate zend_extension=xdebug.so to zend_extension=/usr/lib/php/20190902/xdebug.so and save file (Note that 20190902 can be different because it is the version of php extension)
Now open the /etc/php/7.4/fpm/php.ini file
sudo vi /etc/php/7.4/fpm/php.iniAdd the settings below and save the file
[Xdebug]
xdebug.remote_enable=1
xdebug.remote_port=9999
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
;xdebug.remote_host=127.0.0.1
xdebug.idekey="vscode"
;xdebug.idekey="PHPSTORM"
Restart the php7.4-fpm service
sudo service php7.4-fpm restartInstall the Node.js v12.x:
sudo curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install -y nodejs
sudo npm i -g yarnNow you have a local unix web server on your Windows computer and will can debug your web applications easily congratulations!