Guide to install Apache, PHP, MariaDB and PhpMyAdmin on your archlinux system and serve php-based database applications
pacman -S apache php php-apache mariadb phpmyadmin
The main PHP configuration file is well-documented and located at /etc/php/php.ini
If you want to display errors in browser set: display_errors = On
You can also enable error reporting in .htaccess
file: php_flag display_errors On
If you want to use mysqli operations to connect to a mysql database uncomment theese lines in php.ini
extension=mysqli
extension=pdo_mysql
If you want to use sessions go to the [Session]
section in php.ini
Uncomment the line:
session.save_path = "/tmp"
Configure how PHP sends mails when usign the mail()
function at the [mail function]
section in php.ini
For testing you can simulate sending mails to a logfile:
sendmail_path = 'cat >> /your/path/sendmail.log'
mail.log = "/your/path/sendmail.log"
Make sure Apache has permissoins to write to that file
The main Apache configuration file is located at /etc/httpd/conf/httpd.conf
The default Doument Root is /srv/http
On linux lammp installation the
httpd.conf
is located at/opt/lampp/etc/httpd.conf
The default Document root is:/opt/lampp/htdocs
Make sure to restart apache after a configuration to see it's effects.
To tell apache where your app is located and with which alias it can be accessed create a new config file: /etc/httpd/conf/extra/<YOUR_APP>.conf
Alias /<YOUR_ALIAS> "path/to/application"
<Directory "path/to/application">
DirectoryIndex index.html
AllowOverride All
Options FollowSymlinks
Require all granted
</Directory>
Now we have to tell apache to use this new config file. Add the following line to your /etc/httpd/conf/httpd.conf
Include conf/extra/<YOUR_APP>.conf
This was the main part, but mostly the apache user does not have access rights to the specified folder in your filesystem. The result is a 403 Error.
To fix this, you can give every user full access to your project folder (Attention: make sure if that makes sense in your use case):
chmod -R 777 /path/to/project/
Make sure, that apache has also has access to the folder that contains your project (Read access is enough here)
E.g. if your project is located under /home/username/project
use:
chmod 711 /home/username/
By default Apache would just serve your php files as plain text files. To make apache execute your php scripts follow theese steps:
Make sure that the mpm_event module is disabled and the mpm_prefork module is enabled
In your httpd.conf
#LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
Add to your httpd.conf:
LoadModule php_module modules/libphp.so
AddHandler php-script .php
Include conf/extra/php_module.conf
systemctl start httpd.service
systemctl stop httpd.service
systemctl restart httpd.service
systemctl enable httpd.service #autostart service on boot
Run mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Start the mariadb service: systemctl enable --now mariadb
mysql --protocol=socket #run this command as root (e.g. prefixed with sudo)
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE `db_name`;
GRANT ALL PRIVILEGES ON `db_name` . * TO 'username'@'localhost';
Create the Apache configuration file:
/etc/httpd/conf/extra/phpmyadmin.conf
Alias /phpmyadmin "/usr/share/webapps/phpMyAdmin"
<Directory "/usr/share/webapps/phpMyAdmin">
DirectoryIndex index.php
AllowOverride All
Options FollowSymlinks
Require all granted
</Directory>
And include it in /etc/httpd/conf/httpd.conf
:
# phpMyAdmin configuration
Include conf/extra/phpmyadmin.conf
Make sure to restart the apache daemon after your configurations: systemctl restart httpd
Open your browser and go to: localhost/your-app