26 avril 2024

Ubuntu server – Installation et configuration de WordPress

Ma méthode pour déployer un stack LAMP et déployer WordPress en quelques lignes de commande.

Installation LAMP Stack (Linux, Apache, MySQL, and PHP)

sudo apt install tasksel
sudo tasksel install lamp-server
sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc

Configuration du domaine

Setup DNS

Go to your web domain registrar and create A record pointing to your new server or modify etc/hosts on host and guest for testing labConfigure

Apache conf for website

Search for existing site : cd /etc/apache2/sites-availables et ll

Copy 000-default.conf : 

$ sudo cp 000-default.conf farfad.fr.conf

Edit config file : sudo nano farfad.fr.conf

<Directory /var/www/html>        
Require all granted  
</Directory>  
<VirtualHost *:80>  
        ServerName farfad.fr
        ServerAlias www.farfad.fr
        ServerAdmin webmaster@localhost  
        DocumentRoot /var/www/html
</VirtualHost>

$ a2dissite 000-default.conf
$ a2ensite farfad.fr.conf
$ systemctl reload apache2

Go to website to see if apache is ok

Prepare Database and PHP

Create database

CREATE DATABASE wordpress;  
GRANT ALL ON wordpress.* TO 'wordpressuser' IDENTIFIED BY 'Secure1234!';  
quit  

Secure Mysql

mysql_secure_installation (yes to all question)

Edit /etc/php/7.2/apache2/php.ini

upload\_max\_filesize = 20M  
post\_max\_size = 21M

Install WordPress

$ cd /var/www/html/
$ mv index.html index.html.old (or rm)
$ wget https://wordpress.org/latest.tar.gz
$ tar -xzvf latest.tar.gz
$ cd /wordpress
$ mv * .. (Move files to the root html directory)
$ rm latest.tar.gz
$ rm -r wordpress

Edit wp-config.php

$ mv wp-config-sample.php wp-config.php
$ sudo nano wp-config.php
Edit DB name,user, password

Remove Authentication Unique Keys (define lines)
Go to https://api.wordpress.org/secret-key/1.1/salt/
Copy lines and paste them to the config file

Go to site and finish the configuration of wordpress

Troubleshooting


One important addition to setting up WordPress. Permission errors with the WordPress installation can be fixed with the following command.

$ chown -R www-data:www-data /var/www/html/*