Shay Anderson Software
SHAYANDERSON
  • About
  • Projects
  • Contact
Xap is a new rapid PHP-MySQL development engine that offers simple shorthand syntax, pagination, ORM, caching   Learn More

Install LAMP on Windows 10 with WSL

By Shay Anderson on March 2018
Knowledge Base  /  MS OS  /  Install LAMP on Windows 10 with WSL
The following instructions will walk you through installing LAMP on Windows 10 using Windows Subsystem for Linux (WSL)
This tutorial installs LAMP on WSL using Windows 10 version 1709 build 16299.309. Use run > winver to find the Windows 10 version.

1. First, use the windows key and search for "turn windows features on or off", then in the features list enable Windows Subsystem for Linux (Beta). Next, install Ubuntu through the Microsoft Store.

2. After install, open Ubuntu in Windows. This will download the entire Ubuntu image and finish install. Set the username and password. Then run update:
# apt-get update && apt-get upgrade
3. Next setup SSH. First, uninstall the SSH service:
# apt-get remove openssh-serverReinstall the SSH service:
# apt-get install openssh-serverEdit the /etc/ssh/sshd_config file:
# cp -v /etc/ssh/sshd_config /etc/ssh/sshd_config.ORIG
# nano /etc/ssh/sshd_config
Make these edits:
- Change: port 22 to 2222
- Change: PermitRootLogin Yes to PermitRootLogin No
- Change: PasswordAuthentication no to PasswordAuthentication yes (not required if SSH keys are used)
- Change: UsePrivilegeSeparation yes to UsePrivilegeSeparation no
- Add/Uncomment: ListenAddress 0.0.0.0
- Add: AllowUsers {username} and UseDNS no

Restart the SSH service:
service ssh --full-restartNow use an SSH client, like putty, to SSH into the server using 127.0.0.1:2222

4. Add hostname to hosts file:
# cat /etc/hostname
{hostname}
Add the hostname to /etc/hosts like: 127.0.1.1 {hostname}

5. Install Apache:
# apt-get install apache2Test configuration:
# apache2ctl configtestEnable Apache mods:
# a2enmod rewrite
# a2enmod headers
Start Apache: # service apache2 start
6. Install MySQL:
# apt-get install mysql-serverEdit MySQL configuration file (optional):
[mysqld]
#default-storage-engine=MyISAM
#wait_timeout = 36000
#max_allowed_packet = 2000M

# query log
#general_log = 1
#log_output = table

# innodb setup
innodb_file_per_table = 1
innodb_file_format = barracuda
Start MySQL service:
# service mysql startSet root password:# mysql
> SELECT user,host,authentication_string FROM user;
> FLUSH PRIVILEGES;
> ALTER USER 'root'@'localhost' IDENTIFIED BY 'my-password';
If the password query doesn't work use:> UPDATE mysql.user SET authentication_string = PASSWORD('my-password'), password_expired = 'N' WHERE User = 'root' AND Host = 'localhost';
> FLUSH PRIVILEGES;
Or another possible fix to connection issues:> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'my-password';Then transfer existing DBs using on existing server: # mysqldump --single-transaction --quick --lock-tables=0 --routines --triggers --skip-lock-tables --all-databases > db.sql
This will install MySQL version 5.7.x. Optionally, 5.5 or 5.6 can be installed.

7. Install PHP:
# apt-get install php7.0 php7.0-cli php7.0-common php7.0-curl php7.0-gd php7.0-mbstring php7.0-mysql php7.0-xml libapache2-mod-phpOr PHP 7.2:# apt-get install php7.2 php7.2-cli php7.2-common php7.2-curl php7.2-gd php7.2-mbstring php7.2-mysql php7.2-xml libapache2-mod-phpTest version:
# php -vEdit file /etc/apache2/mods-enabled/dir.conf:
# cp -v /etc/apache2/mods-enabled/dir.conf /etc/apache2/mods-enabled/dir.conf.ORIG
# nano /etc/apache2/mods-enabled/dir.conf
Add index.php to beginning of DirectoryIndex list: <IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
Restart Apache: # service apache2 restart
Install & Configure XDebug (Optional)
Install:
# apt-get install php-xdebugEdit file /etc/php/7.2/apache2/php.ini and add section at end of file (config for Netbeans IDE):[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_handler = "dbgp"
#xdebug.remote_host = localhost
xdebug.remote_port = 9000
xdebug.remote_mode = req
xdebug.idekey = "netbeans-xdebug"
Restart Apache: # service apache2 restart

8. Because services won't autostart using WSL Ubuntu, a script can be created to start services, example: # nano /startAdd the services to start: #!/bin/sh

service ssh start
service mysql start
service apache2 start

echo "System ready."
Add permissions: # chmod u+x /startNow when Ubuntu is started simply run the two commands: # sudo -s
{enter password}
# /start

A MS Windows OS network share can be mounted in WSL using:
# mkdir /mnt/myshare
# mount -t drvfs '\\sharename\sharedir' /mnt/myshare
Contact
Contact

Contact us today for a free quote or software consulting

Explore
Recent Projects
Check out recent programming and software development projects
Knowledge Base
View recent technology topics and notes
Get a Quote
Want a quote for software development?
SHAYANDERSON

Enterprise Software / Database / Server

Software Engineer, PHP Programmer
& Web App Developer in Tampa Bay, Florida
Copyright © 2023 ShayAnderson.com
All Rights Reserved