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

Difficulty: ★★☆☆☆

  • Rewritten using a simplified language 2022-11-12T07:02:00Z by @linux-aarhus
  • Verified on 2022-11-06T15:45:00Z by @linux-aarhus using Manjaro XFCE
  • Tutorial by @abusultanw in the old forum : Dead Link original link

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

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

Important

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

sudo pacman -Syyu

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

Systemfiles are modifed 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

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

Iniitialize 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 seervice

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

Tt 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

Save the file and restart the httpd service.

systemctl restart httpd

Test PHP

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

micro /srv/http/test.php

With content

<?php
phpinfo();

Save the file and open your web browser and navigate to http://ip.x.y.z/test.php which should then provide you with the currennt php configuraiton, 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

Edit the file /etc/php/php.ini

micro /etc/php/php.ini

Modify to include the following modules (remove the ; at the beginning of the line

[...]
extension=bz2
[...]
extension=mysqli
[...]

Save and close php.ini.

Create phpMyAdmin configuration

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

micro /etc/httpd/conf/extra/phpmyadmin.conf

With content

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 configuraton

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 file.

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

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

Generated a random string

echo $(openssl rand -hex 16)

Add the value inside the empty quotation marks

$cfg['blowfish_secret'] = ''

Add a tempdir config

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

Save the file and restart the httpd service

systemctl restart httpd

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.

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

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!

2 Likes