Linux Tutorials

Install LAMP On Manjaro

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

Important information

By default, the server will serve files in the browser located at ‘/srv/http’. You can change it from the server configuration file or leave it as it is for ease of use. For more information, check out the Apache newcomers guide.

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.

[[email protected] 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.

[[email protected] 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 –

[[email protected] 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
[[email protected] 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.



11 comments

Stephen November 19, 2020 at 11:20 am

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.

Reply
Pablo December 30, 2020 at 7:04 am

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.

Reply
Sohail May 3, 2021 at 1:49 pm

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.

Reply
dieter November 29, 2020 at 3:12 pm

You create a file calles phpinfo, yet you link to a file called phptest

Reply
Sohail May 3, 2021 at 1:51 pm

Fixed. Thanks for pointing it out.

Reply
Mustafa Hakan Borazan February 12, 2021 at 3:36 am

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

Reply
Josue Carrasco February 15, 2021 at 8:41 am

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.

Reply
John May 2, 2021 at 10:36 pm

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??

Reply
Kushank June 12, 2021 at 4:34 am

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…

Reply
franco July 6, 2021 at 7:33 pm

Yes, you remove to them.

Reply
Genesis September 10, 2021 at 8:16 pm

I would recommend you uncomment these three (3) lines
;extension=bz2
;extension=mysqli
;extension=iconv

To the below if you are using php8

extension=bz2
extension=mysqli
extension=iconv

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.