User Tools

Site Tools


servers:nginx:wordpress

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
servers:nginx:wordpress [2019/06/28 22:48]
Sean Rhone
servers:nginx:wordpress [2020/04/24 12:19] (current)
Sean Rhone Ubuntu 20.04
Line 7: Line 7:
 ===== Prerequisites ===== ===== Prerequisites =====
  
-  * [[distros:fedora_server|Fedora Server]] +  * [[distros:ubuntu_server|Ubuntu Server]] ((Last tested on 20.04)) 
-  * [[servers:mariadb | MariaDB]] +  * [[servers:mariadb|MariaDB]] 
-  * [[servers:nginx_php_php-fpm | nginx + PHP + PHP-FPM]] +  * [[servers:nginx_php_php-fpm|nginx + PHP + PHP-FPM]] 
-  * [[servers:nginx:lets_encrypt | Let's Encrypt]]+  * [[servers:nginx:lets_encrypt|Let's Encrypt]]
  
 ===== Notes ===== ===== Notes =====
Line 20: Line 20:
 **** ****
  
-  sudo git clone --branch 'master' --depth '1' --recurse-submodules 'https://github.com/WordPress/WordPress.git' '/var/www/blog' && sudo chown -R 'nginx':'nginx' '/var/www/blog' && sync +  sudo git clone --branch 'master' --depth '1' --recurse-submodules 'https://github.com/WordPress/WordPress.git' '/var/www/blog' && sudo chown -R 'www-data':'www-data' '/var/www/blog' && sync
- +
-===== SELinux ===== +
- +
-  sudo semanage fcontext --deleteall "/var/www/blog(/.*)?" +
- +
-  sudo semanage fcontext --add --type 'httpd_sys_rw_content_t' "/var/www/blog(/.*)?" +
- +
-  sudo restorecon -R -v '/var/www/blog' && sync+
  
 ====== Database ====== ====== Database ======
  
-  mysql --user='root' --password+  sudo mysql
  
   CREATE DATABASE wordpress;   CREATE DATABASE wordpress;
Line 39: Line 31:
  
   FLUSH PRIVILEGES;   FLUSH PRIVILEGES;
 +
 +  EXIT
  
 ====== nginx + PHP-FPM Configuration ====== ====== nginx + PHP-FPM Configuration ======
Line 44: Line 38:
 ===== PHP-FPM Socket ===== ===== PHP-FPM Socket =====
  
-  sudo -e '/etc/php-fpm.d/blog.conf' && sudo systemctl restart 'php-fpm'+  sudo -e '/etc/php/7.4/fpm/pool.d/blog.conf' && sudo systemctl restart 'php7.4-fpm'
  
 <code> <code>
 [blog] [blog]
-user = nginx +user = www-data 
-group = nginx+group = www-data
  
-listen = /run/php-fpm/blog.sock +listen = /run/php/blog.sock 
-listen.owner = nginx +listen.owner = www-data 
-listen.group = nginx+listen.group = www-data
 listen.allowed_clients = 127.0.0.1 listen.allowed_clients = 127.0.0.1
  
Line 71: Line 65:
 php_value[max_file_uploads] = "100" php_value[max_file_uploads] = "100"
  
-php_value[session.save_handler] = files +php_value[session.save_handler] = "files" 
-php_value[session.save_path] = /var/lib/php/session +php_value[session.save_path] = "/var/lib/php/sessions" 
-php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache +php_value[soap.wsdl_cache_dir] = "/var/lib/php/wsdlcache" 
-php_value[opcache.file_cache] = /var/lib/php/opcache</code>+php_value[opcache.file_cache] = "/var/lib/php/opcache"</code>
  
 ===== FastCGI ===== ===== FastCGI =====
  
-  sudo -e '/etc/nginx/default.d/blog.conf'+  sudo -e '/etc/nginx/snippets/blog.conf'
  
 <code> <code>
Line 90: Line 84:
     fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;     fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     fastcgi_param PATH_INFO $fastcgi_path_info;     fastcgi_param PATH_INFO $fastcgi_path_info;
-    fastcgi_pass unix:/run/php-fpm/blog.sock;+    fastcgi_pass unix:/run/php/blog.sock;
 }</code> }</code>
  
