Skip to content

Instantly share code, notes, and snippets.

@BeKnowDo
Last active July 8, 2024 10:58
Show Gist options
  • Save BeKnowDo/eda124eea1aba844f9eecfbcd6cc411a to your computer and use it in GitHub Desktop.
Save BeKnowDo/eda124eea1aba844f9eecfbcd6cc411a to your computer and use it in GitHub Desktop.
Windows 10 sucks...but we can make it less sucky. This is how I setup local development for Win10

Install Chocolately

Install ConEmu

  • Install via chocolately choco install conemu -y

Install Nginx

  • Install via chocolately choco install nginx -y ** The -y argument is to skip any confirmation messages...just install it. It's fine ;)

Install PHP

  • Install via chocolately choco install php -y

Install MySQL

  • Install via chocolately choco install mysql -y

Install MySQL Workbench

  • Install via chocolately choco install mysql.workbench -y

Composer (PHP package manager)

  • Install the Composer package manager for PHP choco install composer -y

Other Developer Applications

choco upgrade chocolatey -y

choco install vscode -y

choco install git -y IF YOU RECEIVE A DEPENDENCY ERROR - please run choco install git.install -y

choco install smartgit -y

choco install vlc -y

choco install 7zip.install -y

choco install dbeaver -y


Configuration Paths

Nginx Configuration Path
  • C:\tools\nginx-1.17.0\conf or whichever is the latest version installed Please use the path of the latest version of nginx installed by chocolately
PHP Configuration Path
  • C:\tools\php72 or whichever is the latest version installed

PHP.ini Enabled Extensions

  • Un-comment extensions directory
extension_dir = "ext"
  • Make sure to enable the following extensions

extension=curl
extension=fileinfo
extension=intl
extension=gd2
extension=odbc
extension=pdo_mysql
extension=pdo_odbc

Download HiddenConsole

Download the following code snippet that will run PHP in the background without needing to have a console/terminal opened.

HiddenConsole - unzip this file into the c:\tools directory.

Read more on why we want this tool.

Create bat file in the same directory as your PHP Configuration Path.

We use this .bat file to run PHP-FPM. You can name this file anything you'd like, i.e.: start-php-fcgi.bat.
Copy the following into that file and make sure to use your PHP CONFIGURATION PATH

@ECHO OFF
ECHO Starting PHP FastCGI...
set PATH=C:\tools\php73\;%PATH%
C:\tools\RunHiddenConsole.exe C:\tools\php73\php-cgi.exe -b 127.0.0.1:9000

Now open a new terminal/prompt and run the following command c:\tools\php73\start-php-fcgi.bat


This will run the required PHP CGI on windows :)

Example Nginx Configuration

  • This is our default nginx configuration. I like to put all servers into a dedicated folder, e.g.: /servers
Default Configuration
# user  nobody;
worker_processes  1;
#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on; 
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;
        error_page   500 502 503 504  /50x.html;

        location = /50x.html {
            root   html;
        }
        
        location ~ \.php$ {
           root           html;
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
           include        fastcgi_params;
        }
    }

    include C:/nginx-1.17.3/conf/servers/*.conf;
}

Additional Server Example Configuration

server {
    listen 80;
    server_name LOCAL_DOMAIN;
    index index.php;
    error_log C:/nginx-1.17.3/logs/error.log;
    access_log C:/nginx-1.17.3/logs/access.log;
    root C:/THE_ROOT_OF_YOUR_PROJECT;
    location / {
        try_files $uri /index.php$is_args$args;
    }
    location ~ \.php {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:9000;
    }
}

Running all of this stuff :)

  • I use CMDer but you can use any terminal. I'd use cmder. It's less suckage.

Nginx

  • Nginx should be running at this point. You can check by visiting http://localhost in your browser of choice.
  • Next, let's add nginx to Windows' PATH variables. To do this, open "System Properties" and visit the "Advanced Tab" and click on "Environment Variables" on the bottom right of the window (http://drops.cavscout.us/TSdFDY).
  • Next, you'll need to find "Path" variable under "System variables" (http://drops.cavscout.us/vtP5bo) and enter the nginx path which is: C:\tools\nginx-1.17.0.
  • Click 'OK' and you should be all set to use nginx in your terminal.
  • You now have the following options to run in the terminal:
    • nginx -s stop fast shutdown
    • nginx -s quit graceful shutdown
    • nginx -s reload changing configuration, starting new worker processes with a new configuration, graceful shutdown of old worker processes
    • nginx -s reopen re-opening log files
  • Next, you'll need to create an entry in Windows' hosts file which is located in C:\Windows\System32\drivers\ .

Generating SSH Key

Windows 7 (how dare you)

To generate an SSH key in Windows 7, you'll need to download a console/terminal emulator that has SSH built-in. One of the most widely used emulators for Windows is either Cygwin or Cmder. Let's go with Cmder.

  • Download Cmder
  • Extract the zip file into your desired directory (I'd keep it at the root of your C: drive - i.e.: C:/Cmder)

This is a mandatory security step from GitHub.

  • Open PowerShell (as admin) and type the following command: ssh-keygen.exe

    You'll be prompted several times. There is no need to do anything other than hitting the enter key until you see ASCII art (a picture of sorts) in the terminal (powershell in this case).

(Make sure vscode is installed)

  • Copy the path generated by ssh-keygen and open it with vscode code C:\Users\YOUR_USER_PROFILE_NAME\.ssh\id_rsa.pub.

    Open the file named id_rsa.pub copy the value from the file.

    Hint: The ssh key should begin with: ssh-rsa

  • Log into https://github.com/settings/key and click "New SSH Key".

  • Paste your rsa key and click submit/save.

Now you are able to successfully clone any respository from GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment