domingo, 6 de março de 2022

Install the LAMP Stack on Windows WSL

0 comentários

 Fonte: How to Install the LAMP Stack on Windows WSL - Website for Students


Install Apache HTTP Server

The A in LAMP stands for Apache HTTP server. Apache is the most popular open source web server powering majority of the websites online.

To install Apache on Ubuntu, run the commands below:

sudo apt update
sudo apt install apache2

After installing Apache2, the commands below can be used to stopstart and restart Apache2 services.

sudo service apache2 stop
sudo service apache2 start
sudo service apache2 restart

To validate that Apache is installed and functioning, open your web browser and browse to the server’s hostname or IP address.

You should get a test page if every works.

http://localhost

lamp windows wsl ubuntu

Install MariaDB Database Server

M in LAMP stands for MySQL or MariaDB database server. For this tutorial, we’re going to be installing MariaDB instead.

MariaDB is a true open source database server you can run with your projects. It is fast, secure and the default server for almost all Linux.

To install MariaDB, run the commands below:

sudo apt-get install mariadb-server mariadb-client

After installing MariaDB, the commands below can be used to stopstart and restart MariaDB services.

sudo service mysql stop
sudo service mysql start
sudo service mysql restart

Next, run the commands below to secure the database server with a root password if you were not prompted to do so during the installation.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

To verify and validate that MariaDB is installed and working, login to the database console using the commands below:

sudo mysql -u root -p

Type the root password when prompted.

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 46
Server version: 10.3.29-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

If you see a similar screen as shown above, then the server was successfully installed.

PHP and Related Modules

The P in LAMP stands for PHP. PHP is a general-purpose scripting language the glues all the other components of the stack.

To install PHP and recommended modules, run the commands below.

sudo apt install php libapache2-mod-php php-common php-mysql php-gmp php-curl php-intl php7.4-mbstring php-xmlrpc php-gd php-xml php-cli php-zip

That should get PHP installed with recommended PHP modules that you can run with many PHP based applications.

To validate that PHP is installed, run the commands below:

php -v

You should see an output like the one below:

PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

You can also test with a test php script and displays installed version as well as related modules that are enabled or disabled.

To do that, run the commands below to create a php test file called phpinfo.php

sudo nano /var/www/html/phpinfo.php

Then type the content below and save the file.

<?php phpinfo( ); ?>

Save the file.

Open your browser and browse to your server hostname followed by phpinfo.php

Restart Apache, then type the address and browse to the file.

http://example.com/phpinfo.php

You should see PHP default test page.

Leave a Reply