Install LAMP On Manjaro

LAMP stands for Linux, Apache, MySQL/MariaDB, and PHP or Perl or Python. If you are using Manjaro, you can easily install LAMP on Manjaro.

Manjaro is one of the cleanest Linux distributions available. If you are using Manjaro for web development, you can easily install LAMP on Manjaro Linux. All the required packages are already available in the default repositories.

Install LAMP On Manjaro

Before installing any package, update the system using pacman.

sudo pacman -Syu

The above command will ask for the sudo password, enter the password, and it’ll check for any available updates.

Install Apache

Next, install Apache. Apache is the most popular web server, and its extensive documentation helps new users configure it easily. Currently, Apache’s latest stable version is v2.4.46, which is available in the Manjaro repository.

One can either fire up the GUI software installer and search for ‘apache’ to install it or use the CLI package manager ‘pacman’ command.

Install Apache on Manjaro GUI
Install Apache on Manjaro GUI

Or use the CLI to install Apache –

sudo pacman -S apache
Install Apache on Manjaro CLI
Install Apache on Manjaro CLI

It’s just a small package and will be installed in a few seconds. Once the installation has been completed, open the Apache configuration file that exists on /etc/httpd/conf/httpd.conf and comment out the following line –

# LoadModule unique_id_module modules/mod_unique_id.so
GUI text editor - mousepad
sudo mousepad /etc/httpd/conf/httpd.conf

CLI text editor - nano
sudo nano /etc/httpd/conf/httpd.conf
Edit Apache configuration
Edit Apache configuration

Please save the file, and that is it. We can now enable and start the apache server by using the following command –

sudo systemctl enable httpd
sudo systemctl restart httpd

Once done, confirm it by checking service status or by visiting the http://localhost in the browser. If it shows the following page, it means the server is up and running completely fine.

sudo systemctl status httpd
Apache server
Apache server

Install MySQL

MariaDB is the default implementation of MySQL in Arch Linux. To install MariaDB, use the following command –

sudo pacman -S mysql

The installation will prompt you to choose the provider for MySQL. Hit enter to choose the default repository, i.e., MariaDB.

[sandy@Manjaro http]$ sudo pacman -S mysql
:: There are 2 providers available for mysql:
:: Repository extra
   1) mariadb
:: Repository community
   2) percona-server

Enter a number (default=1): 

Next, press enter to confirm the installation.

[sandy@Manjaro http]$ sudo pacman -S mysql
:: There are 2 providers available for mysql:
:: Repository extra
   1) mariadb
:: Repository community
   2) percona-server

Enter a number (default=1): 
resolving dependencies...
looking for conflicting packages...

Packages (1) mariadb-10.5.5-2

Total Installed Size:  234.53 MiB

:: Proceed with installation? [Y/n] 

The installation may take 10 to 20 seconds, depending on your internet speed. Once completed, begin by initializing the MariaDB data directory using the following command –

sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

And that is it. MariaDB is installed on Manjaro. Let’s enable and start it by using the following commands –

sudo systemctl enable mysqld
sudo systemctl restart mysqld

Confirm the installation by checking the service status –

sudo systemctl status mysqld

Desired output –

[sandy@Manjaro http]$ sudo systemctl status mysqld
● mariadb.service - MariaDB 10.5.5 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
     Active: active (running) since Sun 2020-10-04 12:51:42 IST; 1min 2s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 13481 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 13482 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galer>
    Process: 13508 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
   Main PID: 13491 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 9 (limit: 9446)
     Memory: 78.3M
     CGroup: /system.slice/mariadb.service
             └─13491 /usr/bin/mariadbd

