Install LEMP(P) Stack (Linux, Nginx, MariaDB, PHP)(phpMyAdmin) on Arch Manjaro
Install LEMP(P) stack on Arch Manjaro
This is a guide to show how to setup a LEMP(P) stack (Linux, Nginx, MariaDB, PHP)(phpMyAdmin) on Arch Manjaro. Linux as OS EngineX or Nginx is an HTTP and Reverse Proxy Server. MariaDB is an SQL database server. PHP to run php based websites with Nginx. PhpMyAdmin to manage Databases with a GUI. You can also use this guide to install a LEMP stack. Just don't install phpMyAdmin.
Update Arch Manjaro
Before doing anything, make sure Arch Manjaro is updated.
sudo pacman -Syu
Install Nginx Webserver
nginx.org recommends using the mainline version. Install nginx-mainline Install nginx-mainline using pacman
sudo pacman -S nginx-mainline
Check the status of Nginx Check the status of Nginx using systemctl
sudo systemctl status nginx
Start nginx Start nginx using systemctl
sudo systemctl start nginx
Enable nginx to start at boot Enable nginx to start at boot using systemctl
sudo systemctl enable nginx
Check if nginx is working (Replace 'localhost' with the ip or name of your server when testing from remote pc)
http://localhost
You should see the following:
Standard Nginx uses port 80
Install MariaDB Database Server
Install MariaDB Install MariaDB with pacman
sudo pacman -S mariadb
BEFORE you start MariaDB Run the following command
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Start MariaDB Start MariaDB using systemctl
sudo systemctl start mariadb
Check the status of MariaDB Check the status of MariaDB using systemctl
sudo systemctl status mariadb
Enable MariaDB to start at boot Enable MariaDB to start at boot using systemctl
sudo systemctl enable mariadb
Improve the initial security of MariaDB Run the MariaDB secure installation script
sudo mariadb-secure-installation
Secure MariaDB Answer with the following
enter current password for root (has no password): Just press Enter
Switch to Unix socket authentication [Y/n]: N
Set root password? [Y/n]: Y (not necessary, you login as root without pass then )
New password: ****
Re-Enter new 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
Login to the MariaDB console Login to the MariaDB console as root
mariadb -u root -p
Make a user for yourself in MariaDB Make a user for yourself to login to MariaDB and phpMyAdmin
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Exit the MariaDB console
exit;
Install PHP
Now we can install PHP. The latest version is php8, but some site's prefer php7. I suggest installing and configuring both, because some site's will only work with one or the other. Nginx makes it real easy to select which php version to run the site's on. Some extra info: There is php-CGI (FastCGI) and php-FPM (FastCGI Process Manager). FPM is the newer, better and faster FastCGI. I'm using FPM to handle php.
Install PHP 7
Install PHP7 + a lot of extensions Allot of website CMS's (WordPress, Yoomla etc.) still aks for php7 and need one or more extensions, so better catch 'm all.
sudo pacman -S php7 php7-{dblib,embed,enchant,fpm,gd,geoip,grpc,igbinary,imagick,imap,intl,mongodb,odbc,pgsql,phpdbg,pspell,redis,snmp,sodium,sqlite,tidy,xsl}
Edit php.ini for PHP7 Edit php.ini for PHP7 and activate the extensions. To see which extensions you have for php7: /usr/lib/php7/modules
sudo nano /etc/php7/php.ini
Search for the extension part (ctrl+w) and paste this over it I uncommented all extensions, added the missing ones and the ones we installed
extension=bcmath
extension=bz2
extension=calendar
extension=curl
extension=dba
extension=enchant
extension=exif
extension=ffi
extension=ftp
extension=gd
extension=geoip
extension=gettext
extension=gmp
extension=grpc
extension=iconv
extension=igbinary
extension=imagick
extension=imap
extension=intl
extension=ldap
extension=mongodb
extension=mysqli
extension=odbc
zend_extension=opcache
extension=pdo_dblib
extension=pdo_mysql
extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite
extension=pgsql
extension=pspell
extension=redis
extension=shmop
extension=snmp
extension=soap
extension=sockets
extension=sodium
extension=sqlite3
extension=sysvmsg
extension=sysvsem
extension=sysvshm
extension=tidy
extension=xmlrpc
extension=xsl
extension=zip
Now also adjust the next settings (ctrl+w to search)
# How much memory php can use
memory_limit = 2048M
# Upload max filesize (also the max size used for importing databases in phpMyAdmin for instance)
upload_max_filesize = 1024M
# Post max size (set 0 for unlimited)
post_max_size = 0
When starting php i got the message: PHP Warning: Module "mongodb" is already loaded in Unknown on line 0 To fix that, edit
sudo nano /etc/php7/conf.d/mongodb.ini
Now comment out the extension (because we already have it in php.ini)
;extension=mongodb.so
Start php-fpm for php7 Start php-fpm for php7 using systemctl
sudo systemctl start php-fpm7
Enable php-fpm for PHP7 to start at boot Enable php-fpm to start at boot using systemctl
sudo systemctl enable php-fpm7
Install PHP8
Install PHP8 + a lot of extensions
Some packages (like phpMyAdmin) install PHP8, so let's get that setup to.
sudo pacman -S php php-{dblib,embed,enchant,fpm,gd,geoip,grpc,igbinary,imagick,imap,intl,mongodb,odbc,pgsql,phpdbg,pspell,redis,snmp,sodium,sqlite,tidy,xsl}
Edit php.ini for PHP8 Edit php.ini for PHP8 and activate the extensions. To see which extensions you have for php8: /usr/lib/php/modules
sudo nano /etc/php/php.ini
Search for the extension part and paste this over it (halfway the file) I uncommented all extensions, added the missing ones and the ones we installed
extension=bcmath
extension=bz2
extension=calendar
extension=curl
extension=dba
extension=enchant
extension=exif
extension=ffi
extension=ftp
extension=gd
extension=geoip
extension=gettext
extension=gmp
extension=grpc
extension=iconv
extension=igbinary
extension=imagick
extension=imap
extension=intl
extension=ldap
extension=mongodb
extension=mysqli
extension=odbc
zend_extension=opcache
extension=pdo_dblib
extension=pdo_mysql
extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite
extension=pgsql
extension=pspell
extension=redis
extension=shmop
extension=snmp
extension=soap
extension=sockets
extension=sodium
extension=sqlite3
extension=sysvmsg
extension=sysvsem
extension=sysvshm
extension=tidy
extension=xsl
extension=zip
Now also adjust the next settings (ctrl+w to search)
# How much memory php can use
memory_limit = 2048M
# Upload max filesize (also the max size used for importing databases in phpMyAdmin for instance)
upload_max_filesize = 1024M
# Post max size (set 0 for unlimited)
post_max_size = 0
When starting php i got the message: PHP Warning: Module "mongodb" is already loaded in Unknown on line 0 To fix that, edit
sudo nano /etc/php/conf.d/mongodb.ini
Now comment out the extension (because we already have it in php.ini)
;extension=mongodb.so
Start php-fpm for PHP8 Start php-fpm service for PHP8 using systemctl
sudo systemctl start php-fpm
Enable php-fpm for PHP8 to start at boot Enable php-fpm for PHP8 to start at boot using systemctl
sudo systemctl enable php-fpm
Configure Nginx to run PHP
Now we need to tell Nginx to run PHP using php-fpm. ps: The standard config of nginx is a mess, hard to understand and i'm not using it like that. I will make a separate guide for Nginx. This is because Arch Manjaro installs the bare minimum. Edit nginx.conf
sudo nano /etc/nginx/nginx.conf
Uncomment user http I saw that at the start of the file the user is commented out standard on Arch !!! Remove the # infront of '#user http;'
user http;
Now search for the following part
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
Change it to the following (or just paste it under the above)
# pass the PHP scripts to FPM Unix socket running on unix:/run/php-fpm7/php-fpm.sock
# Change php-fpm7 to php-fpm for php8
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass unix:/run/php-fpm7/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Save (ctrl+o) and exit (ctrl+x) the file Test nginx.conf
sudo nginx -t
If both test are ok Reload Nginx
sudo systemctl reload nginx
Test PHP
Now we are gonna make 2 test files to see if everything is working ok. Test.php Create test.php in the Nginx Webroot.
sudo nano /usr/share/nginx/html/test.php
Paste the following lines in the file:
<?php phpinfo(); ?>
ctrl+ o to save and ctrl + x to exit. Whoami.php Create whoami.php in the Nginx Webroot.
sudo nano /usr/share/nginx/html/whoami.php
And paste in the following:
<?php echo exec('whoami'); ?>
ctrl + o to save and ctrl + x to exit. Check test.php Let's check test.php (Replace 'localhost' with the ip or name of your server when testing from remote pc)
http://localhost/test.php
If that works you should see this page
Check whoami.php Now to check which user Nginx runs as (Replace 'localhost' with the ip or name of your server when testing from remote pc)
http://localhost/whoami.php
That should show you the user Nginx is running as in the left top corner
Install phpMyAdmin
Install phpMyAdmin for easier management of databases with a GUI Source: https://wiki.archlinux.org/title/phpMyAdmin 1. Install phpmyadmin
sudo pacman -S phpmyadmin
2. Config phpMyAdmin Now we first need to make a database user for phpMyAdmin 2.1 Create a pma user and set privileges Login to mariadb
mariadb -u root -p
Run the following commands Change the default 'pma' and 'pmapass' to the user and pass you are gonna fill in to 'config.inc.php'
CREATE USER 'pma'@'%' IDENTIFIED BY 'pmapass';
GRANT ALL PRIVILEGES ON *.* TO 'pma'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;
2.2 Edit config First generate a 32 long code to use as blowfish_secret
echo $(openssl rand -hex 16)
2.2.0 Edit phpMyAdmin config Copy this command, paste it and then copy your generated code before your press enter
sudo nano /usr/share/webapps/phpMyAdmin/config.inc.php
2.2.1 Add blowfish_secret passphrase Paste in the code you generated
$cfg['blowfish_secret'] = '...';
2.2.2 Configure the database user/ password Remove the // infront of controluser and controlpass and change to the user and password you set earlier
//* User used to manipulate with storage */
// $cfg['Servers'][$i]['controlhost'] = 'my-host';
// $cfg['Servers'][$i]['controlport'] = '3306';
$cfg['Servers'][$i]['controluser'] = 'pma';
$cfg['Servers'][$i]['controlpass'] = 'pmapass';
2.2.3 Uncomment Storage database and all tables
/* Storage database and tables */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
$cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
$cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';
2.2.4 Add Template directory Copy and paste this in or else you will see a notice in phpMyAdmin.
$cfg['TempDir'] = '/var/tmp';
Example where i added it
/**
* Directories for saving/loading files from server
*/
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
$cfg['TempDir'] = '/var/tmp';
Now save "ctrl + o" and exit "ctrl + x" 2.3 Install Database Now to generate a database with all the tables
mariadb -u root -p < /usr/share/webapps/phpMyAdmin/sql/create_tables.sql
3. Add phpMyAdmin to nginx Open nginx.conf
sudo nano /etc/nginx/nginx.conf
Add a server block for phpMyAdmin phpMyAdmin will be available on port 81 in this example. Change the port to any port you would like to use. phpMyAdmin runs on PHP8.
# phpMyAdmin - Control Panel
server {
listen 81;
listen [::]:81;
server_name pma.domain.ltd;
root /usr/share/webapps/phpMyAdmin;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Run nginx test
sudo nginx -t
Reload nginx
sudo systemctl reload nginx
4. Test phpMyAdmin Now to test if it works Go to
http://localhost:81
you should be greeted with
You can now login with the user you added to MariaDB for yourself when configuring MariaDB. When logged in and still seeing config message: The phpMyAdmin configuration storage is not completely configured, some extended features have been deactivated. Click on the phpmyadmin database one time so pma set's that as the default config db. Now you have a LEMPP stack running. Thanx for reading my guide, i hope it helped