You have installed Arch Linux, great. Now what about installing a web server to display your personal website, for example?
In this post, I explain step-by-step how to install and configure WordPress. For this, you need four components, commonly called “the LAMP stack”. It is a “stack” because each level derives off its base layer. The letters in LAMP refer to four layers:
- L for Linux, the operating system. This should be done already – if not, read this post and come back here.
- A for Apache. This is the web server, the software that receives the HTTP requests and sends back the responses to the clients that want to see your website on their browser.
- M for MySQL. This is the database that contains your blog posts, users, comments, and anything else that WordPress needs in a database format.
- P for PHP. This is the part that dynamically interacts with ???
Apache
The Apache HTTP Server is a free and open-source cross-platform web server software.
Apache supports a variety of features, many implemented as compiled modules which extend the core functionality. These can range from server-side programming language support to authentication schemes. Some common language interfaces support Perl, Python, Tcl, and PHP. Popular authentication modules include mod access, mod auth, mod digest, and mod auth digest, the successor to mod_digest. A sample of other features include SSL and TLS support (mod ssl), a proxy module (mod proxy), a URL rewriter (implemented under mod rewrite), custom log files (mod log config), and filtering support (mod include and mod ext filter).
Installing Apache on Arch Linux is straightforward, just run:
sudo pacman -S apache
Configuration
/etc/httpd/conf
is the folder that contain the configuration files
/etc/httpd/conf/httpd.conf
is the main configuration file, which includes various other configuration files
# Uncomment to enable virtual hosts:
Include conf/extra/httpd-vhosts.conf
/etc/httpd/conf/extra/httpd-default.conf
contains default settings
# To hide server information like Apache and PHP versions:
ServerTokens Prod
# To turn off your server's signature:
ServerSignature Off
PHP
sudo pacman -S php php-apache
install PHP
# Comment this line:
#LoadModule mpm_event_module modules/mod_mpm_event.so
# Uncomment this line:
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
# Place this at the end of the LoadModule list:
LoadModule php_module modules/libphp.so
AddHandler php-script .php
# Place this at the end of the Include list:
Include conf/extra/php_module.conf
To test whether PHP was correctly configured:
echo "<?php phpinfo(); ?>" | sudo tee /srv/http/test.php
createtest.php
file- go to http://localhost/test.php
Virtual hosts
<VirtualHost *:80>
ServerName *example.com*
ServerAlias *www.example.com*
ServerAdmin *example*@*example.com*
DocumentRoot /srv/http/*example*
ErrorLog /var/log/httpd/*example*-error.log
CustomLog /var/log/httpd/*example*-access.log combined
</VirtualHost>
User directories
User directories are available by default through http://localhost/~*username*
and show the contents of ~/public_html
(this can be changed in /etc/httpd/conf/extra/httpd-userdir.conf
).
mkdir $HOME/public_html
touch $HOME/public_html/index.html
chown user:http $HOME $HOME/public_html $HOME/public_html/index.html
chmod 750 $HOME $HOME/public_html $HOME/public_html/index.html
give only read (descend into) permission to the web server user for the home directory and the user directory
TLS
ServerName www.example.com
# Uncomment:
LoadModule ssl_module modules/mod_ssl.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
# Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf
Set up an HTTP-to-HTTPS redirection to force HTTPS:
<VirtualHost *:80 [::]:80>
# Redirect all traffic to HTTPS
Redirect permanent / <https://example.com/>
Certbot
The plugin certbot-apache
provides an automatic configuration for the Apache HTTP Server. This plugin will try to detect the configuration setup for each domain. The plugin adds extra configuration recommended for security, settings for certificate use, and paths to Certbot certificates.
certbot comes with a systemd certbot-renew.service
, which attempts to renew certificates that expire in less than 30 days. If all certificates are not due for renewal, this service does nothing.
sudo cp -r /etc/httpd/conf /etc/httpd/conf.bak
backup configuration files
# Uncomment:
LoadModule rewrite_module modules/mod_rewrite.so
sudo pacman -S certbot-apache
install plugin
sudo certbot --apache
get a certificate and configure Apache automatically
sudo chmod 700 /etc/letsencrypt/archive
sudo chmod 755 /etc/letsencrypt/live
sudo chmod 600 /etc/letsencrypt/live/example.com/privkey.pem
sudo systemctl restart httpd
Usage
sudo systemctl start httpd.service
run Apache
httpd
-M
dump a list of loaded static and shared modules-t
run syntax tests for configuration files only-S
show the settings as parsed from the config file (currently only shows the virtualhost settings)
sudo apachectl configtest
run a configuration file syntax test. It parses the configuration files and either reports Syntax Ok
or detailed information about the particular syntax error. This is equivalent to apachectl -t
.
WordPress installation
We are now ready to proceed with the last layer of the LAMP stack: WordPress itself.
But we first need to tweak some configuration files for Apache and PHP.
Apache
Enable the Apache module unique_id_module
that provides a magic token for each request guaranteed to be unique across all requests.
# Uncomment:
LoadModule unique_id_module modules/mod_unique_id.so
LoadModule rewrite_module modules/mod_rewrite.so
Alias /wordpress "/srv/http/wordpress"
<Directory "/srv/http/wordpress">
AllowOverride All
Options FollowSymlinks
Require all granted
</Directory>
PHP
sudo pacman -S php-gd
WordPress needs php-gd
to modify images
# Uncomment:
extension=gd
extension=mysqli
# Change the maximum upload file size of the media library
; Maximum allowed size for uploaded files.
upload_max_filesize = 64M
; Maximum size of POST data that PHP will accept.
post_max_size = 64M
MariaDB
sudo pacman -S mariadb
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
sudo systemctl start mariadb.service
sudo mariadb-secure-installation
MariaDB installation with a number of recommended security measures, such as removing anonymous accounts and removing the test database
sudo mariadb -u root -p
login as root, and enter the commands:
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO "example-user"@"localhost" IDENTIFIED BY "example_password";
FLUSH PRIVILEGES;
EXIT
WordPress
OK, now everything is ready to install WordPress. The process is relatively easy and just involves downloading a compressed file that contains WordPress, uncompressing the file, change form configuration in a file, and completing the installation in a browser.
cd /srv/http
sudo wget <https://wordpress.org/latest.tar.gz
sudo tar xvzf latest.tar.gz
sudo rm latest.tar.gz
sudo chown -R http:http /srv/http/wordpress
cd wordpress
sudo cp wp-config-sample.php wp-config.php
sudo nano /srv/http/wordpress/wp-config.php
set the database details in the configuration file:
define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'example-user' );
define( 'DB_PASSWORD', 'example-password' );
/* Add any custom values between this line and the "stop editing" line. */
/* to be added if <http://192.168.178.2/wordpress/wp-admin> redirects to <http://localhost/wordpress/wp-login.php?redirect_to=http%3A%2F%2F192.168.178.2%2Fwordpress%2Fwp-admin%2F&reauth=1> */
if (isset($_SERVER['HTTP_HOST'])) {
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://';
define('WP_HOME', $protocol . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', $protocol . $_SERVER['HTTP_HOST']);
}
Go to http://localhost/wordpress to finish the installation.
http://localhost/wordpress/wp-admin admin page