Oct 04 12:51:42 Manjaro mariadbd[13491]: 2020-10-04 12:51:42 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
Oct 04 12:51:42 Manjaro mariadbd[13491]: 2020-10-04 12:51:42 0 [Note] InnoDB: 10.5.5 started; log sequence number 4062669; tr>
Oct 04 12:51:42 Manjaro mariadbd[13491]: 2020-10-04 12:51:42 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_b>
Oct 04 12:51:42 Manjaro mariadbd[13491]: 2020-10-04 12:51:42 0 [Note] Server socket created on IP: '::'.
Oct 04 12:51:42 Manjaro mariadbd[13491]: 2020-10-04 12:51:42 0 [Note] InnoDB: Buffer pool(s) load completed at 201004 12:51:42
Oct 04 12:51:42 Manjaro mariadbd[13491]: 2020-10-04 12:51:42 0 [Note] Reading of all Master_info entries succeeded
Oct 04 12:51:42 Manjaro mariadbd[13491]: 2020-10-04 12:51:42 0 [Note] Added new Master_info '' to hash table
Oct 04 12:51:42 Manjaro mariadbd[13491]: 2020-10-04 12:51:42 0 [Note] /usr/bin/mariadbd: ready for connections.
Oct 04 12:51:42 Manjaro mariadbd[13491]: Version: '10.5.5-MariaDB'  socket: '/run/mysqld/mysqld.sock'  port: 3306  Arch Linux
Oct 04 12:51:42 Manjaro systemd[1]: Started MariaDB 10.5.5 database server.
lines 1-25/25 (END)

The final step toward completing MySQL setup, run mysql_secure_installation to set up the root password and remove the test database for security.

sudo mysql_secure_installation
[sandy@Manjaro http]$ sudo mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] Y
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

That’s it. You can now login to MySQL root user and create or manage databases from MySQL command-line interface.

mysql -u root -p

In another tutorial, I will show you how to create MySQL user, grant privileges, and create databases in MySQL.

Install PHP

The last part of LAMP is PHP. PHP 7 is already available in the Manjaro repository. To install PHP and PHP Apache module in Manjaro, use pacman command –

sudo pacman -S php php-apache

Set up PHP Apache module by updating a few entries in the apache configuration file that exists at /etc/httpd/conf/httpd.conf.

sudo mousepad /etc/httpd/conf/httpd.conf

Or

sudo nano /etc/httpd/conf/httpd.conf

Find and comment out the following line in the configuration –

#LoadModule mpm_event_module modules/mod_mpm_event.so

Find and uncomment the following line in the configuration –

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

And at the end of the file, add the following lines –

LoadModule php7_module modules/libphp7.so
AddHandler php7-script php
Include conf/extra/php7_module.conf

Now save the file and exit. Restart the apache server to make sure all the configurations are loaded properly.

sudo systemctl restart httpd

That’s all. PHP is now installed and configured to be used with the Apache webserver.

To test the PHP installation, create a file at /srv/http/phptest.php and write the following PHP code –

<?php
phpinfo();
?>

Now open this file in the browser by visiting the localhost/phptest.php.

PHP information
PHP information

With the above set of tools, you should be able to develop and test your web application without any issues. If you want a little more ease in handling databases, we can do that by installing phpMyAdmin. It is a browser-based database management system.

It is straightforward to use and can be installed on Manjaro in no time.

Install phpMyAdmin

phpMyAdmin is easy to use the graphical interface to create, delete, and update databases.

sudo pacman -S phpmyadmin

phpMyAdmin requires PHP mysqli and PHP bz2 extensions enabled. Edit the php.ini and uncomment the following lines to enable the extensions –

extension=bz2
extension=mysqli

Now save and close the file.

In other Linux distributions, phpMyAdmin by default works on http://localhost/phpmyadmin but in Manjaro, we will have to manually configure the apache server to serve phpMyAdmin on this address.

Create an apache configuration file for phpMyAdmin.

sudo mousepad /etc/httpd/conf/extra/phpmyadmin.conf

And paste the following configurations in the file –

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

The Alias refers to the web address where it will serve phpMyAdmin, and the Directory is the location of phpMyAdmin. Please save the file and close it.

Now we’ll need to add the above configuration file in the main Apache configuration to enable it. Open the apache configuration and include the address of the phpMyAdmin configuration.

