Month: March 2021

How to run PHP script on the command line (without web server)

How to run PHP script on Windows command line

If you want not only the ability to run PHP from the command line, but also a full-fledged Apache + PHP + MySQL web server on Windows, then complete the installation according to this article.

To run PHP on the command line, you do not need to install a web server, just download and unpack the archive with the PHP interpreter.

Let's start by downloading the latest PHP version for Windows from the official website: https://windows.php.net/download/

There are several options that differ:

  • Version (e.g. 8.0, 7.4, 7.3)
  • Computer architecture, (x64 and x86)
  • Thread Safe or Non Thread Safe

Choose the latest version, between x64 and x86 choose the same version as your webserver. That is, if your Apache is 64-bit, then PHP must be 64-bit as well. Always choose ‘Thread Safe’ version.

There are two links for each file:

  • Zip
  • Debug Pack

Choose Zip because the debug package is only for those who really know why they need it. This does not mean debugging PHP scripts, but debugging the PHP interpreter itself.

If you often run PHP scripts from the Windows command line, it is highly recommended to To add PHP path to %PATH% environment variable on Windows. This eliminates the need to specify the full path to the php.exe file every time.

Now that PHP is installed and the path to php.exe has been added to the Windows environment variable, open a command prompt by pressing the Win+x key combination and select Windows PowerShell.

To check what works fine, look at the PHP help:

php -h

In fact, we are running the php.exe file, but the extension can be dropped. That is, the previous entry is equivalent to

php.exe -h

How to run .php script on Windows and Linux command line

The following command is used to run the .php file in the Windows console:

php -f path\to\file.php

The -f option can be skipped, that is, the previous and next commands are the same:

php path\to\file.php

I created a test file which is located in the path C:\Users\Alex\Documents\PHP\test.php then I can run it in PHP like so:

php -f C:\Users\Alex\Documents\PHP\test.php

or like this:

php C:\Users\Alex\Documents\PHP\test.php

How to pass arguments to a PHP script on the command line

To pass arguments to the script, list them after the filename, separated by a space. If the arguments themselves contain spaces or other characters that are special to the command line shell, then enclose those arguments in single or double quotes.

php path\to\file.php 'arg1' 'arg2' 'arg3' 'arg_n'

An example of running a PHP script with three arguments:

php C:\Users\Alex\Documents\PHP\test.php 'Alex' 'hackware.ru' 'Admin'

How to access arguments in a PHP script

The arguments passed are contained in the $argv array. Moreover, the ordinal number of the argument corresponds to the number in the array. That is, the first argument will be placed in $argv[1], the second in $argv[2], and so on.

The very first element of the array named $argv[0] contains the full path to the script to run.

The content of the test.php file:

<?php

echo 'Name: ' . $argv[1] . PHP_EOL;
echo 'Web site: ' . $argv[2] . PHP_EOL;
echo 'Status: ' . $argv[3] . PHP_EOL;

Let's run it and pass three arguments to the script:

php C:\Users\Alex\Documents\PHP\test.php 'Alex' 'hackware.ru' 'Admin'

How to get data from user in the console in PHP

Thanks to the passed arguments, the script can perform actions not only with the data written in it, but also with other values specified when the script was run.

By the way, when working in a web server environment, that is, when a PHP script performs tasks for a website, the ability to pass arguments to it is implemented using the HTTP GET and POST methods. These arguments are passed before starting the script, and after starting the PHP script, new data cannot be sent – you need to wait for the program to finish running, and, if necessary, run it again with new data.

While the script is running, it may be necessary to enter new data; in the console, this is achieved using a prompt, into which the user can enter a value and press Enter to pass it to the script. In the context of a website, there is no such possibility – to transfer data already during the execution of the script. That is, the console launch of PHP scripts with arguments is not only easier (no need to fiddle with an HTML form), but even more flexible.

PHP uses the readline function to query the user.

This feature works the same on both Windows and Linux. Moreover, on Linux, it has the interactive capabilities of Bash, for example, it saves the input history, to which you can return using the arrows. On Windows, this feature has appeared since PHP 7.1.

If you really need to, you can configure the auto-completion of the input data. All GNU Readline features are covered here. I will only touch on readline, which reads the line entered by the user. With this function, you can specify one optional argument – a string that will be shown to the user at the prompt.

