Tutorial

How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Arch Linux

Published on September 8, 2012
How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Arch Linux

About LAMP

The LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Arch Linux uses the powerful Pacman installer which can download all of the most recent, required packages for each program with one command.

Set Up

The steps in this tutorial require the user to have root privileges. You can see how to set that up here in steps 3 and 4.

Step One—Install Apache

Apache is a free open source software that runs over 50% of the world’s web servers.

Before installing any of the LAMP programs, we should update the package manager:

sudo pacman -Syu

Once the update is complete, we can install Apache:

sudo pacman -S apache

After Apache is installed, we need to make a couple of changes in the configuration.

Open up the apache configuration file:

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

Comment out the unique_id_module (you can use ctrl w to find it quickly):

#LoadModule unique_id_module modules/mod_unique_id.so

Restart Apache:

sudo systemctl restart httpd

During the apache restart, you may get a notice that says the following:

httpd: apr_sockaddr_info_get() failed for droplet1
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
                                                                         [DONE]

Although this alert does not interfere with the apache launch, you can easily eliminate it if you like by adding your hostname to your configuration.

Open up the hosts file:

sudo nano /etc/hosts

Add your hostname to the end of the line beginning with 127.0.0.1:

127.0.0.1       localhost.localdomain   localhost droplet1

Subsequent restarts of Apache will no longer display that message. With that, Apache is now installed on your server. Directing your browser to your server’s IP address (http://12.34.56.789) will display an auto-index directory. You can quickly try out a sample page by adding an index.html file to Arch’s document root directory, located within “srv/http”:

sudo nano /srv/http/index.html
<html>
<title>Welcome</title>
<body>
<h2>Hello, Welcome to Arch</h2>
</body>
</html>

You can visit the placeholder page by going to your server’s IP address in your browser.

How to Find your Server’s IP address

You can run the following command to reveal your server’s IP address.

curl -s icanhazip.com

Step Two—Install MySQL

MySQL is a powerful database management system used for organizing and retrieving data.

Since March 2013, MariaDB has become the default implementation of MySQL in Arch repositories. Installing the package "mysql" will automatically drop in MariaDB as a replacement. See the original announcement for more details.

To install MySQL, open terminal and type in these commands:

sudo pacman -S mysql

Hit enter if it asks you anything, unless you know you don't want the defaults.

Once you have installed MySQL, start it running

sudo systemctl start mysqld

Finish up by running the MySQL set up script:

sudo mysql_secure_installation

The process will ask you for your current MySQL root password (not to be confused with your server password) and, since it has not yet been set, simply press enter.

When prompted, “Set root password?” type Y, and afterwards enter in your new MySQL root password.

After that it’s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the new changes.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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, MySQL 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...

Once you're done installing MySQL, finish the LAMP stack by installing PHP.

Step Three—Install PHP

PHP is an open source web scripting language that is widely used to build dynamic webpages.

To install PHP, open terminal and type in this command.

sudo pacman -S php php-apache

PHP should also be added to the apache configuration file:

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

Paste in this text block within the config.

# Use for PHP 5.x:
LoadModule php5_module       modules/libphp5.so
AddHandler php5-script php
Include conf/extra/php5_module.conf

Step Four—See your PHP Config and Add Programs to Startup

After LAMP is completely installed, we can take a look and see the PHP details by creating a quick php info page

To set this up, first create a new blank file:

sudo nano /srv/http/info.php

Add in the following line:

<?php
phpinfo();
?>

Then Save and Exit.

Restart apache so that all of the changes take effect:

sudo systemctl restart httpd

Visit your php info page (make sure you replace the example ip address with your correct one): http://12.34.56.789/info.php

Your screen should then look like this:

PHP info

To close out the LAMP installation, open up the configuration file of Arch’s innitscripts and add the apache server and MySQL daemons to the list of programs that run upon server startup:

sudo systemctl enable mysqld httpd

Congratulations, you have now installed the LAMP server on Arch Linux!

See More

Once LAMP is installed, you have a great base on which to build your site. Check out this tutorial to see how to install Wordpress on Arch

By Etel Sverdlov

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the author(s)

Etel Sverdlov
Etel Sverdlov
See author profile
Category:
Tutorial

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
38 Comments
Leave a comment...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

I was able to set up a LAMP on Arch Linux. Now I’m trying to install wordpress on it using SSH, but it keeps on failing. Is there a way to access my new LAMP server using a FTP client? Can you help me out here what steps to take?

This comment has been deleted

    Moisey Uretsky
    DigitalOcean Employee
    DigitalOcean Employee badge
    September 14, 2012

    Hi,

    You would need to install an FTP server in order to be able to access your server via an FTP account.

    However, you should be able to install Wordpress using SSH and we have some articles that can help you with that: https://www.digitalocean.com/community/articles/how-to-install-wordpress-on-centos-6--2

    This is for CentOS but the majority of things should be very similar.

    If you are running into a particular problem paste us your error messages and we’ll help you troubleshoot it.

    This comment has been deleted

      Arch Linux has moved to use systemd instead of init so rc.d method for starting MySQL daemon will not work when pacman -Syu has been used right after a new droplet has been set up.

      This comment has been deleted

        So the solution goes like this:

        • pacman -Sy to update the repository database

        • replace pacman

        • pacman -S mysql

        • pacman -S glibc (needs to be renewed or the MySQL daemon won’t start)

        • making the folder needed for MySQL logs: mkdir /var/log/mysql chown mysql:mysql /var/log/mysql chmod 750 /var/log/mysql

        • editing /etc/mysql/my.cnf

        [mysqld_safe] log-error=/var/log/mysql/error.log

        [mysqld] log-error=/var/log/mysql/error.log

        • sudo /usr/bin/mysqld_safe &
        • sudo mysql_secure_installation
        • kill the mysqld_safe
        • get the daemon handling script for /etc/rc.d/mysqld from a previous installation or from another server

        when I do sudo pacman -Syu, it says sudo: pacman: command not found

        This comment has been deleted

          This guide is a bit out-dated, systemd has replaced sysvinit/initscripts. Daemons do not go in rc.conf anymore, but are handled by systemd. See https://wiki.archlinux.org/index.php/Systemd

          This comment has been deleted

            As of 2013-03-25 mysql is no longer an offical package for Arch, see https://www.archlinux.org/news/mariadb-replaces-mysql-in-repositories/ for the announcement.

            This comment has been deleted

              You must update the command “sudo pacman -S mysql” to “sudo pacman -S mariadb” because Arch Linux didn’t use MySQL from time ago.

              This comment has been deleted

                Kamal Nasser
                DigitalOcean Employee
                DigitalOcean Employee badge
                July 10, 2013

                We have updated the article re: mariadb.

                This comment has been deleted

                  I am not able to locate the ip address of my virtualbox.ifconfig|grep inet is giving 10.0.2.15 after installing apache I would like to see index page from my windows7 explorer. How I would do this

                  Kamal Nasser
                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  August 15, 2013

                  @ynomani: Your virtualbox’s IP address is 10.0.2.15, you can browse to http://10.0.2.15 if you want to access Apache on the VM.

                  When I put the first command it reports: “sudo: pacman: command not found”, I tried to install pacman (sudo apt-get install pacman), but it states: pacman is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. I have created the new user, and I am trying to do this from the connection with this new user. Suggestions?

                  Kamal Nasser
                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  August 18, 2013

                  @aramis001: What OS are you using?

                  Thank you for such a wonderful post it rely helped me a lot

                  Please how to i run multiple hosts in this apache server?

                  So I can use pacman to get everything. My problem is after I edit httpd.conf and start apache for the first time i get an error message:

                  Job for httpd.service failed. See ‘systemctl status httpd.service’ and ‘journalctl -xn’ for details.

                  I try httpd -t to learn: httpd: Syntax error on line 65 of /etc/httpd/conf/httpd.conf: Cannot load /etc/httpd/modules/mod_authnz_ldap.so into server: libldap-2.4.so.2: cannot open shared object file: No such file or directory

                  Any help appreciated.

                  Kamal Nasser
                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  September 7, 2013

                  @j_morange: Did you install apache2-ldap?

                  sudo pacman -S apache2-ldap error: target not found: apache2-ldap

                  Sounds like it’s about to get complicated?

                  Fixed - could not find any instructions on this. Ended up adding some more # inside httpd.conf:

                  line 65: #LoadModule authnz_ldap_module modules/mod_authnz_ldap.so line 81: #LoadModule ldap_module modules/mod_ldap.so

                  After a sudo systemctl restart httpd it seemed to work and I was able to browse to my new webpage at localhost.

                  So new question, I’ve not pretty much finished the install process. However the tutorial is a little incomplete I think, when I got to my localhost, it pops up an index and I actually have to click the info.php file to get it to show the correct page. How can I direct this to run straight away or set it up to put php in html (have allowed .htaccess in httpd.conf and made a .htaccess file with the line ‘AddType application/x-httpd-php .html’, but nothing is working so far).

                  Thanks very much!

                  Kamal Nasser
                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  September 8, 2013

                  @j_morange: I’m not sure what you mean, can you please explain this part?

                  <pre>when I got to my localhost, it pops up an index and I actually have to click the info.php file to get it to show the correct page.</pre>

                  There is a database manager like phpmyadmin for mariadb?

                  Kamal Nasser
                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  November 17, 2013

                  @me: MariDB is a drop-in MySQL replacement which means that phpMyAdmin will work fine with MariaDB.

                  For some reason when I tried to access the local host using the sever’s ip (which I got by ‘curl -s icanhazip.com’), the page intitally took too long to load, and then eventually “the server was not found”. Using ‘localhost’ in my browser instead of the ip, worked though. I am just mentioning it, in case someone else has a similar issue

                  I got Wordpress installed, & I can access the Admin Panel, but when I try to to see the front end, all I get is a page that says “Welcome to Arch”

                  Not sure how I posted that twice, but sorry. Anyway, I know what is happening, but I dont know how to fix it. Obviously it is directing to the place holder page we created in the tutorial. So how do I make it direct to the correct page? I

                  Kamal Nasser
                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  December 29, 2013

                  @wolf: Try clearing your browser’s cache—does that fix it?

                  why my apache wont running after added line?

                  LoadModule php5_module modules/libphp5.so AddHandler php5-script php Include conf/extra/php5_module.conf

                  here error messages :

                  [luckymeerza@hostname ~]$ sudo systemctl restart httpd Job for httpd.service failed. See ‘systemctl status httpd.service’ and ‘journalctl -xn’ for details. [luckymeerza@hostname ~]$ sudo systemctl status httpd ● httpd.service - Apache Web Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled) Active: failed (Result: exit-code) since Thu 2014-08-14 22:48:17 WIB; 7s ago Process: 4009 ExecStop=/usr/bin/apachectl graceful-stop (code=exited, status=1/FAILURE) Process: 4098 ExecStart=/usr/bin/apachectl start (code=exited, status=1/FAILURE) Main PID: 3830 (code=exited, status=0/SUCCESS)

                  Aug 14 22:48:17 hostname apachectl[4098]: [Thu Aug 14 22:48:17.6360… Aug 14 22:48:17 hostname apachectl[4098]: AH00013: Pre-configuratio… Aug 14 22:48:17 hostname systemd[1]: httpd.service: control proces…1 Aug 14 22:48:17 hostname systemd[1]: Failed to start Apache Web Se… Aug 14 22:48:17 hostname systemd[1]: Unit httpd.service entered fa… Hint: Some lines were ellipsized, use -l to show in full.

                  if I remove those 3 lines, apache running well, but apache doesnt interpret my php file.

                  Thanks, hoping for your support

                  Andrew SB
                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  August 14, 2014

                  @mirzalazuardi: Run apachectl configtest It should give you an idea of what the issue might be.

                  @mirzalazuardi @asb Having same issue, only difference is:

                  [root@x]# systemctl status httpd.service
                  ● httpd.service - Apache Web Server
                     Loaded: loaded (/usr/lib/systemd/system/httpd.service; ***disabled***)
                  
                  apachectl configtest
                  

                  Comes back clean.

                  I’ve isolated it to only the line

                  LoadModule php5_module       modules/libphp5.so
                  

                  Edit: Weird so I ran configtest again and I got an error: “Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe.” Easy fix:

                  /etc/httpd/conf/httpd.conf
                  # This line was causing problems, comment it or remove:
                  # LoadModule mpm_event_module modules/mod_mpm_event.so
                  
                  # Add in this line:
                  LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
                  

                  arch wiki

                  @etel Please update the tutorial with @01010101110 comment where he suggests to change the LoadModule line in /etc/httpd/conf/httpd.conf as per the PHP section of the Arch Linux Apache HTTP Server Wiki and FS#39218 - [php] Enable thread safety.

                  This comment has been deleted

                    Hi ,

                    I installed apache http server and everything going well. I’m using Sublime Text 2 as my text editor.So when i going to save some file after editing it with sublime text it says that "Unable to save file to /svr/http/*** " … I think it happening beacaus of permission problem. I’m using my pc as a normal user (not as the root).how can i solve this.

                    Thanks !

                    Thank you!

                    In the instalation’s step of mariadb before run the command “sudo systemctl start mysqld” gone need run “mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql” . Tried run without it but no work. I’m using Antergos Linux 64-bit

                    UPDATE for PHP7 In /etc/httpd/conf/httpd.conf, comment the line: #LoadModule mpm_event_module modules/mod_mpm_event.so

                    and uncomment the line: LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

                    The above is required, because libphp7.so included with php-apache does not work with mod_mpm_event, but will only work mod_mpm_prefork instead.

                    Then replace:


                    Use for PHP 5.x:

                    LoadModule php5_module modules/libphp5.so AddHandler php5-script php Include conf/extra/php5_module.conf


                    With


                    Use for PHP 7.x:

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


                    REF: https://wiki.archlinux.org/index.php/Apache_HTTP_Server#PHP

                    As of recent using MariaDb in Arch it is importan to install and initialize MariaDB date directory using $ sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

                    before running sudo mysql_secure_installation

                    On Manjaro (I don’t know if it applies to another Arch distro) when you install MySQL (MariaDB) you cannot directly start the dbms via sudo systemctl start mysqld. Previous to do it, you’ll need to run mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql to create the MySQL tables in the corresponding directory.

                    After that, follow the guide as normal.

                    Join the Tech Talk
                    Success! Thank you! Please check your email for further details.

                    Please complete your information!

                    Become a contributor for community

                    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

                    DigitalOcean Documentation

                    Full documentation for every DigitalOcean product.

                    Resources for startups and SMBs

                    The Wave has everything you need to know about building a business, from raising funding to marketing your product.

                    Get our newsletter

                    Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

                    New accounts only. By submitting your email you agree to our Privacy Policy

                    The developer cloud

                    Scale up as you grow — whether you're running one virtual machine or ten thousand.

                    Get started for free

                    Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

                    *This promotional offer applies to new accounts only.