[HowTo] Install Apache, MariaDB (Mysql), PHP (LAMP)

Difficulty: ★★☆☆☆

  • NOTE: The phrase ip.x.y.z is a placeholder for the server address which can be a valid hostname or an IP address e.g. 192.168.1.10 2023-05-23T22:00:00Z by @linux-aarhus

This tutorial walk you through installing and configuring Apache, MySQL, PHP (LAMP).

LAMP is the the acronym of Linux, Apache, MySQL/MariaDB, PHP/Perl/Python.

Important


Never add packages without a full system sync - to sync your system execute

sudo pacman -Syu

The commands in this guide requires root permissions and must be prepended with sudo.

If you are confident you may find it more efficient to switch to root context

su -l root

Editing system files


System files are modified using the micro terminal editor but any terminal editor will do…

  • To save files in micro editor press Ctrl+s
  • To exit the micro editor press Ctrl+q
  • To search in micro editor press Ctrl+f

Either install micro or substitute micro for your terminal editor of choice (install xsel and/or xclip for clipboard functionality - requires xorg - wayland has wl-clipboard)

pacman -S micro

Install Apache


Install Apache web server using command

pacman -S apache

Edit the /etc/httpd/conf/httpd.conf file,

micro /etc/httpd/conf/httpd.conf

Search for and comment the following line if it is not already

[...]
# LoadModule unique_id_module modules/mod_unique_id.so
[...]

Search for ServerAdmin and replace with a valid email (best practice - not necessary in test environments)

[...]
ServerAdmin you@example.com
[...]

Next edit the ServerName variable to something meaningful - at the bare minimum use your server’s IP address

[...]
ServerName ip.x.y.z:80
[...]

Save and close the file then enable and start the web service

systemctl enable --now httpd

Verify the status of the service

# systemctl status httpd
● httpd.service - Apache Web Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: disabled)
     Active: active (running) since Fri 2022-11-11 13:03:33 CET; 4s ago
[...]
Nov 11 13:03:33 test systemd[1]: Started Apache Web Server.

Test web service

Test the webservice by creating a sample page in the default web root in /srv/http

micro /srv/http/index.html

Add text - no need for our test to be strictly html compliant

<h2>It works!</h2>

Now, open your web browser and navigate to

http://ip.x.y.z

You should be greeted with the It works message.

Install MariaDB


MariaDB is the default implementation of MySQL in Manjaro. To install MariaDB execute

pacman -S mariadb

Initialize the MariaDB data directory prior to starting the service, by using the installer script (do not change --datadir)

mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

When the script has completed enable and start the service

systemctl enable --now mariadb

You can verify the MariaDB service status (shortened)

# systemctl status mariadb
● mariadb.service - MariaDB 10.9.3 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: disabled)
     Active: active (running) since Fri 2022-11-11 13:09:51 CET; 10s ago
[...]
Nov 11 13:09:51 test systemd[1]: Started MariaDB 10.9.3 database server.

Secure your MariaDB service

It is recommended to secure your database installation using the provided script. Read the prompts carefully - the root password is not your system password but for MariaDB.

mariadb-secure-installation

Install PHP


Manjaro uses the - at any time - latest php version. To install PHP and the apache PHP module

pacman -S php php-apache

Proceed to configure Apache PHP module by editing the file /etc/httpd/conf/httpd.conf

micro /etc/httpd/conf/httpd.conf

Search and locate the following and edit to read as below

[...]
#LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
[...]

Scroll to the bottom of the file and add for current PHP

LoadModule php_module modules/libphp.so
AddHandler php-script .php
Include conf/extra/php_module.conf

Check your config

apachectl configtest

Save the file and restart the httpd service.

apachectl restart

Test PHP

Create a file info.php file in the web service root folder

micro /srv/http/info.php

With content

<?php phpinfo(); ?>

Save the file and open your web browser and navigate to http://ip.x.y.z/info.php which should then provide you with the current php configuration, enabled modules etc.

Install phpMyAdmin


phpMyAdmin is a graphical MySQL/MariaDB administration tool that can be used to create, edit and delete databases. To install phpMyAdmin

pacman -S phpmyadmin

Create/Edit the file /etc/php/conf.d/phpmariadb.ini

micro /etc/php/conf.d/phpmariadb.ini
extension=bz2
extension=iconv
extension=mysqli
extension=pdo_mysql

Save and close the file. Verify your ini-file is loaded

php --ini

Create Apache configuration

Then create a new Apache configuration to be able to load phpMyAdmin

micro /etc/httpd/conf/extra/phpmyadmin.conf
Alias /phpmyadmin "/usr/share/webapps/phpMyAdmin"
<Directory "/usr/share/webapps/phpMyAdmin">
    DirectoryIndex index.php
    AllowOverride All
    Options FollowSymlinks
    Require all granted
