Laravel development environment on MX Linux from repositories

In this article we’ll setup Laravel 8 development environment onto MX Linux box. Since MX Linux is based on Debian, the instructions herein, though untested, may still be valid for any Debian based Linux. Unlike previous article where we used Bitnami Lamp bundled software, here we’ll use repositories to individually install all the components required for Laravel development environment.

First things first. Run update and upgrade commands:

sudo apt update
sudo apt upgrade

MariaDB Installation:

MariaDB is a fork of MySQL which has gradually taken over the original MySQL in the open source landscape. So, let’s install it by entering the following command:

sudo apt install mariadb-server

After installation the MariaDB will be be started.

Should you need to restart MariaDB, execute:

sudo service mysql restart

To stop the MariaDB service, execute:

sudo service mysql stop

To start MariaDB again, execute:

sudo service mysql start

To make the MariaDB server more secured, you’d want to use the script mysql_secure_installation provided with installation. So go ahead and execute:

sudo mysql_secure_installation

Since we’ve just installed MariaDB, and we haven’t set the root password yet, the password will be blank, so just press Enter when asked for ‘Enter current password for root (enter for none)’:

Just press Enter here.

OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorization. Set root password? [Y/n]

Enter Y.

New password:

Enter the password for root now.

Re-enter new password:

Enter the password confirmation.

Password updated successfully!

Reloading privilege tables.. … Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n]

Enter Y.

… Success!

Normally, root should only be allowed to connect from ‘localhost’. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n]

Enter Y.

… Success!

By default, MariaDB comes with a database named ‘test’ that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n]

Enter Y.

– Dropping test database…

… Success! – Removing privileges on test database… … Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n]

Enter Y.

… Success!

Cleaning up… All done! If you’ve completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!

The mysql_secure_installation script exits now.

Now you log into the MariaDB server through the client by executing:

sudo mysql

While in mysql client run:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root-Password-That-You-Set-Above';
flush privileges;
exit;

Now you can use user ‘root’ along with its password that you set above in Laravel database settings. Moreover, you can enter to mysql client by entering:

mysql -u root -p

Now if you want to stop MariaDB server, enter following command:

sudo mysqladmin shutdown -p

And then enter password for root.

Again, if you want to start the MariaDB server, enter:

sudo service mysql start

PHP 7.4 Installation:

Here, we’ll download PHP 7.4 from an updated repository. First, install some dependencies and download GPG key.

sudo apt -y install lsb-release apt-transport-https ca-certificates 
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

Then add repository.

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list

Next step is to Install PHP 7.4. Before installation, update system package list as follows:

sudo apt update

Then install  PHP 7.4 on MX Linux, by entering following command:

sudo apt -y install php7.4

To install additional PHP packages which would be required by Laravel, enter following command:

sudo apt install php7.4-bcmath php7.4-intl php7.4-mbstring php7.4-xml php7.4-mysql php7.4-zip php7.4-gd php7.4-mcrypt

Composer Installation:

Install PHP package manager Composer by following instructions as given at getcomposer.org. Or you may enter the following commands to install Composer version 2.1.6, which is the latest one at the time of writing;

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

This will create composer.phar in the current working directory which is executable and can be used by entering ‘php composer.phar’ command. However, it is recommended that you move this file to proper location to make it executable globally; so execute the following command:

sudo mv composer.phar /usr/local/bin/composer

Now, you can create Laravel project by entering following command:

composer create-project laravel/laravel myapp

You will have to change .env file in myapp directory as follows in order to use MariaDB in your Laravel app:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=root-password-as-you-set-above

Node.js Installation:

Down the road, you’ll be needing node.js too. So, install it by using a node version manager like n. To install n along with the latest node.js LTS version enter the following command:

curl -L https://git.io/n-install | bash -s -- -y

This will create n directory in your home directory and install n and latest node.js LTS version there. In order to make executable available system-wide, again change the .bashrc file as follows;

featherpad ~/.bashrc

At the end of the file, insert following line (of course, replace ‘sohail’ with your user directory name):

export PATH="/home/sohail/n/bin:$PATH"

Save and close .bashrc file. Exit Terminal and then reopen Terminal. Now, n, node, npm commands are available at the command prompt.

You can always uninstall n by executing n-uninstall or update it using n-update.

Leave a Comment