WordPress Installation:
As of 2/2016, WordPress is at version 4.4.x)
That means that you must be running mySQL 5.6 or greater, and PHP version 5.6 or greater.
Instructions for Ubuntu:
1. Install:
$ sudo apt-get install wordpress
Make the Wordpress share root a subfolder in Apache's folder structure:
$ sudo ln -s /usr/share/wordpress /var/www/html/wordpress
Upgrade/install mySQL server:
$ sudo apt-get install mysql-server
< this will include prompts for setting up root logins>
2. Setup the mySQL database, for WordPress
$ sudo gzip -d /usr/share/doc/wordpress/examples/setup-mysql.gz
$ sudo bash /usr/share/doc/wordpress/examples/setup-mysql -n mwwordpress localhost
(where mwwordpress is the name of the database, and localhost meaning the default/global web site)
Note: The second command to setup wordpress can be reused for multiple blog sites:
$ sudo bash /usr/share/doc/wordpress/examples/setup-mysql -n wordpress_mwdomain_net mwdomain.net
(where wordpress_mwdomain_net is the databasee for the WordPress site mwdomain.net)
Restart Apache:
$ sudo /etc/init.d/apache2 restart
3. Setup WordPress
Open a web browser and navigate to your WordPress site:
http://localhost/wordpress or if not on your server http://mwdomain.com/wordpress
(where mwdomain.com is the default web site for this server)
Complete the setup pages to start using WordPress.
Instructions for CentOS / RedHat:
1. Upgrade Apache (httpd), mySQL, and PHP, and myPHPAdmin.
If you are on CentOS 6.7 or CentOS 7, you will like NOT be up to PHP 5.6 and mySQL 5.6.
I had to enable the remi repository, to upgrade them.
Instructions for CentOS 6.7/7.
We have a bunch of commands to enter, they all need root access.
$ sudo su
<enter password>
Enable the Extras repository for CentOS and RedHat:
#sudo yum install epel-release
If that doesn't work, enable, based on the distribution version:
(Version URLs are in this wiki location: https://fedoraproject.org/wiki/EPEL )
CentOS 6:
# cd /root/tmp
# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
# rpm -Uvh epel-release-6*.rpmAdobe Creative Suite
CentOS 7 :
# cd /root/tmp
# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# rpm -Uvh epel-release-7*.rpm
RedHat 6:
# cd /root/tmp
# wget https://rhel6.iuscommunity.org/ius-release.rpm
sudo rpm -Uvh ius-release*.rpm
RedHat 7:
# cd /root/tmp
# wget https://rhel7.iuscommunity.org/ius-release.rpm
sudo rpm -Uvh ius-release*.rpm
Upgrade yum w/plugin-replace:
# yum install yum-plugin-replace
Finally, get the Remi repository, depending on the version of CentOS/RedHat:
(Version URLs are in this location: www.famillecollet.com )
CentOS 6 / RedHat 6:
# cd /root/tmp
# wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo rpm -Uvh remi-release-6*.rpm
CentOS 7 / RedHat 7:
# cd /root/tmp
# wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
sudo rpm -Uvh remi-release-7*.rpm
Enable the remi repository:
vi /etc/yum.reps.d/remi.repo
Under the section [remi], update enabled=0 to enabled=1, and save.
At this point, I could enable the whole remi repository, but I'm enabling the repository by command only to limit the packages which yum updates from remi.
2a. Upgrade the default *80 web site in the Apache config, to enable mod_rewrite.
# vi /etc/httpd/conf/httpd.conf
Locate the <Directory "/var/www/html"> section.
Update the line AllowOverride None to AllowOverride All, and save.
Save the update, and restart Apache.
# service httpd restart
(or use servicectl for the new way of restarting services)
2b. Make sure the /var/www/html folder to have a .htaccess file.
# ls -l /var/www/html/.htaccess
<if you don't get any results create it; otherwise, make sure that it is owned by apache and both the user and the group have access>
To create, and change access:
# touch /var/www/html/.htaccess
# chown root:root .htaccess
# chmod 664 .htaccess
You can check logs with:
# tail /var/log/http/error.log
3. Install/upgrade PHP and mySQL
# yum clean
# yum --enablerepo=remi,remi-php56 update
# yum --enablerepo=remi,remi-php56 upgrade php php-gd php-mysqlnd php-mcrypt
(Yes, PHP5.5 and 5.6 use php-mysqlInd insted of php-mysql)
Confirm version of php:
# php -v
Install phpMyAdmin:
# yum --enablerepo=remi install phpMyAdmin
(Yes, it's uppercase.)
Update the phpMyAdmin.conf to give access to your network, customize for your conditions, and save.
# vi /etc/http/conf.d/phpMyAdmin.conf
<Directory /usr/share/phpMyAdmin/>
<IfModule !mod_authz_core.c>
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from 192.168.99.0/24
</IfModule>
</Directory>
Note:
Evaluate other optimization actions to Apache for WordPress in the optimization/performance tweaks below these instructions.
Restart Apache again
# service httpd restart
Login to the phpMyAdmin in your web browser.
( e.g. http://localhost/phpMyAdmin or if not on your server http://mwdomain.com/phpMyAdmin .
Use your mysql username and password for login. )
Note: Stay logged into phpMyAdmin to create the database below.
4. Create a new database in mySQL. Create it's user.
Under the Databases tab, under the Create Database label:
a. Enter a database name for WordPress database ( e.g. wordpressmwcom )
b. Change the collation option from utf8 to utf8_unicode_ci / utf8_general_ci or your language.
c. Click Create, to create the empty database.
Click the Users tab, click the Add User button.
a. Enter the user in the User name field (e.g. wpusermwcom ).
b. Enter a secure password and confirm it in the Re-type field.
c. Leave all options enabled for the privileges, at default.
d. Click Go, to create the user.
Return to the Users tab, click Edit privileges. We need to give the new user access to the new WordPress database.
a. Locate the Database-specific privileges section
b. Under Add privileges to the following database dropdown, select the new database (e.g. mwwordpress_com).
c. Click Check All to select/give all privileges. Click Go.
4. Download the WordPress zip to tmp folder, update the database information, and copy into place.
# cd /root/tmp
# wget https://wordpress.org/latest.tar.gz
# tar -xzvf latest.tar.gz
Copy (cp) wp-config-sample.php to wp-config.php. Update the wp-config.php database info to the one you just created.
# cd wordpress
# cp vp-config-samplephp wp-config.php
# vi wp-config.php
Update the following lines in the file and save:
define('DB_NAME','wordpressmwcom');
define('DB_USER', 'wpusermwcom);
define('DB_PASSWORD','thewpuserpasswordenteredabove');
Copy into place:
# cd /root/tmp
# cp -r wordpress/* /var/www/html/
Customize ownership of files:
(folders typical 775, files typical 664, wp-config.php typical 600)
# chown apache:apache /var/www/html/wordpress/
# chmod 775 /var/www/html/wordpress/
# cd /var/www/html/wordpress/
# find . -type f -exec chmod 644 {}
# find . -type d -exec chmod 755 {}
# chmod 600 wp-config.php
Note: if WordPress won't function with wp-config.php being 600, then change to 644.
6. Run the configuration set-up, which they call installation. Open your web browser and complete the site setup.
http://mwwordpress.com/wp-admin/install.php
_____________________________________________________________________________________________
Apache Performance / Optimization for WordPress
1. Update httpd.conf, with the following updates:
a Remove all LoadModule entries not in use on the server.
WordPress NEEDS the following:
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
If you comment out the negotiation_module module entry, then you also need to comment out the Language Priority line and the ForceLanaguagePriority lines, as well.
In addition, I could not comments out a couple other authz and authn modules because they were in use w/in the Apache conf file. Since the server had a couple "normal" HTML sites, we needed to leave them.
b. Update the prefork.c entries and reduce the limits of servers and max clients, otherwise your Apache server could run out of memory. Alternately, you can increase the GBs of memory for your server, instead. You don't want the Apache processes to go into the disk swap or run the server out of memory.
With Apache services stopped, find out the free memory:
# free -m
Start Apache and wait a few minutes for your Apache processes to come to full size.
The size of each httpd process could be 15MB, and for one site we had to help manage, the developer had created a complex WordPress site w/a large gallery and lots of "cool" plugins; the result was that each httpd process was 459MB.
If you have 4096Mb of "free" memory (don't include swap), you do the following math:
- (Free Memory - the VPS httpd apache process) / process size
( 4096Mb - 132MB ) / 459 MB = 3964MB / 459 MB = 8.6 MaxClients.
So for the above WordPress site, you might want to increase the RAM in the server. This web site typically sees a peak usage of 50 concurrent users. Of course, you could pull out some of those cool plugins from your WordPress site, but what fun would that be? That night we added 16 GB to the server for a total of 20 GB of free RAM).
(20480 - 132MB) / 459 MB = 20348 / 459 MB = 44.3 MaxClients
This was deemed close enough. So our prefork.c section was updated like below:
<IfModule prefork.c>
StartServers 3
MinSpareServers 3
MaxSpareServers 12
ServerLimit 50
MaxClients 50
MaxRequestsPerChild 2000
</IfModule>
StartServers = Number of apache httpd server processes started with "service httpd start".
MinSpareServers = Number of spare, at the ready, httpd processes for bursts, up to the number for MaxSpareServers.
MaxSpareServers = Total maximum processes allowed.
MaxClients = The sessions/users consuming the processes. The ServerLimit is the maximum MaxClients allowed on the server. I tend to keep MaxClients and ServerLimit with the same value.
MaxRequestsPerChild = Max limit of the number of requests one child process can handle during its process life. Reducing this can give you small gain.
c. KeepAlive optimization.
If you use KeepAlive, it allows a client connection request to stay in use for 15 seconds by default. That means that even if the request is long done, the process waits anyway, rather than recycling. Using it can give a performance gain because multiple pages, images, JS files, CSS files, can be requested w/one connection rather than multiple.
Some people say to turn this off to free up connections and thereby memory. However, this seems to make a noticeable negative impact to wait time for users, since this site specifically is very heavy on images and files.
If the WordPress site(s) are small, you can turn it off and see a boost in performance, since less or no memory swap to disk occurs. If the WordPress site(s) are large, I'd say try it first enabled/on. If you know you don't need 15 seconds to get the site content, reduce the KeepAliveTimeout setting from the default 15 seconds to something less, and the maxinum requests held typically higher. Afterwards, try with KeepAlive Off to compare the two options.
KeepAlive On
KeepAliveTimeout 5
MaxKeepAliveRequests 200
d. Reduce the global timeout to something smaller for DOS or massive surges in site visits. The default is 2 minutes.
Timeout 45
2. Using FastCGI w/PHP to increase scalability.
Search the web for mod_php and FastCGI to see the pros and cons of using FastCGI.
Post Install Topics:
- Disabling or enabling comments.
- Adding a MailChimp subscribe option.
___________________________________________________________
Migration Notes:
Perform a backup of the whole site (folder) and the database before you begin.
Use phpMyAdmin to export the SQL of the app.
- Login to phpMyAdmin using the database admin login ID.
- Select the database name on the left. Click the SQL Export option at the top menu.
- - Custom (radio button)
- - Format SQL
- - Confirm database name
- - Under Options, enable Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT statement, enable CREATE TABLE options: IF NOT EXISTS and AUTO_INCREMENT, Enclose table and column names with backquotes.
- Save the sql file for import later.
Note:
If the database name is not going to be the same, on the new server, you can edit the SQL file just exported and change the name. The CREATE DATABASE line is near the top of the SQL command code.
-- Database: `db123abcd`
--
CREATE DATABASE IF NOT EXISTS `db123abcd` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `db123abcd`;
In the above example, if the new database name has to be dbmydomain, then change the CREATE DATABASE line and the USE line immediately beneath to:
CREATE DATABASE IF NOT EXISTS `dbmydomain` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `dbmydomain`;
Warning: Beware the WSOD (white-screen-of-death):
- PHP version not high enough. e.g. 5.6 instead of 7.1. This can happen during migration or upgrade when a new version of a plugin or the WordPress core requires 7.1 and the code was not written to "fail nicely".
- Folder missmatch. If you have to migrate a WordPress site, and don't have access to the old site to change the folder names right before moving the database, you can update the folder in the database directly via phpMyAdmin or by adding define tags to the wp-config.php file.
define('WP_HOME','http://www.myblogdomain.tld');
define('WP_SITEURL','http://www.myblogdomain.tld');
Copy of Files:
1. Download all files, including the hidden file .htaccess, from the current host. (We use FileZilla.)
2. Upload all the files to the new host.
3. Update the wp-config.php file to any new database connection info.
- Update the define('DB_NAME', 'db123abcd'); to define('DB_NAME', 'dbmydomain');
- Update the define('DB_USER', 'user123'); to define('DB_USER', 'dbdomainuser');
- Update the define('DB_PASSWORD', 'abc123'); to define('DB_USER', 'db123#CBA#1');
Migration Notes if Changing the Domain Name to/from a SubDomain
Subfolder to Main Folder:
If you moved the site from a subfolder to the main folder, then you need to perform multiple changes:
WordPress Admin Updates Before Migration:
1. http://myblogdomain.tld/subfolder/wp-admin/
2. Administration --> Settings --> General
3. Update the WordPress address (URL) and Site Address (URL), from myblogdomain.tld/subfolder to myblogdomain.tld.
4. Update the Permalinks to switch from /folder/page to the "Plain" (numerical) type. Note your original selection so you can put it back afterwards.
Administration --> Settings --> Permalinks
5. If running caching plugin, disable it.
6. Log out.
7. Clear your browser cache.
Migration of Files:
1. Copy all files from the subfolder to the root folder (usually /web or /public_html).
2. Delete all files in the subfolder but the .htaccess.
.htaccess
Add a rewrite to the subfolder if you want old search engine links to redirect up a directory. Update the code in the .htaccess hidden file to something like the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.myblogdomain\.tld$ [NC]
RewriteRule ^(.*)$ "http://www.myblogdomain.tld/$1" [R=301,L]
</IfModule>
Update Permalinks back to page format:
1. http://myblogdomain.tld/wp-admin/
2. Administration --> Settings --> Permalinks
3. Proof your site.
4. Re-enable your caching plugin, if applicable.
3. Log out.
_________________
SQL Migration Snippits
To update the Posts (pages) so the domain is updated from subdomain.myblogdomain.com to myblogdomain.com:
> UPDATE wp_posts SET post_content=(REPLACE (post_content, 'subdomain.myblogdomain.com','myblogdomain.com'));
Note:
This will NOT update content for image sliders and galleries used by plugin widgets. Those have to be updated separately.
Reset a WordPress User Password Using the WP_Users Table via phpMyAdmin:
1. Run the following command:
$ openssl passwd -1 'mynewpwd'
--> $1$gJ6IwgYT$CJrsU123YVWxnUqS0ptbeAMLW1
2. Login to phpMyAdmin using the database WP (db user) login, open the Database on left, select the wp_users table on left, locate the WordPress user in the wp_users table, replace the hash password column value for the user with the output above. Log out of myPHPAdmin.
3. Have the user login using the 'mynewpwd' password, and then change it.
Shell Scripts:
Script to Install Apache on CentOS:
#!/bin/bash
/usr/bin/yum install httpd -y
/sbin/chkconfig httpd on
/sbin/service httpd start
Note: The script above is for legacy init.d, not systemctl.
Script to Install MySQL-Server and MySQL-Client on CentOS:
#! /bin/bash
/usr/bin/yum install mysql-server mysql-client -y
/sbin/ckconfig mysqld on
/sbin/server mysqld start
Note: The script above is for legacy init.d, not systemctl.
Script to Install Current Distro Version of PHP on CentOS:
#! /bin/bash
/usr/bin/yum install php php-mysql mysql-client -y
<run second script after this one completes>
#! /bin/bash
/sbin/service httpd restart
Script to Create WordPress Database:
#! /bin/bash
/usr/bin/mysql -e "CREATE DATABASE wordpress;" --user=$dbuser --password=$dbpassword
/usr/bin/mysql -e "CREATE USER wpadmin;" --user=$dbuser --password=$dbpassword
/usr/bin/mysql -e "SET PASSWORD FOR 'wpadmin'@'%'=PASSWORD('$wpadmpwd');" --user=$dbuser --password=$dbpassword
/usr/bin/mysql -e "GRANT ALL PRIVILEGES ON wordpress.* TO 'wpadmin'@'%' IDENTIFIED BY '$wpadmpwd';" --user=$dbuser --password=$dbpassword
/usr/bin/mysql -e "FLUSH PRIVILEGES;" " --user=$dbuser --password=$dbpassword
Note: The above script assumes that 3 variables have been already set into the session.
Script to Download WordPress and Install Setup to /var/www/html/
#!/bin/bash
cd /tmp
/usr/bin/wget http://wordpress.org/Latest.tar.gz --output-document-/tmp/Latest.tar.gz
/bin/tar --xzvf /tmp/latest.tar.gz
mv /tmp/workpress/* /var/www/html/
Script to Configure WordPress:
#!/bin/bash
cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
/bin/sed -i "s/database_name_here/$WP_DB_NAME/g" /var/www/html/wp-config.php
/bin/sed -i "s/usernamename_here/$WP_DB_USER/g" /var/www/html/wp-config.php
/bin/sed -i "s/database_name_here/$WP_DB_PASSWORD/g" /var/www/html/wp-config.php
/bin/sed -i "s/locahost/$WP_DB_HOST/g" /var/www/html/wp-config.php
Max File Size Limits for Uploads:
Override for site --> Sites tab --> Add Site button.
- Select Client (created above or already existing).
- Enter Domain (e.g. mindatering.com).
- Switch PHP to PHP-FPM.
- Switch to Options tab and add the following to the Available PHP Directive Snippets:
post_max_size = 48M
upload_max_filesize = 24M
- Save.
Update globally:
$ sudo vi /etc/php/<php version>/pfm/php.ini
and
$ sudo vi/etc/php/<php version>/cgi/php.ini
previous page
|