Support #839
Install a Linux, Apache2, MySQL, PHP Web Server on Arch Linux
Description
- Table of contents
- Prepare the Environment
- Install MySQL
- Install Apache
- Install PHP
- Resources
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
- Create the webappuser user with the SuperSecretPassword password and the webappdb database:
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
- Set your timezone:
- 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 afterLoadModule 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
- Comment the following line:
- 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(); ?>
- And add the following contents:
- To see if it works, open a web browser and go to http://localhost/test.php