How to set up a LAMP test environment on WSL
The Windows Subsystem for Linux was intended to reintroduce Windows as a development platform. With so many developments underway for the web, WSL is ideal for quickly setting up a web development environment by assembling a LAMP (Linux / Apache / MySQL / PHP) environment.
So let’s get started.
Install and start Apache
The Apache HTTP server may have more competition from newcomers like NGINX, but it is still a reliable web server. Moreover, it is very easy to install in Ubuntu WSL:
sudo apt install apache2
You may come across other tutorials that tell you how to use systemctl in Ubuntu to make systemd start the server. WSL does not use systemd to manage services. Instead, in Ubuntu on WSL you use the a service command to start and stop all services.
To start the Apache server, type:
sudo service apache2 start
To make sure it works, go to http: // localhost and you should see the default Ubuntu test page. WSL automatically maps the Ubuntu system port numbers to the ones that match your host system.
By default, Apache will serve the DocumentRoot from / var / www / html, you must therefore save your HTML files there.
Install and configure PHP
If you want to add more complex interactivity to your web pages, PHP is a widely used server-side scripting language. It is also fairly simple to install and configure for use with Apache.
To install PHP and the associated Apache module, use this command:
sudo apt install php libapache2-mod-php
To test your PHP installation, write the following short script and save it in the / var / www / html phone book. Let’s call it infophp.php. You will need root privileges to save the file in this directory.
Then navigate to http: //localhost/phpinfo.php, and you should see the PHP info page. You will now be able to embed PHP code in your web applications.
Configuring MariaDB for the database
If you want to be able to save data in your web application, such as usernames and passwords, you will need a database server. For many years, MySQL was a go-to open source relational database management system (RDBMS), but after Oracle acquired the project, some of the original developers integrated the project into MariaDB.
MariaDB is an instant replacement for MySQL, which allows users to use the same commands and any other plugins without having to spend too much time learning a new system.
To install MariaDB, use the following command:
sudo apt install mariadb
To start the server, use the a service previously mentioned command:
sudo service mysql start
Yes, it’s “mysql”, not “mariadb”. A lot of the commands refer to MySQL, but you’ll really be talking to MariaDB. That’s what the developers mean when they say MariaDB is an “instant replacement” for MySQL.
The default installation of MariaDB is quite insecure, with the root password for the MariaDB server empty. If you are just developing a web application on your own, security might not be an issue on your development system. Nonetheless, it is a good habit to harden up all the servers you run on your system, even if you are the only one using them.
Fortunately, MariaDB comes with a script that you can run to increase server security:
This will walk you through several steps, such as changing the database root password, disallowing remote root logins, and removing the default test database.
You can use MariaDB’s command line to configure and administer databases, but most people prefer to use a GUI. PhpMyAdmin is a very popular option. Installing it on WSL is also easy:
sudo apt install phpmyadmin
Ubuntu will also walk you through the initial setup of phpMyAdmin, including setting up a username and password. To use it, make sure Apache is up and running, then navigate to http: // localhost / phpmyadmin.
Enter the username and password you chose during the installation process and you will now be able to manage your database server from your browser.
You can now start developing web applications
Now that you’ve seen how easy it is to start developing web applications with WSL, you can start building the next Google or Amazon. Looking to expand your web development skills? You can take classes to learn more.
Do you want to become a web designer but you have no skills? Buy this pack and become a pro in no time.
About the Author