How install and configure Apache,MariaDB,PHP on Arch Linux. ( Antergos OS )

How install and configure Apache,MariaDB,PHP on Arch Linux. ( Antergos OS )

Today I am going to tell you how install LAMP ( Apache,MariaDB , PHP on Linux ) and configure it.

LAMP stack is set of open source software to up and run web application. Small description about these software will given in each chapter.

To install these software on Arch Linux you can use pacman manager ( graphical tool or terminal ). If you use pacman-manager graphical tool search each software and it will show you latest version available on repository. If you use terminal use this code to update repository first.

 sudo pacman -Syu

Install Apache

Web server is the software which receive the request to web page and take to the web page. Apache is the most widely used web server software which developed and maintain by Apache Software Foundation. Apache is an open-source software available for free.

Now you have up to date pacman repository and can install Apache.

sudo pacman -S apache

After that edit /etc/httpd/conf/httpd.conf file. To open that file on nano,

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

Then comment out the module mention below,

#LoadModule unique_id_module modules/mod_unique_id.so

[ In nano text editor use Ctrl + w search text and remove ‘#’ to comment out a line ]
Then save ( Ctrl + O ) and close ( Ctrl + x ) the file.

Now we can restart Apache server using this command.

sudo systemctl restart httpd

If you get error like ,

httpd: apr_sockaddr_info_get() failed for ####

httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName

you can add your hostname (To find your hostname just type ‘hostname’ and execute on terminal)  to host file and fix this issue. To do that open host file using nano and add your hostname at the end of line begin with 127.0.0.1 (localhost IP).

 sudo nano /etc/hosts 

Add hostname on this line,

127.0.0.1       localhost.localdomain       localhost #####(you hostname)

example: 127.0.0.1       localhost.localdomain      localhost Emalsha-PC

Now you can restart web server using given command. To check whether httpd service run correctly use this command to get service status.

sudo systemctl status httpd

It will give you this kind of result,

screenshot_20170218_084321

Now you can try Apache web server by creating simple html page on /srv/http/ directory.

sudo nano /srv/http/index.html

Then put this html on it,


<html>

<title>Welcome Apache Web Server</title>

<body>
<h1>This is testing file to Apache web server.</h1>
</body>

</html>

Save and close the file and browse localhost ( or given IP ex:127.0.0.1 ) on your browser.If you got this result you successfully installed Apache web server software.

screenshot_20170218_113221

Install MariaDB

MariaDB Server is one of the most popular database servers in the world. It’s made by the original developers of MySQL and guaranteed to stay open source. It is an enhanced, drop-in replacement for MySQL. MariaDB is used because it is fast, scalable and robust, with a rich ecosystem of storage engines, plugins and many other tools make it very versatile for a wide variety of use cases.

Already you have updated your pacman repository and now we can install latest version.

sudo pacman -S mysql

Since 2013 MariaDB is the official default implementation of MySQL in Arch Linux. Therefore when you going to install mysql it will ask whether install MariaDB or Percona server. Use default selection MariaDB and continue installation.

Start MariaDB using this command

sudo systemctl start mysqld

You can check is it running by using this command

sudo systemctl status mysqld

It gives you this kind of result.

screenshot_20170218_212753

Now you have to set up root password and other security settings. To do this use this command.

mysql_secure_installation

It will proceed you to some questions and first will ask root password. But very first you haven’t set any password therefore keep it blank and enter. Then it will ask your new password and continue process. It’s better to follow default options it suggested.

If you got error like
error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’
                Check that mysqld is running and that the socket: ‘/var/run/mysqld/mysqld.sock’ exists!

Then try this command.

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

 

Now MariaDB is ready to use.

Remember :

You want this service run each time therefore you can enable load this service at startup by using this command.

sudo systemctl enable mysqld httpd

If you want these services start use this ,

sudo systemctl start ##### ← service name

if you want to restart

sudo systemctl restart #####

if you want to get current status

sudo systemctl status #####

Install PHP

PHP is a server-side scripting language designed primarily for web development but also used as a general-purpose programming language. Current stable php version is 7.1.2 ( when I write this blog – 18/02/2017) and install using this command.

sudo pacman -S php php-apache

Then edit Apache configuration file

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

First find this line and comment it.

LoadModule mpm_event_module modules/mod_mpm_event.so
( put ‘#’ at the beginning)

Then put this lines at the end of the config file.

 LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
 LoadModule php7_module modules/libphp7.so
 AddHandler php7-script php
 Include conf/extra/php7_module.conf
 save and close the file.

Now you can check whether php installed correctly or not by creating simple php file on apache host folder.

nano /srv/http/info.php

and put this lines on it.

<?php     phpinfo(); ?>

You have altered httpd.conf file therefor restart the httpd server to take this updates.

sudo systemctl restart httpd

Now you can browse http://localhost/info.php on your browser and you get result like this.

Screenshot_20170218_234446.png

Wow … You have installed php correctly.

Congratulations ! Now you have LAMP stack and start the building yourself.

9 thoughts on “How install and configure Apache,MariaDB,PHP on Arch Linux. ( Antergos OS )

  1. Now you can try Apache web server by creating simple html page on /srv/http/ directory.
    1
    sudo nano /srv/http/index.html

    Then put this html on it,

    Welcome Apache Web Server

    This is testing file to Apache web server.

    Save and close the file and browse localhost ( or given IP ex:127.0.0.1 ) on your browser.If you got this result you successfully installed Apache web server software.

    WE don’t have right on srv/html … how can we fixe that please

    Like

  2. Hi Dag,

    Yes you may don’t have permission to create new file on that folder.
    So, first identify you current user by opening new terminal and give command “users”,
    Then it will show you current users. Then you can change ownership and give permission to that user to work on /srv/http/.. folder

    To change ownership use, ”chown YOUR_USER:YOUR_USER_GROUP /srv/http”
    To change permission use, “chmod +655 /srv/http”

    Like

  3. After installing MariaDB if you encounter errors starting the server the solution is in the Arch wiki…

    # mysql_install_db –user=mysql –basedir=/usr –datadir=/var/lib/mysql

    This has to be done before starting MariaDB in order to set it up properly.

    Liked by 1 person

  4. Thank you Emalsha! I spent an entire day trying to set up my LAMP stack on Manjaro before I came across your blog. Unlike many other internet tutorials, you broke the subject down in a clear and readable manner! Not only did it solve my issues, it helped me to understand the configuration of LAMP software so that in the future I will be able to more easily solve other problems. Cheers!

    Liked by 1 person

Leave a reply to stewieandro Cancel reply