sudo mousepad /etc/httpd/conf/httpd.conf

Paste the following line at the end of the file.

Include conf/extra/phpmyadmin.conf

Once done, restart the apache server –

sudo systemctl restart httpd

That is all! Now visit http://localhost/phpmyadmin and login to the database using the credentials you created above.

Summary

To summarize, in this article, we successfully installed LAMP in Manjaro and set up phpMyAdmin to easily manage databases on our system. Alternatively, one can also use DBeaver to manage databases graphically. DBeaver is a free and open-source tool for managing MySQL and other popular database systems such as Microsoft SQL, Oracle, SQL lite, PostgreSQL, and many more.

If you face any trouble with this article, let me know in the comment section below.

SHARE THIS POST

MassiveGRID Banner
14 Comments Text
  • Thanks, good article.

    I think you mean to say “uncomment” for the lines

    extension=bz2
    extension=mysqli

    as they should be uncommented to enable them. They are commented out by default.

    Also, MySQL no longer allows the root user to have no password. I set up as you described, giving no password, and am now locked out of MySQL. Have yet to figure out what to do to get around this, short of starting over.

    That being said, this was a very helpful article for me as I migrate my dev work from Windows to Manjaro – Thank you.

    • Hi Stephen,

      I am glad this article helped you. Yes I did mean to say uncomment the two lines. I have fixed that.

      Regarding locking out of your MySQL, you can use `sudo mysql’ to log in to MySQL root.

    • Hi, did you manage to solve the password issue? I had the same problem, just ran te “sudo mysql_secure_installation” command again and in the option to change root password selected “y” and entered a new one. It is working fine after that.

  • Instead of following codes:
    LoadModule php7_module modules/libphp7.so
    AddHandler php7-script php
    Include conf/extra/php7_module.conf

    Use following codes for php8:
    LoadModule php_module modules/libphp.so
    AddHandler php-script php
    Include conf/extra/php_module.conf

  • Hi, im using manjaro 20.2.1, and now if you install php it give you php 8, not 7, so you have to change this part:
    LoadModule php7_module modules/libphp7.so
    AddHandler php7-script php
    Include conf/extra/php7_module.conf

    Now you have to use:
    LoadModule php_module modules/libphp.so
    AddHandler php-script php
    Include conf/extra/php_module.conf

    That work for me.

  • I had trouble with the final thing:
    (Using FireFox) localhost/phpmyadmin
    Simply gave me the “Unable to connect” page.
    I tried spelling and caps variations and still no go.
    Any ideas??

    • Did you figure this error out.looks like i have encountered the same problem as you. please share the solution if you have

  • Hello, Could you please help me.
    I got this message

    Composer detected issues in your platform: Your Composer dependencies require the following PHP extensions to be installed: iconv

    at the end when I entered http://localhost/phpmyadmin

    I’m just starting to learn linux so I think it’s hard to understand certain things.

    I’m confused about this particular line. When you said, “uncomment the following lines to enable the extensions”

    extension=bz2
    extension=mysqli

    Originally it was this,
    ;extension=bz2
    ;extension=mysqli

    To uncomment this, am I supposed to remove the semi colons?
    I’m just starting to learn these so I get confused fairly easy. Sorry if this is a dumb question…

  • I just wished the article mentioned how to change things so that Apache will load websites from a user’s directory and NOT have to make changes to the user’s website using sudo/root. I’ve no interest in being in root just to change a web page.

  • After many hours, and with a lot of patience, I have been able to follow this tutorial step by step with very good results, but I would like to have a graphical interface to manage this mounted server, likewise, I would like to install several versions of php to load different CMS or different codes compatible with different versions of php, and to be able to change more easily between one version and another.

    In short, this effort and this tutorial are greatly appreciated. It needs to be updated or clarified that now it downloads php 8 and not 7 and the version is not mentioned in the configuration lines, at least that’s how it worked for me.

    thank you a thousand

  • Leave a Reply

    Your email address will not be published. Required fields are marked *