Setting Up a New Windows Computer For PHP App Development

If you’re setting up a new Windows machine and wanting to get it all configured up so its running well, these steps can help. This may also help if you are transferring an existing PHP local dev environment to a new one on a new computer. It considers things like Visual Studio Code, Debugging (XDebug), Git, Composer, Node.js and npm.

Install Xampp (Then Optimise)

Start by installing Xampp and MySQL and then get some settings right to assist you in developing great websites. Don’t optimise just yet. Later, once your sites are running, we’ll follow steps to optimise Xampp performance on windows to get your sites running like lightning.

  1. Setup Xampp basics and configure it for efficient PHP development.
  2. After following the steps below, you may want to optimise Xampp performance.
  3. After optimising Xampp and Setting up VS Code, add Debugging ability with XDebug.

Enable Long Path Support in Windows and Git

Enable Long Path Support (Windows 10 and later): If you’re using Windows 10 or later, you can enable long path support to allow paths longer than the traditional 260 characters limit. This can be done through a group policy edit or by modifying the registry. This is a protection in case any of your folder structures (e.g. plugins) end up having very nested files that exceed the standard length allowed by Windows and Git. Not required but may save you hassles transferring files and dealing with Git pushes.

You may have this problem with WooCommerce and plugin files in paths like */SkAdNetworkConversionValueSchema/*

  • Group Policy:
    1. Type gpedit.msc in the Start search box and hit Enter.
    2. Navigate to Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem.
    3. Find the Enable Win32 long paths option and set it to Enabled.
  • Registry Edit:
    • Press Win + R, type regedit, and press Enter.
    • Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem.
    • Find or create a DWORD value called LongPathsEnabled and set its value to 1.

Git Config: You can also try to set core.longpaths to true in your Git configuration. This can be done globally or just for your repository:

For a specific repository, navigate to the repository directory and run:

git config core.longpaths true

For global configuration, run: (apply this one)

git config --global core.longpaths true

Transferring Web Files and MySQL Data Between Computers

Copying Website Files from htdocs folder

Copy the website folders and files to xampp/htdocs folder on the new computer, by using something like a separate external drive that can be used to copy and paste sites from one computer to the next.

Copying the MySql Databases to the New Computer

Visit C:\xampp\mysql\data. For each database you want there will be a folder. Copy those, as well as the ibdata1 file at C:\xampp\mysql\data. Put those in the same directory on the new computer. The ibdata1 file contains the data rows. When complete, restart MySQL server using Xampp UI.

Optimise Xampp Performance on Windows

Start by testing and validating that your sites are running. Remember to optimise performance. Xampp is notorious for running slowly (especially for large WordPress sites), but tweaking Xampp settings can make a world of difference. Use the instructions here to tweak Xampp settings and make it more performant.

Setup of Visual Studio Code

Install Visual Studio Code, then …

Re-setup Git (Source Control)

In response to a message that will likely appear when you start working with a project. “Git not found. Install it or configure it using the “git.path” setting. Click Download git.” If Visual Studio is prompting you to download Git from its website, it indicates that Git is not already installed on your system, or at least not integrated with Visual Studio. In this case, you will need to download and install Git separately.

Below assumes you have also copied your previous .git folder for that website from your other installation. If configured correctly, it should pickup the remotes pretty easily.

Check Git Installation:

  • Open terminal (Command Prompt or PowerShell).
  • Run: git --version.
  • If not installed, download and install Git from Git website.

Initialize Local Repository:

  • Navigate to your project directory in the terminal.
  • Run: git init.

Check Existing Remote Configuration:

  • Run: git remote -v.
  • If your GitHub repo shows up, your good, otherwise investigate steps to get this happening.
  • Run: git status
  • Confirm if it’s all okay, you should see your remotes considered

Alternatively, you may need to run:

Fetch the Latest Changes:

  • Run git fetch to update your local copy of the remote branch without merging those changes into your local branch.

Merge the Changes:

  • Run git merge origin/master (replace master with the name of your branch if it’s different). This will merge the remote changes into your local branch.
  • Resolve any merge conflicts if they arise.

If Visual Studio Code is indicating that Git needs your username and email configured to identify who is making the changes in the repository. This information is used in the commit logs. Here’s how you can set up your user.name and user.email in Git:

git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"

Reset up Extensions in Visual Studio Code

  • Git Graph: great for visualising Commit History, Branches and Merges
  • PHP Intellisense: a great extension to assist PHP coding in visual studio

Refine and Tweak Settings for Visual Studio Code (settings.json)

The settings.json file found in the Users\yourname\AppData\Roaming\Code\User directory is the User settings file for Visual Studio Code. This file contains global settings that apply to all projects you open with VS Code on your computer. It’s common for this file to have numerous settings, especially if you’ve customized your VS Code environment or installed extensions that add their own settings.

"php.validate.executablePath": "C:\\xampp\\php\\php.exe"

Check the settings.json file for other settings that may have bee added in your old machine and copy over or discard as needed.

Install Composer on Your Computer

Good for installing and managing pre-built extensions so you don’t have to build them from scratch. Good applications are built by the bricks of things that people have already put a lot of work into. Setting it up on your new machine is necessary if you’re working with PHP projects that use Composer. It is best to install globally on your computer and then use it individual to manage dependencies in each of your projects.

Note: if you’ve already installed XDebug from some previous steps, you’ll need to temporarily disable XDebug, because XDebug ends up trying to debug the PHP being run when COmposer installs, and you end up with an error. In your php.ini, file comment out ‘zend_extension=xdebug’ by putting a “;” at the beginning. Re-enable it afterwards.

  1. Download Composer:
  2. Install Composer:
    • Run the downloaded installer.
    • Follow the instructions to install Composer. On Windows, the installer will set up Composer globally by default.
  3. Verify Installation:
    • Open a terminal or command prompt.
    • Run composer --version to verify that Composer is installed.

Add Node.js (and npm) to Your Computer

Node Package Manager (npm) is another great tool to help you manage dependencies and get access to pre-built additions to your app. Node.js is needed if you want to use npm. It requires Node.js to be installed to function. With npm, use can use npm commands in the terminal, which is the standard way to manage node modules and dependencies.

  1. Download Node.js:
    • Go to the Node.js website.
    • Download the installer for your operating system. The Node.js installer comes with npm, so you don’t need a separate installation for npm.
  2. Run the Installer:
    • Execute the downloaded file and follow the installation instructions.
    • It’s recommended to use the default settings provided in the installer, which include npm and adding Node.js to your system’s PATH.
  3. Verify Installation:
    • Once installed, you can verify the installation by opening a terminal or command prompt.
    • Type node -v and press Enter. This command should return the current version of Node.js, indicating it’s installed correctly.
    • Similarly, type npm -v to check the npm version, verifying that npm is also installed.

Setup Linux (Ubuntu) For Windows

Why Ubuntu on Windows? To help with web deployment and to open up a world of Linux commands. For one, Rsync can be a great way to sync and deploy web files. Rsync (Remote Sync) is a Linux/Unix based utility for data backup and synchronization both locally and remotely. Using Rsync command, you can sync files and directories across directories, disks or networked computers and copy files from one directory to another local directory, sync files from local machine to network server or vice versa. Linux is also a great way to work with SSH which is useful to communicate with and run commands on Linux hosting servers, allowing your windows machine to connect to Linux instances.

Some more info from Windows about installing: https://learn.microsoft.com/de-de/linux/install

In powershell, enter the command wsl --install

Getting Your Public and Private Keys

To use SSH on linux, you need a public and private key. If you’ve already got yours, transfer them securely (e.g. usb drive) to your new computer. If you haven’t already, you can generate a new SSH key pair using ssh-keygen. This will create a private key (usually id_rsa) and a public key (usually id_rsa.pub). These get stored at LINUX:home/user/.ssh, which is the default location. SSH commands know to look here for these when making SSH calls to servers that need authentication.

That’s it, you can now use a linux terminal to dive into the world of linux commands on your very own windows machine and use things like Rsync and SSH to help you manage files on other servers.

Some other notes

ERROR: -bash: ./deploy_all_TEST.sh: /bin/bash^M: bad interpreter: No such file or directory

This indicates that your shell script deploy_all_TEST.sh has Windows-style line endings (CRLF – Carriage Return and Line Feed) instead of the Unix-style line endings (LF – Line Feed) that Linux expects.

This often happens when a script is edited or created on a Windows system. Linux interprets the carriage return (^M) as part of the command, which leads to this error.

To fix this, you need to convert the line endings to Unix style. You can do this using the dos2unix utility in your WSL environment. If dos2unix is not installed, you can install it first. Here’s how you can do it:

  1. Install dos2unix (if it’s not already installed):bash

sudo apt update sudo apt install dos2unix

Convert the Line Endings:

bash

dos2unix ./deploy_all_TEST.sh

Run Your Script Again:

bash

  1. ./deploy_all_TEST.sh

This should convert the line endings to the Unix style and allow you to run your script without the interpreter error.

0 0 votes
Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

0
Would love your thoughts, please comment.x
()
x