</Directory>

Edit the Apache configuration

micro /etc/httpd/conf/httpd.conf

Include phpMyAdmin configuration at the very end of the file

[...]
Include conf/extra/phpmyadmin.conf

Save and close the httpd.conf - then test your config

apachectl configtest

Restart apache

apachectl restart

phpMyadmin config


Option 1

Edit the phpMyAdmin /etc/webapps/phpmyadmin/config.inc.php and add a value for blowfish_secret

micro /etc/webapps/phpmyadmin/config.inc.php 

Generate a random number in hex format

openssl rand -hex 16

Add the value inside the empty quotation marks

$cfg['blowfish_secret'] = 'your-generated-value';

Add temp folder

$cfg['TempDir'] = '/tmp';

Save the file

Option 2

Use terminal tools to add the mentioned configuration values.

sed -i -e "/blowfish/s/''/'$(openssl rand -hex 16)'/gi" /etc/webapps/phpmyadmin/config.inc.php
echo "\$cfg['TempDir'] = '/tmp';" >> /etc/webapps/phpmyadmin/config.inc.php

Test phpMyAdmin

Open your browser and navigate to

http://ip.x.y.z/phpmyadmin

Using Nginx


If you want to use Nginx instead of Apache web server, refer the following article.

Sources: http://www.ostechnix.com/install-apache-mariadb-php-lamp-stack-on-arch-linux-2016/

Revision

  • 2024-04-12T22:00:00Z Fix various spelling errors by @cscs
  • 2023-01-04T23:00:00Z Added sed command to inject blowfish_secret into config.inc.php by @linux-aarhus
  • 2022-12-28T23:00:00Z Fix missing semicolon in config.inc.php by @linux-aarhus
  • 2022-11-12T07:02:00Z Rewritten using a simplified language by @linux-aarhus
  • 2022-11-06T15:45:00Z Verified by @linux-aarhus using Manjaro XFCE
  • Tutorial by @abusultanw in the old forum : Dead Link original link
32 Likes

it has been of great help, Thanks a lot!

1 Like

1. Ini adalah forum berbahasa Inggris
2. Silakan buka topik Anda sendiri untuk masalah baru ini

  1. This is an English speaking forum
  2. Please open your own topic for this new problem as you’re posting this in a tutorial section which is meant to post feedback to the tutorial itself, not to post issues.

Thank you for your cooperation.

:+1:

1 Like

Hy, here I have a problem. And when I go localhost / phpmyadmin. Then the output could be where Access is forbidden, error 403.
Please give me a solution

1 Like

Please open a new topic in the correct category by:

  • going here: https://forum.manjaro.org
  • choosing the #support category
  • choosing the category that matches best what your issue it.
  • If you can’t find any category, click #support:general
  • Click the New topic button in the top right corner.
  • Describe your issue there.

Gud bro…

1 Like

Worked for me.

Thanks!

1 Like

Thank a TON for this! Got me off the ground quickly and easily as a New Jack.

1 Like

If your httpd didn’t start after last update (~09.02.2021), just modify httpd.conf:

LoadModule php_module modules/libphp.so
AddHandler php-script php
Include conf/extra/php_module.conf

Note, there is no php version in these lines

how to uncomment in php.ini

Just remove semicolon ; from line begining :wink:

thanks

I did eveything as it is in the above how to guide but i get this end result

The ‘ip-address/phpmyadmin’ is just an example, you have to put the ip address of your computer or you can try as follows:

  • ‘localhost/phpmyadmin’
1 Like

This guide is slightly outdated, we have already PHP8 so these lines should look like:

LoadModule php_module modules/libphp.so
AddHandler php-script php
Include conf/extra/php_module.conf
1 Like

thanks, fixed

you solve it? i got this error too

Hi @dstyle ,

First of all thanks for the tutorial.
Is there any tutorial how to use two php version like 7.4 and 8 together with virtual hosting and defining in the virtual host info which php version to use?

I did search in the net and didn’t find any good one.

Tried to follow this one with no luck. link arch wiki

If there is any tutorial please share.
Thanks

anyone on how to correctly setup a symbolic link for web development ? I keep messing up the /srv/http directory…

I’m looking to create a symlink between a folder in my home folder and the http folder so that i can modify files with out sudo but can see the output in localhost.

Anyone ?

I use:

sudo chown MYUSERNAME:http -R /srv/http/

sudo find /srv/http/ -type d -exec chmod 755 {} +
sudo find /srv/http/ -type f -exec chmod 644 {} +

Replace MYUSERNAME with appropriate!

3 Likes