An example of a PHP console script that asks the user for data at a command line prompt:

<?php

$len_min = readline("The minimum number of characters in a password is: ");
$len_max = readline("Maximum number of characters in a password: ");
$base = readline("Password base (0 - digits; 1 - lowercase letters; 2 - uppercase letters): ");

echo "Received initial data: \r\nPassword length from $len_min to $len_max characters ";
switch ($base) {
	case 0:
		echo "and the base of the password is in lowercase digits.";
		break;
	case 1:
		echo "and the base of the password is in lowercase letters.";
		break;
	case 2:
		echo "and the base of the password is in uppercase letters.";
		break;
}

How to execute PHP commands interactively

If you need it, then you can work with the PHP interpreter interactively, entering the code line by line. In this case, the code is executed after pressing the Enter button, but the values of the variables are saved within one session. That is, you can assign a value to a variable and then use it in other lines.

To run an interactive shell:

php -a

How to run individual PHP commands

Use the -r option to run individual commands:

php -r 'echo 2**100;'

Ubuntu in VirtualBox does not stretch to full screen although Guest Additions are installed (SOLVED)

1. Are the Guest Additions actually installed?

First, make sure you actually have Guest Additions installed.

It is recommended to update the guest OS to the latest package versions:

sudo apt update
sudo apt full-upgrade

After the update is complete, restart your computer:

reboot

There is a guest additions package in the standard repositories. It can be installed as follows:

sudo apt update
sudo apt install virtualbox-guest-dkms

2. Enabling full screen mode and resizing the guest OS screen

To switch to full screen mode, press Host+A, or go to Menu → View → Full screen mode.

If this did not help either, then maximize the virtual machine window to the maximum, then go to Menu → View → Auto-resize Guest Display.

3. Changing the type of graphics controller

If that doesn't work, try with different graphics controllers. With the virtual machine turned off, you need to go to its settings, then to the Display tab.

On this tab, you need to set VMSVGA or VboxVGA as the Graphics controller - try different controllers and see which one works with “Auto-resize Guest Display”.

4. Reinstallation and reconfiguration of virtualbox-guest-dkms:

sudo apt remove virtualbox-guest-dkms --purge
sudo apt install virtualbox-guest-dkms
sudo dpkg-reconfigure virtualbox-guest-dkms

5. Increase the video memory size

In the settings of the virtual machine, increase the video memory size to the maximum

6. Manually change the screen resolution settings

Go to the screen resolution settings of your guest virtual machine and select another, more appropriate.

So

Some of these methods should help you. Write in the comments – which one, it will help other users who have encountered the exact same problem.

If all else fails, then it is recommended to update VirtualBox to the latest version, and also make a full system update and reboot:

sudo apt update && sudo apt full-upgrade -y
reboot

Why does my laptop beep during operation or when shutting down?

Why is the motherboard beeping?

When the laptop is turned off, the “beeper”, “speaker” is triggered. Why is this happening?

Problems at the hardware level are sometimes so serious that the computer cannot start – for example, the RAM is faulty or the contacts of the central processor are loose – in this case, it will not be possible to turn on the computer so that you can analyze the causes of its problem.

Therefore, a self-diagnosis mechanism is built into the motherboards, and to inform the user about the causes of the problem, beeps are emitted – their number and duration encodes the cause of the problem.

We do not come across beeps (squeaks) when turning on the computer very often, since such serious hardware problems are rare.

But even less often, we encounter sound signals from the motherboard while the computer is running or when it is being turned off. This article will tell you about the possible reasons why the computer beeps already during operation.

There can be several reasons why the computer beeps during operation, usually these are notifications about which the user should be aware.

Low battery alarm

In BIOS, this setting may be called:

  • Battery low alarm beep
  • Low battery alarm

If you do not like that the laptop starts beeping when the battery is low, then go to BIOS and disable this setting.

Beep when power off

If, when you disconnect the power adapter, your laptop starts to beep, then you can disable this setting in the BIOS. To do this, look for options there:

  • Power control beep
  • Power beep