Line 97: Line 91:
   * :!: ''style-src'' in the CSP blocks a Google font URL from being loaded ((at least with the Twenty Seventeen theme; nothing appears broken, so looks good to me)) ((add ''fonts.googleapis.com'' after ''unsafe-inline'' in ''style-src'' to fix this))   * :!: ''style-src'' in the CSP blocks a Google font URL from being loaded ((at least with the Twenty Seventeen theme; nothing appears broken, so looks good to me)) ((add ''fonts.googleapis.com'' after ''unsafe-inline'' in ''style-src'' to fix this))
  
-  sudo -e '/etc/nginx/conf.d/blog.conf' && sudo systemctl reload 'nginx'+  sudo -e '/etc/nginx/sites-available/blog.conf'
  
 <code> <code>
Line 106: Line 100:
     index 'index.php';     index 'index.php';
  
-    include '/etc/nginx/default.d/blog.conf'; +    include '/etc/nginx/snippets/blog.conf'; 
-    include '/etc/nginx/default.d/headers.conf';+    include '/etc/nginx/snippets/headers.conf';
  
     client_max_body_size '10M';     client_max_body_size '10M';
Line 126: Line 120:
     }     }
 }</code> }</code>
 +
 +==== Enable ====
 +
 +****
 +
 +  sudo rm -f '/etc/nginx/sites-enabled/blog.conf' && sudo ln -s '/etc/nginx/sites-available/blog.conf' '/etc/nginx/sites-enabled/blog.conf' && sudo systemctl reload 'nginx' && sync
  
 ====== Initial Setup ====== ====== Initial Setup ======
Line 145: Line 145:
 <code> <code>
 [Service] [Service]
-User=nginx +User=www-data 
-Group=nginx+Group=www-data
 Type=oneshot Type=oneshot
 ExecStart='/usr/bin/git' -C '/var/www/blog' pull origin 'master' ExecStart='/usr/bin/git' -C '/var/www/blog' pull origin 'master'
-ExecStartPost='/usr/bin/sync'</code>+ExecStartPost='/bin/sync'</code>
  
 ==== Timer ==== ==== Timer ====
Line 178: Line 178:
 <code> <code>
 [Service] [Service]
-User=nginx +User=www-data 
-Group=nginx+Group=www-data
 Type=oneshot Type=oneshot
 ExecStart='/usr/bin/git' -C '/var/www/blog' gc --aggressive --prune='all' ExecStart='/usr/bin/git' -C '/var/www/blog' gc --aggressive --prune='all'
 ExecStart='/usr/bin/git' -C '/var/www/blog' fsck --full --strict ExecStart='/usr/bin/git' -C '/var/www/blog' fsck --full --strict
-ExecStartPost='/usr/bin/sync'</code>+ExecStartPost='/bin/sync'</code>
  
 ==== Timer ==== ==== Timer ====
Line 216: Line 216:
 Type=oneshot Type=oneshot
 WorkingDirectory=/var/www WorkingDirectory=/var/www
-ExecStart='/usr/bin/bash' -c '"/usr/bin/tar" -cvzf "/home/CHANGEME/backups/wordpress-files-auto-"$$(date +%%Y-%%m-%%d)".tar.gz" "blog"' +ExecStart='/bin/bash' -c '"/bin/tar" -cvzf "/home/CHANGEME/backups/wordpress-files-auto-"$$(date +%%Y-%%m-%%d)".tar.gz" "blog"' 
-ExecStartPost='/usr/bin/sync'</code>+ExecStartPost='/bin/sync'</code>
  
 === Timer === === Timer ===
Line 256: Line 256:
 WorkingDirectory=/var/lib/mysql/tmp WorkingDirectory=/var/lib/mysql/tmp
 ExecStartPre='/usr/bin/mysqldump' --defaults-extra-file='/var/lib/mysql/auth/wordpress' --single-transaction 'wordpress' -r '/var/lib/mysql/tmp/wordpress.sql' ExecStartPre='/usr/bin/mysqldump' --defaults-extra-file='/var/lib/mysql/auth/wordpress' --single-transaction 'wordpress' -r '/var/lib/mysql/tmp/wordpress.sql'
-ExecStart='/usr/bin/gzip' -f '/var/lib/mysql/tmp/wordpress.sql' +ExecStart='/bin/gzip' -f '/var/lib/mysql/tmp/wordpress.sql' 
-ExecStart='/usr/bin/bash' -c '"/usr/bin/mv" "/var/lib/mysql/tmp/wordpress.sql.gz" "/home/CHANGEME/backups/wordpress-database-auto-"$$(date +%%Y-%%m-%%d)".sql.gz"' +ExecStart='/bin/bash' -c '"/bin/mv" "/var/lib/mysql/tmp/wordpress.sql.gz" "/home/CHANGEME/backups/wordpress-database-auto-"$$(date +%%Y-%%m-%%d)".sql.gz"' 
-ExecStartPost='/usr/bin/sync'</code>+ExecStartPost='/bin/sync'</code>
  
 === Timer === === Timer ===
