# Wordpress
```bash
sudo apt update && apt full-upgrade -y
sudo apt install apache2 wget curl git php libapache2-mod-php php-cli php-mysql php-zip php-curl php-xml php-json php-gd php-intl php-mbstring php-imagick php-fpm php-dom php-gd php-imagick -y
```
## apache
### wpugo
```bash
wget https://wordpress.org/latest.tar.gz --directory-prefix=/tmp/
sudo tar xvfa /tmp/latest.tar.gz -C /var/www/wpugo/ --strip-components=1
sudo chown -R www-data:www-data /var/www/wpugo/
sudo rm /var/www/wpugo/index.nginx-debian.html
sudo cp wordpress/wp-config-sample.php wordpress/wp-config.php
```
> edit wordpress/wp-config.php with database infos
| Database | User | Password | Host |
|---|
| wpugo | wordpress | wordpress | patrick:3306 |
| `sudo rm /var/www/wpugo/readme.html` | | | |
> add virtualhost to /etc/apache2/sites-available/ugo.delmar.bzh.conf
```conf
ServerName ugo.delmar.bzh
DocumentRoot /var/www/wpugo
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
```
> vim /var/www/html/wp-admin/setup-config.php
> Add before line 20 (20 gg)
> `> $_SERVER['HTTPS']='on';`
> sudo vim /var/www/html/wp-config-sample.php
> Add before line 82 (82 gg)
> `$_SERVER['HTTPS']='on';`
```bash
sudo chmod -v 666 /var/www/wpugo/.htaccess
sudo a2ensite ugo.delmar.bzh.conf
sudo a2dissite 000-default
apache2ctl configtest
```
```
# Redirection vers HTTPS
RewriteCond %{SERVER_PORT} ^8082$ [OR]
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://ugo.delmar.bzh/$1 [R=301,L]
# Redirection du non-www vers www en HTTPS
RewriteCond %{HTTP_HOST} ^delmar.bzh [NC]
RewriteRule ^(.*)$ https://ugo.delmar.bzh/$1 [R=301,L]
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
```
> sudo vim /etc/apache2/mods-enabled/dir.conf
> `DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm`
```bash
systemctl reload apache2
exit
```
### Starting WP
#### Database infos
| Website | Database | Name | Username | Password | Host | Prefix |
|---|
| wp1 | wpjul | wordpress | 28CWAm2yDy2PMVnU9ZwtxvNQ | db.lxd | wp\_ | |
| wp2 | wpugo | wordpress | 28CWAm2yDy2PMVnU9ZwtxvNQ | db.lxd | wp\_ | |
\#docker #apache #mariadb #server #cms #blog
### Fix upload\_max\_filesize directive
1. Get container ID : `sudo docker container ls --filter name='wordpress'`
2. Update .htaccess file : `sudo docker container exec -it bash -c "echo 'php_value upload_max_filesize 256M' > '/var/www/html/.htaccess'"`
---
##### **(!) In order to handle SEO url, include rewrite rules in [delmar.bzh.conf](https://bookstack.delmar.bzh/books/selfhosted/page/lamp "L.A.M.P")**
## VirtualHost
```
.
├── apache
| └── wordpress (82)
└── mariadb
```
`/etc/apache2/sites-available/delmar.bzh.conf`
```conf
ServerName ugo.delmar.bzh
ServerAdmin ugo@delmar.bzh
DocumentRoot /var/www/wpugo
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
```