This tutorial is written to assist absolute beginners (to Linux Mint) to install and configure Apache, PHP, MySQL server and PhpMyAdmin on Linux Mint 21. No prior knowledge of Linux Command Line is required. After looking at many different resources online, I feel that most of them are either out of date or not exactly related to LM. Also installation of PhpMyAdmin is excluded in most of the illustrations. So, I decided to write this tutorial to help others and enable them to use LM for coding php websites. Happy coding!
Note: We're going to install most packages using terminal. Terminal can be opened by the keyboard shortcut
Ctrl
+ Alt
+ T
or by accessing the shortcut from Menu.* I request the Moderators and experienced forum members to please highlight any correction. Thank you.
What's in this tutorial
- How to Install Apache Web Server on Linux Mint
-- How to write to Apache Document Root /var/www (solution)
- How to Install PHP on Linux Mint
-- How to display php errors in Browser (solution)
- How to Install MySQL Server on Linux Mint
- How to Install PhpMyAdmin on Linux Mint
- How to Login to PhpMyAdmin (solution)
- How to change PhpMyAdmin Password (solution)
- Can't perform queries or operations in PhpMyAdmin (solution)
- How to solve incompatible with sql_mode=only_full_group_by error (solution)
Version Information:
The tutorial is written for Linux Mint version 21 and above. LM repositories support the following versions of concerned packages at the time of writing this tutorial:
- Apache ver 2.4.52
- PHP ver 8.1.2
- MySQL server ver 8.0.35
- PhpMyAdmin ver 5.1.1
Let's start:
First thing first... open the terminal first and run the following command:
[Hint:] copy / paste the commands to avoid typo (use shortcut
Ctrl
+ Shift
+ V
to paste)[Hint:] keep your internet connection open during entire process. All packages will be downloaded to your system from Linux Mint repositories prior to installation.
Code: Select all
sudo apt-get update
How to Install Apache 2 Web Server:
Run the following command to install Apache 2 Web Server:
Code: Select all
sudo apt install apache2
Y
.Once the installation is done, you may check the version of installed package using
apache2 -v
command in terminal. Or open http://localhost
in your browser.Done? Not yet exactly, the default DocumentRoot directory of apache2 is
/var/www/
. The DocumentRoot is the folder where we store our php code / project files. The directory should be owned by root
and you most probably not have permissions to write / save your php code files. Changing owner and permission of this directory is our last step setting up Apache for now.Run these two commands (one by one) in the terminal to enable write permission and change ownership of the directory:
Code: Select all
sudo chmod -R 755 /var/www
sudo chown -R $USER:$USER /var/www
How to Install PHP:
Installing PHP is pretty straight forward. Run the following command:
Code: Select all
sudo apt install php
Y
and wait for the installation process to complete.To know the version of installed package, run [php -v] command from terminal.
One little tweak: I would suggest one little tweak before we complete the PHP section here. PHP by default does not show errors in the browser when we run some php file from localhost. Rather, the execution of code stops at line containing some error. This is because display_errors is set to Off in php configuration (php.ini) file. I (personally) prefer to display code errors in the browser to make it easier to trace. Maybe someone don't. So, this step can be optional depending on your preference.
Here is how we can edit this setting in our php.ini file:
Code: Select all
sudo nano /etc/php/8.1/apache2/php.ini
;
is comment in php configuration file. Look for display_error = Off
in the file, replace Off
with On
press Ctrl+X
to exit and press Y
to save changes.Note:PHP configuration file is located in
/etc/php/8.1/apache2
folder at the time of writing this tutorial. One may have to search for php.ini
file in:/etc
>>php/
>> <php version>
>> apache2
folder.Restart apache service using this command:
Code: Select all
sudo service apache2 restart
test.php
file in [/var/www/html] directory with following code:
Code: Select all
<?php phpinfo(); ?>
Code: Select all
http://localhost/test.php
The process of installing and configuring PHP is complete. You may save your php projects / codes in
/var/www/html
folder to run from localhost.How to Install MySQL Server:
Go with the command below to initiate MySQL Server installation:
Code: Select all
sudo apt install mysql-server
Y
to start installation. Wait for the installation process to complete and run this command to check MySQL service status when done:
Code: Select all
sudo systemctl status mysql
How to Install PhpMyAdmin:
To install PhpMyAdmin, I would prefer to go with GUI method:
1. Open
Software Manager
from Menu
2. Search for
phpmyadmin
, click appropriate package from results to open and click Install
3. The installation process will prompt to choose Web Server... make sure to check
apache
and click Next4. The other prompt will ask whether
dbconfig-common
should be used, remember to check
this also and finish Installation.Note: Enter password for phpmyadmin if prompted during installation.. don't panic if it don't ask.
You may have to restart apache once again... do it from terminal:
Code: Select all
sudo service apache2 restart
Code: Select all
http://localhost/phpmyadmin
Can't login to PhpMyAdmin?
You may find login information to access phpmyadmin easily in case you forget it or if you're not asked to enter password for phpmyadmin during installation. Your login information is stored in
/etc/dbconfig-common/phpmyadmin.conf
file. To open it, run:
Code: Select all
sudo nano /etc/dbconfig-common/phpmyadmin.conf
dbc_dbuser='phpmyadmin'
line and password at dbc_dbpass='Jer6xx3xxxXx'
line. Don't make any change(s) in the file. Note down your login details and close it.How to change password for PhpMyAdmin:
To change the password of PhpMyAdmin or any other user, I prefer to go for MySQL Shell. There may be some more ways for PhpMyAdmin IKD. It's what I find easiest:
Code: Select all
sudo mysql
Code: Select all
sudo mysql -u root -p
Code: Select all
use mysql;
select user,host,plugin from user;
Code: Select all
ALTER USER 'phpmyadmin'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NewPassword';
phpmyadmin
is the user name, localhost
is the host and mysql_native_password
is the plugin. Exit MySQL terminal using exit;
command.Not able to perform queries or operations in PhpMyAdmin?
You may not be able to run queries or perform basic operations in PhpMyAdmin because MySQL PRIVILEGES are not granted to 'phpmyadmin'. Go through the following procedure to know what operations are allowed to phpmyadmin:
To access MySQL Shell, run
sudo mysql
or sudo mysql -u root -p
in the terminal and...
Code: Select all
SHOW GRANTS FOR 'phpmyadmin'@'localhost';
Code: Select all
GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, REFERENCES, RELOAD on *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
Code: Select all
GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
Finally run the FLUSH PRIVILEGES command immediately after CREATE USER or GRANT statement in order to reload the grant tables to ensure that the new privileges are put into effect:
Code: Select all
FLUSH PRIVILEGES;
Code: Select all
SHOW GRANTS FOR 'phpmyadmin'@'localhost';
exit;
command.How to solve incompatible with sql_mode=only_full_group_by error in MySQL:
This is the last topic, I would like to cover in this tutorial. Many old MySQL queries are rejected new MySQL versions having incompatible group by clause. Like this one:
Code: Select all
SELECT cust_id, cust_name from myorders group by cust_id;
We can resolve this error by disabling ONLY_FULL_GROUP_BY sql mode from MySQL Shell. First login to MySQL Shell using
sudo mysql
or mysql -u root -p
.View current sql_mode:
Code: Select all
select @@sql_mode;
Code: Select all
SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
Code: Select all
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
Code: Select all
SET PERSIST sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
exit;
and from terminal run:
Code: Select all
sudo service mysql restart