Line 288: Line 288:
 **** ****
  
-  sudo systemctl stop nginx php-fpm+  sudo systemctl stop nginx php7.4-fpm
  
 ==== Backup Folder ==== ==== Backup Folder ====
Line 300: Line 300:
 **** ****
  
-  sudo -u 'mysql' mysqldump --defaults-extra-file='/var/lib/mysql/auth/wordpress' --single-transaction 'wordpress' -r ~/'wordpress-database-manual-'$(date +%Y-%m-%d)'.sql' && sync+  sudo mysqldump --defaults-extra-file='/var/lib/mysql/auth/wordpress' --single-transaction 'wordpress' -r ~/'wordpress-database-manual-'$(date +%Y-%m-%d)'.sql' && sync
  
 ==== Start Services ==== ==== Start Services ====
Line 306: Line 306:
 **** ****
  
-  sudo systemctl start nginx php-fpm+  sudo systemctl start nginx php7.4-fpm
  
 ===== Client ===== ===== Client =====
Line 336: Line 336:
 **** ****
  
-  rm -f ~/'Downloads/wordpress-files-'*'.tar.gz' ~/'Downloads/wordpress-database-'*'.sql.gz' && sync+  rm -f ~/'Downloads/wordpress-files-'*'.tar.gz' ~/'Downloads/wordpress-database-'*'.sql' && sync
  
 ===== Server ===== ===== Server =====
Line 344: Line 344:
 **** ****
  
-  sudo systemctl stop nginx php-fpm+  sudo systemctl stop nginx php7.4-fpm
  
 ==== Remove Previous Folder ==== ==== Remove Previous Folder ====
Line 356: Line 356:
 **** ****
  
-  cd '/var/www' && sudo tar -xvzf ~/'wordpress-files-'*'.tar.gz' 'blog' && sudo chown -R 'nginx':'nginx' '/var/www/blog' && cd ~ && sync +  cd '/var/www' && sudo tar -xvzf ~/'wordpress-files-'*'.tar.gz' 'blog' && sudo chown -R 'www-data':'www-data' '/var/www/blog' && cd ~ && sync
- +
-==== SELinux ==== +
- +
-  sudo semanage fcontext --deleteall "/var/www/blog(/.*)?" +
- +
-  sudo semanage fcontext --add --type 'httpd_sys_rw_content_t' "/var/www/blog(/.*)?" +
- +
-  sudo restorecon -R -v '/var/www/blog' && sync+
  
 ==== Drop Previous Database ==== ==== Drop Previous Database ====
  
-  mysql --user='root' --password+  sudo mysql
  
   DROP DATABASE wordpress;   DROP DATABASE wordpress;
  
   FLUSH TABLES;   FLUSH TABLES;
 +
 +  EXIT
  
 ==== Re-create Databases ==== ==== Re-create Databases ====
  
-  mysql --user='root' --password+  sudo mysql
  
   CREATE DATABASE wordpress;   CREATE DATABASE wordpress;
 +
 +  EXIT
  
 ==== Restore Database ==== ==== Restore Database ====
Line 384: Line 380:
 **** ****
  
-  mysql --user='root' --password 'wordpress' < ~/'wordpress-database-'*'.sql' && sync+  sudo mysql 'wordpress' < ~/'wordpress-database-'*'.sql' && sync
  
 ==== Reapply Permissions ==== ==== Reapply Permissions ====
  
-  mysql --user='root' --password+  sudo mysql
  
   GRANT ALL PRIVILEGES ON wordpress.* to 'wordpress'@'localhost' IDENTIFIED BY 'x';   GRANT ALL PRIVILEGES ON wordpress.* to 'wordpress'@'localhost' IDENTIFIED BY 'x';
  
   FLUSH PRIVILEGES;   FLUSH PRIVILEGES;
 +
 +  EXIT
  
 ==== Start Services ==== ==== Start Services ====
Line 398: Line 396:
 **** ****
  
-  sudo systemctl start nginx php-fpm+  sudo systemctl start nginx php7.4-fpm
  
 ==== Remove Backups ==== ==== Remove Backups ====
servers/nginx/wordpress.1561776480.txt.gz · Last modified: 2019/06/28 22:48 by Sean Rhone