How to Set Up a LAMP Test Environment on WSL

[ad_1]

Windows Subsystem for Linux was intended to reintroduce Windows as a development platform. With so much development happening for the web, WSL is ideal for setting up a web development environment quickly by assembling a LAMP (Linux/Apache/MySQL/PHP) environment.

So let’s get started.

Install and Start Apache

Ubuntu WSL Apache test page

The Apache HTTP server might have more competition from upstarts like NGINX, but it’s still a reliable web server. Also, it’s very easy to install in Ubuntu WSL:

sudo apt install apache2

You might run across other tutorials that tell you how to use systemctl in Ubuntu to get systemd to start the server. WSL doesn’t use systemd for managing services. Instead, in Ubuntu under WSL, you use the service command to start and stop any services.

To start the Apache server, type:

sudo service apache2 start

To make sure it works, navigate to http://localhost and you should see the default Ubuntu test page. WSL automatically maps port numbers of the Ubuntu system to ones that match your host system.

By default, Apache will serve the DocumentRoot out of /var/www/html, so you should save your HTML files there.

Install and Configure PHP

PHP info page

If you want to add more complex interactivity to your web pages, PHP is a widely-used server-side scripting language. It’s also quite simple to install and configure to 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 directory. Let’s call it phpinfo.php. You’ll need root privileges to save the file in that directory.

<?php
phpinfo();
php?>

Then, navigate to http://localhost/phpinfo.php, and you should see the PHP info page. Now you’ll be able to incorporate PHP code into your web apps.

Setting Up MariaDB for Database

phpMYAdmin page

If you want to be able to save data to your web app, like usernames and passwords, you’ll 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 forked the project into MariaDB.

MariaDB is a drop-in replacement for MySQL, that 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 service command mentioned earlier:

sudo service mysql start

Yes, that’s “mysql,” not “mariadb.” A lot of the commands refer to MySQL, but you’ll really be talking to MariaDB. This is what the developers mean when they say that MariaDB is a “drop-in replacement” for MySQL.

The default MariaDB installation is pretty insecure, with the root password for the MariaDB server blank. If you’re just developing a web app by yourself, security might not be an issue on your development system. Still, it’s a good habit to harden any servers you’re running on your system, even if you’re the only one using them.

Fortunately, MariaDB comes with a script you can run to tighten the server’s security:

sudo mysql_secure_installation

This will walk you through several steps, such as changing the database’s root password, disallowing remote root logins, and removing the default test database.

Related: Database Engines to Consider for Your Next Project

You can use MariaDB’s command line to set up any databases and administer them, but most people prefer to use a graphical front end. 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 that Apache is up and running, then navigate to http://localhost/phpmyadmin.

Enter the username and password you chose during the installation process and now you’ll be able to manage your database server from your browser.

Now You Can Start Developing Web Apps

Now that you’ve seen how easy it is to start developing web apps with WSL, you can start creating the next Google or Amazon. Looking to extend your web development skills? You can take some courses to learn even more.


web dev
These Courses Will Help You Understand Web Development and Design

Want to be a web designer but don’t have any skills? Buy this bundle and become a pro in no time.

Read Next


About The Author

.



[ad_2]

Source link

Leave a comment

Your email address will not be published. Required fields are marked *