The reason for the squeak of the motherboard, which appears at random moments, may be a problem of loss/intermittent power connection. Many laptops beep when you plug in or unplug the power adapter (Lenovo is well known for this). This could indicate a problem with the power adapter cord, the power adapter itself, or a connector inside the computer. You can visually inspect the connector built into the laptop for problems.

As a quick test, you can wiggle the cord near where it connects to your laptop and listen for beeps. You can also look at your screen and see if it goes from plugging in and charging to battery mode. This is the most common cause of random beeps.

Squeak when opening or closing laptop lid

In BIOS, this setting is called Panel close alarm. You can turn it off if you want.

Beep when waking up from sleep or hibernation

Some laptop models beep when the computer wakes up. Again, you can disable this setting in the BIOS.

If none of the above applies to your case, then go to BIOS/EFI and look for settings there with the word Beep, for example, “Beep and Alarm”. Signals may have been set to other events.

Beep due to computer overheating or other malfunction

Also check that the temperature of the computer is far from critical. In this case, most motherboards start to squeak.

Check your computer for hardware problems.

Error “Failed to talk to init daemon” (SOLVED)

You can use command line to shutdown Linux computer, following command will shutdown computer:

shutdown -h now
systemctl halt

To reboot, you can use the following command:

systemctl restart

They usually work fine, but on some distributions they require elevated privileges, which means they need to be run with sudo.

But in single user mode, these commands result in the following error:

System has not been booted with systemd as init system (PID 1). Can’t operate.
Failed to connect to bus: Host is down
Failed to talk to init daemon.

Linux single user mode is used, for example, to reset a forgotten password for the root user or any other user. The operation of the computer in this mode is different from normal and, as you can see from the error message, the system was not booted with systemd as the init of the system, so it cannot connect to the bus and cannot send commands to the init daemon.

Related: How to reset a forgotten login password in Linux

However, there is still a way to turn off the computer.

To log out safely, type:

sync
umount /

These commands instruct the OS to write the changes made to the file system (for optimization purposes, they can be stored in the cache), and then unmount the root file system.

After that, to turn off the computer, run:

poweroff -f

Or restart your computer with the command:

reboot -f

Even if these commands did not help, then use the double -f options.

To turn off your computer run:

poweroff -f -f

Or restart your computer with the command:

reboot -f -f

The -f option means forced immediate stop, shutdown, or reboot. When specified once, this results in an immediate but clean shutdown by the system manager. If specified twice, it results in an immediate shutdown without contacting the system manager.

When using the -f option with systemctl halt, systemctl poweroff, systemctl reboot, or systemctl kexec, the selected operation is performed without shutting down all units. However, all processes will be forcibly terminated, and all file systems will be unmounted or remounted read-only. Therefore, it is a radical, but relatively safe option to request an immediate restart. If you specify --force twice for these operations (except for kexec), they will be executed immediately, without killing any processes or unmounting any filesystems. Warning: specifying --force twice for any of these operations can result in data loss. Note that if you specify --force twice, the selected operation is performed by systemctl itself and is not associated with the system manager. This means that the command must be executed even if the system manager fails.

How to install PowerShell on Arch Linux, Manjaro, BlackArch

PowerShell on Linux

PowerShell is a cross-platform automation and configuration tool/platform. PowerShell has a large number of system administration-oriented commands. But at the same time, PowerShell is a full-fledged programming language that allows you to write functional programs (scripts).

Note that PowerShell 5 is currently preinstalled on Windows by default, but this manual shows the installation of the latest version of PowerShell 7. On Windows, you can also install PowerShell 7.

Due to the differences between Windows and Linux operating systems, not all PowerShell functions work on Linux.

Installing PowerShell 7 on Arch Linux, Manjaro, BlackArch

It is recommended to install the pikaur utility according to the article “Automatic installation and update of AUR packages” and then just run the command:

pikaur -S powershell-bin

If you don't want to install pikaur, then run the following command sequence to install PowerShell:

git clone https://aur.archlinux.org/powershell-bin.git
cd powershell-bin
makepkg -si

How to run PowerShell on Arch Linux, Manjaro, BlackArch

To start an interactive PowerShell session, run the command:

pwsh

Linux PowerShell Examples

To list all PS commands on your computer, open PowerShell (pwsh command), and enter there:

Get-Command

