Created Tuesday 10 January 2017
This is a setup guide for the Linux Apache MySQL PHP development environment (web-development)
# Once below installation steps has been followed, you can enter you web-directory from the browser
localhost/adminer # Database management
Apache
# Install the package
$ pacman -S apache
# And enable/start the service
# For every configuration you make, the service has to be restarted before the changes take affect.
$ systemctl enable httpd.service
# In order for Apache to read your web-directory, a few permissions has to be changed
$ chmod o+x ~
$ chmod o+rx ~/Dropbox
Configuration
# Apaches configuration files can be found at /etc/httpd/conf/httpd.conf
Limit access only from local machine
# Change Listen 80 to your localhost
Listen 127.0.0.1:80
Change directory
# Change to the location where you store all your web-projects. Mine would be ~/Dropbox/www
DocumentRoot "/home/stick/Dropbox/www" <Directory "/home/stick/Dropbox/www">
Setup to use PHP
# One line needs to be commented out and another needs to be uncommented - as shown
#LoadModule mpm_event_module modules/mod_mpm_event.so LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
# This needs to go AFTER LoadModule dir_module modules/mod_dir.so
LoadModule php7_module modules/libphp7.so
# This goes at the END of the include list
Include conf/extra/php7_module.conf
# This goes at the END in LoadModule
AddHandler php7-script php
Setup to use MySQL
# Add this line to enable adminer- which will be our front-end for administrating our databases
Include conf/extra/httpd-adminer.conf
A few security measures
# This is from a separate configuration file found in /etc/httpd/conf/extra/httpd-default.conf
# Turn off ServerSignature and hide additional information with ServerTokens
ServerSignature Off ServerTokens Prod
PHP
# Install these two packages
$ pacman -S php php-apache
Configuration
# The PHP configuration files can be found at /etc/php/php.ini
Change the Timezone
# Edit and uncomment the Timezone line
date.timezone = Europe/Copenhagen
Turn on Errors
# Edit the error_reporting line and turn on errors in the display_errors line
error_reporting = E_ALL display_errors=On
Setup to use MySQL
# Uncomment the following two lines
extension=pdo_mysql extension=mysqli
MySQL
# We'll use mariadb
$ pacman -S mariadb
# Our front-end to administrate our databases
$ yaourt -S adminer
Configuration
# This needs to be run BEFORE enabling/starting the service file
$ mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
# Then enable and start the mariadb service file
$ systemctl enable mariadb.service
$ systemctl start mariadb.service
# And run the Setup Wizard AS ROOT! - follow the few steps. Basically just yes to it all^
$ sudo mysql_secure_installation
# The remaining configuration is done in /etc/mysql/my.cnf
Only allow local access
# Uncomment skip-networking and leave Port blank in both [client] and [mysqld]
[client] Port = [mysqld] Port = skip-networking
Use UTF-8
# Add these lines to the [mysqld] group
[mysqld] init_connect = 'SET collation_connection = utf8_general_ci,NAMES utf8' collation_server = utf8_general_ci character_set_client = utf8 character_set_server = utf8
Tips and Tricks
# A couple of additions
Imagick
# For the imagick features - which have a nice collection of features - install the following package from the AUR
$ cower -d php-imagick
$ cowup
# Then add the following line to the extensions section in the /etc/php/php.ini file
extension=imagick
PHPs mail() from localhost
# To send mails from localhost, install the msmtp package, along with its msmtp-mta
$ pacman -S msmtp msmtp-mta
# Create a rc file in /etc and add the following. Remember to edit the password and username.
# I am currently just using a gmail account for this shit.
$ vim /etc/msmtprc
# Set default values for all following accounts. defaults auth on tls on tls_trust_file /etc/ssl/certs/ca-certificates.crt logfile ~/.msmtp.log # Gmail account gmail host smtp.gmail.com port 587 from username@gmail.com user username password plain-text-password # A freemail service account freemail host smtp.freemail.example from joe_smith@freemail.example ... # Set a default account account default : gmail
# On Gmail (via browser) go to the settings and select IMAP/POP. Activate IMAP and save.
# You need to get to additional google settings, I can't remember how I got here,
# but from there you can go to security and select something like "Allow less secure apps".
# Activate that feature aswell.
# Chown and chmod the msmtprc file
$ chown stick /etc/msmtprc
$ chmod 600 /etc/msmtprc
# It should now be possible to send mails from localhost. Test it from the terminal:
$ php -a
php > mail("jeppesen@tutanota.com", "test", "test");