Project

General

Profile

Support #839

Updated by Daniel Curtis over 7 years ago

{{>toc}} 

 This is a guide on how to set up a LAMP(Linux, Apache2, MySQL, PHP) Web Server on Arch Linux. 

 h2. Prepare the Environment 

 * Switch to the root user: 
 <pre> 
 sudo -s 
 </pre> 

 * Make sure the system is up to date: 
 <pre> 
 pacman -Syu 
 </pre> 

 h2. Install MySQL 

 * Install mariadb: 
 <pre> 
 pacman -S mariadb 
 </pre> 

 * Run the following command before starting the mariadb.service to create the database: 
 <pre> 
 mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql 
 </pre> 

 * Start and enable mariadb at boot: 
 <pre> 
 systemctl enable mariadb 
 systemctl start mariadb 
 </pre> 

 * The run the initial configuration script: 
 <pre> 
 mysql_secure_installation 
 </pre> 

 h3. Create a new MySQL database 

 * Log into the MySQL console: 
 <pre> 
 mysql -h localhost -u root -p 
 </pre> 
 #* Create the *webappuser* user with the *SuperSecretPassword* password and the *webappdb* database: 
 <pre> 
 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 
 </pre> 

 h2. Install Apache 

 * Install apache: 
 <pre> 
 pacman -S apache 
 </pre> 

 * Start and enable apache at boot: 
 <pre> 
 systemctl enable httpd 
 systemctl start httpd 
 </pre> 

 



 h2. Install PHP 

 * Install php and php-apache: 
 <pre> 
 pacman -S php php-apache 
 </pre> 

 * Edit the php config file: 
 <pre> 
 nano /etc/php/php.ini 
 </pre> 
 #* Set your timezone: 
 <pre> 
 date.timezone = America/Los_Angeles 
 </pre> 
 #* Change display_errors to Off: 
 <pre> 
 display_errors=On 
 </pre> 
 #* Limit the paths that can be accessed by PHP: 
 <pre> 
 open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/ 
 </pre> 
 #* Uncomment the following lines to enable the mysql extension: 
 <pre> 
 extension=pdo_mysql.so 
 extension=mysqli.so 
 </pre> 

 * Edit the main apache config file again: 
 <pre> 
 nano /etc/httpd/conf/httpd.conf 
 </pre> 
 #* Comment the following line: 
 <pre> 
 #LoadModule mpm_event_module modules/mod_mpm_event.so 
 </pre> 
 #* Then uncomment the following line: 
 <pre> 
 LoadModule mpm_prefork_module modules/mod_mpm_prefork.so 
 </pre> 
 #* Place this in the @LoadModule@ list anywhere after @LoadModule dir_module modules/mod_dir.so@: 
 <pre> 
 LoadModule php7_module modules/libphp7.so 
 </pre> 
 #* Place the following line at the end of the @Include@ list: 
 <pre> 
 Include conf/extra/php7_module.conf 
 </pre> 

 * Restart apache: 
 <pre> 
 systemctl restart httpd 
 </pre> 

 * Create a file called test.php in your Apache DocumentRoot directory: 
 <pre> 
 nano /srv/http/test.php 
 </pre> 
 #* And add the following contents: 
 <pre> 
 <?php phpinfo(); ?> 
 </pre> 

 * To see if it works, open a web browser and go to http://localhost/test.php  

 h2. Resources 

 * https://wiki.archlinux.org/index.php/Apache_HTTP_Server 
 * https://wiki.archlinux.org/index.php/PHP 
 * https://wiki.archlinux.org/index.php/MySQL

Back