Support #974
Install Wordpress on Debian
Start date:
07/13/2022
Due date:
% Done:
100%
Estimated time:
Description
This is a simple guide for setting up WordPress with nginx on Debian 10.
- Make sure the system is up to date:
sudo apt update && sudo apt upgrade
Install Nginx¶
- Install nginx:
sudo apt install nginx
- Start and enable nginx at boot:
sudo systemctl nginx enable sudo systemctl nginx start
Install PHP¶
- Install php-fpm and extensions:
sudo apt install php-fpm php-common php-gd php-getid3 php-mysql php7.3-cli php7.3-common php7.3-gd php7.3-json php7.3-mysql php7.3-opcache php7.3-readline
- Start and enable php-fpm:
sudo systemctl enable php7.3-fpm sudo systemctl start php7.3-fpm
Install MariaDB¶
- Install MariaDB:
sudo apt install mariadb-server mariadb-client
- Secure the database server:
sudo mysql_secure_installation
- NOTE: I had an issue logging in as root, to workaround this:
sudo systemctl stop mariadb sudo mysqld_safe --skip-grant-tables --skip-networking mysql -u root UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'unix_socket'; FLUSH PRIVILEGES; sudo kill -9 $(pgrep mysql) sudo systemctl start mariadb
- NOTE: I had an issue logging in as root, to workaround this:
Configure a new MySQL database¶
- Log into the MySQL console:
mysql -h localhost -u root -p
- Create the wordpressuser user with the SuperSecretPassword password and the wordpressdb database:
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'SuperSecretPassword'; CREATE DATABASE IF NOT EXISTS `wordpressdb` CHARACTER SET utf8 COLLATE utf8_general_ci; GRANT ALL PRIVILEGES ON `wordpressdb`.* TO 'wordpressuser'@'localhost'; flush privileges; exit
- Create the wordpressuser user with the SuperSecretPassword password and the wordpressdb database:
Install Wordpress¶
- Install git:
sudo apt install git
- Download wordpress:
cd /var/www sudo git clone -b 6.0-branch --depth=1 https://github.com/WordPress/WordPress.git
- Create the nginx config:
sudo nano /etc/nginx/sites-enabled/wordpress.conf
- And add the following:
fastcgi_cache_path /var/cache/nginx/examplesite.com levels=1:2 keys_zone=wpcache:200m max_size=10G inactive=2h use_temp_path=off; fastcgi_cache_key "$scheme$request_method$host$request_uri"; fastcgi_ignore_headers Cache-Control Expires Set-Cookie; upstream SITEPHP { server unix:/var/run/examplesite.com.sock; } server { listen 80; server_name examplesite.com; root /usr/local/www/examplesite.com; index index.php; client_max_body_size 12m; set $skip_cache 0; if ($request_method = POST) { set $skip_cache 1; } if ($query_string != "") { set $skip_cache 1; } if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|^/feed/*|/tag/.*/feed/*|index.php|/.*sitemap.*\.(xml|xsl)") { set $skip_cache 1; } if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { set $skip_cache 1; } add_header X-FastCGI-Cache $upstream_cache_status; location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params; fastcgi_intercept_errors on; fastcgi_pass SITEPHP; fastcgi_cache wpcache; fastcgi_cache_valid 200 301 302 2h; fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503; fastcgi_cache_min_uses 1; fastcgi_cache_lock on; fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } } server { listen 443 ssl; server_name examplesite.com; root /var/www/examplesite.com; index index.php; client_max_body_size 128m; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; set $skip_cache 0; if ($request_method = POST) { set $skip_cache 1; } if ($query_string != "") { set $skip_cache 1; } if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|^/feed/*|/tag/.*/feed/*|index.php|/.*sitemap.*\.(xml|xsl)") { set $skip_cache 1; } if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { set $skip_cache 1; } ssl_certificate /etc/letsencrypt/live/examplesite.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/examplesite.com/privkey.pem; # Configure Strong SSL ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers EECDH+CHACHA20:EECDH+AESGCM:EDH+AESGCM:AES256+EECDH; ssl_prefer_server_ciphers on; ssl_session_cache builtin:1000 shared:SSL:10m; ssl_stapling on; ssl_stapling_verify on; ssl_dhparam /usr/local/etc/nginx/dhparam.pem; add_header Strict-Transport-Security max-age=63072000; add_header X-Frame-Options SAMEORIGIN; add_header X-Content-Type-Options nosniff; add_header X-FastCGI-Cache $upstream_cache_status; location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_cache wpcache; fastcgi_cache_valid 200 301 302 2h; fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503; fastcgi_cache_min_uses 1; fastcgi_cache_lock on; fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; include fastcgi_params; fastcgi_intercept_errors on; fastcgi_pass SITEPHP; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } }
- And add the following:
- Change the wordpress ownership:
sudo chown -R www-data:www-data /var/www/WordPress/
- Restart nginx:
sudo systemctl nginx restart
Updated by Daniel Curtis almost 2 years ago
- % Done changed from 0 to 100
- Status changed from New to Resolved