Project

General

Profile

Support #839

Install a Linux, Apache2, MySQL, PHP Web Server on Arch Linux

Added by Daniel Curtis about 8 years ago. Updated about 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Web Server
Target version:
Start date:
08/07/2016
Due date:
% Done:

100%

Estimated time:
1.50 h
Spent time:

Description

This is a guide on how to set up a LAMP Web Server on Arch Linux.

Prepare the Environment

  • Switch to the root user:
    sudo -s
    
  • Make sure the system is up to date:
    pacman -Syu
    

Install MySQL

  • Install mariadb:
    pacman -S mariadb
    
  • Run the following command before starting the mariadb.service to create the database:
    mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
    
  • Start and enable mariadb at boot:
    systemctl enable mariadb
    systemctl start mariadb
    
  • The run the initial configuration script:
    mysql_secure_installation
    

Create a new MySQL database

  • Log into the MySQL console:
    mysql -h localhost -u root -p
    
    • Create the webappuser user with the SuperSecretPassword password and the webappdb database:
      CREATE USER 'webappuser'@'localhost' IDENTIFIED BY 'SuperSecretPassword';   
      CREATE DATABASE IF NOT EXISTS  `webappdb` CHARACTER SET utf8 COLLATE utf8_general_ci;
      GRANT ALL PRIVILEGES ON `webappdb`.* TO 'webbappuser'@'localhost';
      
      flush privileges;
      exit
      

Install Apache

  • Install apache:
    pacman -S apache
    
  • Start and enable apache at boot:
    systemctl enable httpd
    systemctl start httpd
    

Install PHP

  • Install php and php-apache:
    pacman -S php php-apache
    
  • Edit the php config file:
    nano /etc/php/php.ini
    
    • Set your timezone:
      date.timezone = America/Los_Angeles
      
    • Change display_errors to Off:
      display_errors=On
      
    • Limit the paths that can be accessed by PHP:
      open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/
      
    • Uncomment the following lines to enable the mysql extension:
      extension=pdo_mysql.so
      extension=mysqli.so
      
  • Edit the main apache config file again:
    nano /etc/httpd/conf/httpd.conf
    
    • Comment the following line:
      #LoadModule mpm_event_module modules/mod_mpm_event.so
      
    • Then uncomment the following line:
      LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
      
    • Place this in the LoadModule list anywhere after LoadModule dir_module modules/mod_dir.so:
      LoadModule php7_module modules/libphp7.so
      
    • Place the following line at the end of the Include list:
      Include conf/extra/php7_module.conf
      
  • Restart apache:
    systemctl restart httpd
    
  • Create a file called test.php in your Apache DocumentRoot directory:
    nano /srv/http/test.php
    
    • And add the following contents:
      <?php phpinfo(); ?>
      

Resources

Also available in: Atom PDF