It is possible to filter the information displayed by the Get-Command command. Let's say you want to see PowerShell commands containing the word “Alias”, for this you need to run the following command:

Get-Command -Name *Alias

To display help about a command (cmdlet) use the following:

Get-Help COMMANDLET

For example, to display help about the Get-Alias cmdlet:

Get-Help Get-Alias

To get the most complete help on Get-Command, do the following:

Get-Help Get-Command -Full

To display the contents of a folder (in this case the root of the file system), run:

Get-ChildItem /

To list processes run:

Get-Process

To stop the process with ID 10500 use the command as shown below:

Get-Process -Id 10500 | Stop-Process

See also “Linux PowerShell Basics (Beginner's Guide)”.

How to install PowerShell in Linux Mint

The PowerShell installation instructions often forget about Linux Mint, apparently, their authors believe that Linux Mint users do not need PowerShell. Let's fill that gap and take a look at how to install PowerShell in Linux Mint.

Linux Mint has several versions - “regular”, which, by the way, also differs in desktop environments (Cinnamon, MATE, Xfce) and LMDE (stands for Linux Mint Debian Edition).

How to install PowerShell in Linux Mint 20.1 (Cinnamon, MATE, Xfce)

Installing PowerShell in Linux Mint is the same regardless of the desktop environment (Cinnamon, MATE, Xfce).

Update the package list:

sudo apt update

Install the dependencies:

sudo apt install -y wget apt-transport-https software-properties-common

Download the GPG keys of the Microsoft repository:

wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb

Register the GPG keys for the Microsoft repository:

sudo dpkg -i packages-microsoft-prod.deb

Update the package list after adding packages.microsoft.com:

sudo apt update

Enable the “universe” repositories:

sudo add-apt-repository universe

Install PowerShell:

sudo apt install -y powershell

Start PowerShell:

pwsh

PowerShell will update automatically when all packages on the system are updated. You can separately launch the PowerShell update with the commands:

sudo apt update
sudo apt install powershell

If you want to remove PowerShell from Linux Mint, then run the command:

sudo apt remove powershell

How to install PowerShell in LMDE

Download the GPG keys of the Microsoft repository:

wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb

Add the GPG keys for the Microsoft repository:

sudo dpkg -i packages-microsoft-prod.deb

Update the list of programs:

sudo apt update

Install PowerShell:

sudo apt install -y powershell

Starting PowerShell:

pwsh

PowerShell will update automatically when all packages on the system are updated. You can separately launch the PowerShell update with the commands:

sudo apt update
sudo apt install powershell

If you want to remove PowerShell from LMDE, then run the command:

sudo apt remove powershell

See also “Linux PowerShell Basics (Beginner's Guide)”.

Source

Linux PowerShell Basics (Beginner’s Guide)

PowerShell for Linux

In recent years, there has been a trend at Microsoft to cross-platform some of its products and open their source. Also Linux itself became part of Windows in the form of a subsystem. PowerShell, which was originally a Windows-only component, was released as open source and became cross-platform on August 18, 2016, available for Linux and Mac OS.

PowerShell is a task automation and configuration management system developed by Microsoft. It consists of a command interpreter (shell) and a scripting language built on the .NET Framework.

It offers full access to COM (Component Object Model) and WMI (Windows Management Instrumentation), thereby allowing system administrators to perform administrative tasks on both local and remote Windows systems, as well as WS-Management and CIM (Common Information Model), allowing you to administer remote Linux systems plus network devices.

Within this framework, administrative tasks are mostly performed by specific .NET classes called cmdlets (pronounced command-let). Similar to shell scripts in Linux, users can create scripts or executables by storing groups of cmdlets in files following specific rules. These scripts can be used as standalone utilities or command line tools.

How to install PowerShell on Linux

Installation on various Linux distributions is described in the official documentation “Installing PowerShell on Linux”.

But in the official documentation there is a lack of information about some distributions, to fill this gap, separate instructions were written:

Features of PowerShell on Linux

1. Command case is not important in PowerShell

In Windows, the case of commands and names of files and folders is not important – this is a big difference from Linux, where the case of both commands and files matters.

PowerShell inherits a feature from Windows – case is not important. Although this tutorial shows commands written in different case (for example, Get-Date), this is actually for better readability and it doesn't matter if you enter Get-Date, GET-DATE, get-date, or gET- dATE.

2. Some commands are missing

The set of commands in PowerShell depends on the available modules, that is, even on a Windows computer, if you install, for example, Active Directory, then new commands will appear in PowerShell.

The Linux version of PowerShell lacks some of the commands found in the standard Windows PowerShell, primarily when it comes to Windows-specific things.

3. Many aliases and abbreviations

You can see in the scripts and examples of PowerShell commands the unusual writing of commands – in PowerShell, abbreviated notation is allowed, and there are also many aliases, that is, the same action can be performed by commands written in different ways.

4. PowerShell versions

Please note that PowerShell 5 is currently preinstalled on Windows by default, and this shows the installation of the latest version of PowerShell 7. On Windows, you can also install PowerShell 7, but this version will not replace the preinstalled version – there will be 2 versions of PowerShell, moreover, when launched from the “Power user menu” (Win+x) will open PowerShell 5, and when you start Windows Terminal, PowerShell 7 will open.

5. Skipping option names

Some options are positional and when specifying their values, you can skip the option names – at first this may seem confusing.

How to use Powershell on Linux

In this section, we will have a short introduction to Powershell; where we will see how to start PowerShell, run some basic commands, see how to work with files, directories and processes. Later, you will learn how to list all available commands, show command help and aliases.

To start Powershell, enter:

pwsh

You can check the Powershell version with the following command:

$PSVersionTable

If you only need the version number, then use the following construction:

Get-Host | Select-Object Version

Running some basic Powershell commands on Linux.

Show current date:

Get-Date

Show computer uptime:

Get-Uptime

Show current working directory:

Get-Location

Working with files and directories in Powershell

1. Create a new empty file in two ways:

New-Item hackware.stuff

Or:

"">hackware.stuff

Then add content to it and view the content of the file.

Set-Content hackware.stuff -value "Делаем pwsh.ru - это весело!"
Get-Content hackware.stuff

2. Delete the file in PowerShell.

Remove-Item hackware.stuff
Get-Content hackware.stuff

3. Create a new directory.

Take a look at the following set of commands:

mkdir hackware-files
cd hackware-files
"">domains.list
ls

Sound familiar? Yes, as already mentioned, there are many aliases in PowerShell. The same actions can be performed with the following commands:

New-Item hackware-files -ItemType "directory"
Set-Location hackware-files
New-Item domains.list
Get-ChildItem -Name

In fact, the commands don't just do the same thing – they are identical.

4. To display a long list that displays detailed information about files and directories, including mode (file type), last modified time, enter:

dir

Or:

Get-ChildItem

To display the contents of a specific folder (in this case, the root of the file system), run:

Get-ChildItem /

Working with Processes in PowerShell

How to view all running processes in Linux using PowerShell:

Get-Process

To view detailed information about one or a group of running processes with a given name, specify the process name as an argument to the previous command as follows:

Get-Process httpd

The value of the units in the output is above:

  • NPM(K) – amount of non-paged memory that the process is using, in kilobytes.
  • PM(K) – amount of pageable memory that the process is using, in kilobytes.
  • WS(K) – size of the working set of the process, in kilobytes. The working set consists of the pages of memory that were recently referenced by the process.
  • CPU(s) – amount of processor time that the process has used on all processors, in seconds.
  • ID – process ID (PID).
  • ProcessName – name of the process.

To get all possible data about one or more processes use a command of the form (replace httpd with the name of the process you are interested in):

Get-Process httpd | Format-List *

To stop the process with ID 10500 use the command as shown below:

Get-Process -Id 10500 | Stop-Process

Getting Help in PowerShell

To learn more, get a list of all PowerShell commands for various tasks:

Get-Command

It is possible to filter the information displayed by the Get-Command command. Let's say you want to see PowerShell commands containing the word “Alias”, for this you need to run the following command:

Get-Command -Name *Alias

To display help about a command (cmdlet) use the following:

Get-Help CMDLETS

For example, to display help about the Get-Alias cmdlet:

Get-Help Get-Alias

To get the most complete help on Get-Command, do the following:

Get-Help Get-Command -Full

Aliases in PowerShell

To see all available command aliases, enter:

Get-Alias

To get information about a specific alias, enter its name:

Get-Alias -Name pwd

PowerShell Command History

Last but not least, display the command history (a list of the commands you ran earlier) like this:

history

So this was an introduction to PowerShell on Linux. Of course, PowerShell can actually do much more than create files and show running processes.

How to enable spell checker in Google Chrome. How to add languages for spell checker

The Google Chrome web browser has a built-in spell checker, which is very convenient when writing messages, comments on websites, communicating in web chats, and so on.

You can configure the spell checker: choose offline or online checker (more accurate), as well as enable or disable languages for spell checking.

Online and offline spell checker in Google Chrome

To control spelling settings, click the button with three vertical dots and select “Settings”:

Then select “Advanced” → “Languages

Another way to get into these settings is to enter “chrome://settings/languages” into the web browser address bar.

Here you can choose how you want to check your spelling:

  • Basic spell check (only offline dictionaries and checking rules are used, a less accurate method, but your texts are not sent anywhere, the check takes place on a computer)
  • Enhanced spell check (Uses the same spell checker that’s used in Google search. Text you type in the browser is sent to Google. This is a more accurate spell check using Google's best practices, but it works for those who don't mind that its texts are sent to third-party servers)

By default, the basic spell check is enabled - it will suit most users, it is not necessary to change this.

Here you can turn off the spell check altogether.

How to enable spell checking for another language in Google Chrome

As you can see in the screenshot above, I have the spell checker disabled for Russian. To turn it on, just move the slider.

How to add languages for spell checker in Google Chrome

Let's say I need the web browser to check spelling not only for Russian and English, but also, for example, for French, how can I do this?

If in the list of available spelling checkers you do not see the language you want, this means that you need to add that language first.

Expand “Language”.

Click “Add Languages”.

In the window that appears, you can find the language or scroll through the list and put a check mark next to it.

Spell checking can now be enabled for this language:

How to display all environment variables at the Windows command prompt

This article will show you how to display all environment variables from the Windows command line.

PowerShell and CMD

First of all, you need to distinguish what kind of program you are working in. The first appeared CMD - Windows command line, shell. For many years, CMD was the only option for running on the Windows command line.

Then PowerShell came along. In the beginning, it was an environment that could be specially launched. In recent years, PowerShell has become more common, in the “Power User Menu”, which is invoked by the Win+x keyboard shortcut, PowerShell has replaced CMD. Also, the new Terminal uses PowerShell by default.

The commands for displaying all environment variables depend on whether you are in PowerShell or CMD, so you need to differentiate between them.

PowerShell looks like this:

Or like this:

That is, the command line prompt begins with “PS”.

And the CMD looks like this:

Or like this:

How to list all environment variables in PowerShell

In PowerShell, use one of the following commands:

gci env:
ls env:
dir env:

They are not only equivalent, in fact, they are just aliases for the same command. That is, there is no difference in their use.

How to display all environment variables in CMD

To display environment variables in CMD use the command:

SET

To cut the output in one screen with the ability to scroll through the list, use the following construction:

SET | more

To save the output to a file:

SET > output.txt

This text file, output.txt, can be opened in any editor such as Notepad.

To display the value of a specific variable, use the familiar set command with the variable name:

set VARIABLE

For instance:

set PATH

The set command prints the value of all variables that start with the line VARIABLE. For example, the previous command will print the values of the PATH and PATHEXT variables.

And the following command will print the values of all variables whose name begins with P:

set P

Note that command names on Windows are not case sensitive.

How to install a web server (Apache, PHP, MySQL, phpMyAdmin) on Linux Mint, Ubuntu and Debian

If you are a webmaster, or a PHP programmer, or you just need to run a website on your computer, then you can do it using a web server. On Linux, the web server (Apache) and related components (PHP, MySQL, phpMyAdmin) are installed in just a few commands.

This tutorial will show you how to set up a web server for sites on Linux Mint, Ubuntu and Debian.

How to install Apache, PHP, MySQL, phpMyAdmin on Linux Mint, Ubuntu and Debian

We will do most of the operations in the command line - the Linux terminal.

Open a terminal and run the following two commands in it:

sudo apt update
sudo apt install apache2 default-mysql-server php phpmyadmin

Answer No to the configuration prompt with dbconfig-common:

Use the Tab key to move between items and Enter to continue.

Select “apache2”:

Use the Space key to select items, use the Tab key to move between items, and press Enter to continue.

That's all! The web server (a bunch of Apache, PHP, MySQL, phpMyAdmin) is installed and ready to work. Open the link http://localhost/ in your browser

You will see the standard Apache page:

phpMyAdmin is available at http://localhost/phpmyadmin/

To start the web server every time you turn on the computer, run the command:

sudo systemctl enable apache2
sudo systemctl enable mysql

How to change URL path of phpMyAdmin. How to enable and disable phpMyAdmin

If during the installation of phpMyAdmin you chose not to configure it for use with the Apache web server, use the command to enable phpMyAdmin:

sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-enabled/

Restart the web server for the changes to take effect:

sudo systemctl restart apache2

To disable phpMyAdmin use the command:

sudo rm /etc/apache2/conf-enabled/phpmyadmin.conf

Restart the web server for the changes to take effect:

sudo systemctl restart apache2

There is an important line in the /etc/phpmyadmin/apache.conf file:

Alias /phpmyadmin /usr/share/phpmyadmin

Its essence is that the URL /phpmyadmin (for example, http://localhost/phpmyadmin) begins to correspond to the /usr/share/phpmyadmin folder. That is, the phpMyAdmin files (scripts) are physically located in /usr/share/phpmyadmin, and not in the web server directory (for example, /var/www/html/).

Many automatic scanners of “hidden” files and folders of a web server and sites check the “phpmyadmin”, “pma” and other similar directories. You can hide your phpMyAdmin nicely by changing the Alias. For instance:

Alias /lkjgler94345 /usr/share/phpmyadmin

phpMyAdmin will now be available at http://localhost/lkjgler94345 - not easy to find.

phpMyAdmin setup

By default phpMyAdmin does not allow login without password. If you have not set a password for the MySQL DBMS, then you have two options to choose from:

  • set password
  • make changes to phpMyAdmin setting to allow passwordless login

It is recommended to set a password for the database. To change the password, you can use the script:

sudo mysql_secure_installation

If you want to allow logging into phpMyAdmin without a password, then open the file

sudo gedit /etc/phpmyadmin/config.inc.php

Find the second (there are two) line

// $cfg['Servers'][$i]['AllowNoPassword'] = TRUE;

and uncomment it (remove the two slashes from the beginning of the line) to get:

$cfg['Servers'][$i]['AllowNoPassword'] = TRUE;

Most likely, when connecting, you will receive a surprise in the form of the error “#1698 - Access denied for user 'root'@'localhost'”. Step-by-step actions for its solution in this manual.

Where are the sites on the Apache web server?

By default, the root folder for web documents is /var/www/html. In /var/www you can create your own virtual hosts.

The /var/www/html folder and all files inside it belong to the root user.

For you to be able to modify, add, delete files in this folder, you need to use sudo. For example, with the following command, you will open a file manager to manage the contents of a folder.

sudo nemo /var/www/html

All other programs that make changes to /var/www/html must also be run with sudo.

On a local server, for ease of use, you can make yourself the owner of this folder:

sudo chown -R $USER:$USER /var/www/html

Now you and the programs launched on your behalf do not need superuser privileges to work with the contents of this directory:

nemo /var/www/html

Apache index files

If the user requests from the web server not a file, but a directory, then the server looks for files index.html, index.php, index.htm, etc. in it. If these files are in this directory, then their contents are shown. These files are called index files. If there are two or more such files in a directory at once, then one of them is shown in accordance with the set priority.

You can see which files are index files for your server and in what order their priority is arranged in the file

sudo gedit /etc/apache2/mods-enabled/dir.conf

There you will see something like:

<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

Typically, users want to move the PHP index file (index.php) to the first position after DirectoryIndex, so that something looks like this:

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

After making changes, save and close the file, restart the web server.

Conclusion

This tutorial showed you how to install Apache web server on your Linux Mint machine. In terms of its functionality, this server does not differ from the capabilities of hosting. You can test your sites on it, use it when learning PHP, install WordPress, etc. Moreover, this server can be made available to the local or even global network.

Loading...
X