{"id":378,"date":"2019-05-10T19:26:04","date_gmt":"2019-05-10T19:26:04","guid":{"rendered":"https:\/\/unsrewiki.1sys1.com\/?p=378"},"modified":"2019-05-22T22:00:52","modified_gmt":"2019-05-22T22:00:52","slug":"building-and-scaling-a-website-part-1","status":"publish","type":"post","link":"https:\/\/server-help.org\/index.php\/2019\/05\/10\/building-and-scaling-a-website-part-1\/","title":{"rendered":"Building and Scaling a Website &#8211; Part 1"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">The Basics<\/h2>\n\n\n\n<p>In Part 1 of this guide we will show you how to increase your website performance using the most basic and typical server setup.<\/p>\n\n\n\n<p>This guide assumes that you have a single Cloud Server running CentOS 7 where you plan on hosting a single WordPress site that you will scale in the future by adding additional CPU\/RAM. More advanced options for scaling and redundancy will come in future guides.<\/p>\n\n\n\n<p>At the end of Part 1 you will have a new WordPress Website running Apache, PHP 7.3, MariaDB 10.2, and secured with a Let&#8217;s Encrypt SSL.<\/p>\n\n\n\n<p>1). yum update<\/p>\n\n\n\n<p>2). vi \/etc\/yum.repos.d\/MariaDB.repo<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[mariadb]\nname = MariaDB\nbaseurl = http:\/\/yum.mariadb.org\/10.2\/centos7-amd64\ngpgkey=https:\/\/yum.mariadb.org\/RPM-GPG-KEY-MariaDB\ngpgcheck=1 <\/code><\/pre>\n\n\n\n<p>3). yum install MariaDB-client MariaDB-server <\/p>\n\n\n\n<p>4).  service mariadb start<\/p>\n\n\n\n<p>5).  mysql_secure_installation <\/p>\n\n\n\n<p>6).  yum -y install httpd<\/p>\n\n\n\n<p>7). systemctl enable httpd<\/p>\n\n\n\n<p>8). systemctl start httpd<\/p>\n\n\n\n<p>9). yum install epel-release yum-utils<\/p>\n\n\n\n<p>10). yum install http:\/\/rpms.remirepo.net\/enterprise\/remi-release-7.rpm<\/p>\n\n\n\n<p>11). yum-config-manager &#8211;enable remi-php73<\/p>\n\n\n\n<p>12). yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuration<\/h2>\n\n\n\n<p>You now have a CentOS 7 server configured with Apache 2.4, MariaDB 10.2, and PHP 7.3. We will now get a WordPress site up and running and secure it with an SSL using Let&#8217;s Encrypt.<\/p>\n\n\n\n<p>1). mkdir \/var\/www\/mywebsite.com<\/p>\n\n\n\n<p>2). vi \/etc\/httpd\/conf.d\/mywebsite.conf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80>\n    ServerName mywebsite.com\n    ServerAlias www.mywebsite.com\n    DocumentRoot \"\/var\/www\/mywebsite.com\"\n&lt;\/VirtualHost><\/code><\/pre>\n\n\n\n<p>3). systemctl restart httpd<\/p>\n\n\n\n<p>4). mkdir \/etc\/certbot<\/p>\n\n\n\n<p>5). yum install git<\/p>\n\n\n\n<p>6). cd \/etc\/certbot<\/p>\n\n\n\n<p>7). git clone https:\/\/github.com\/certbot\/certbot<\/p>\n\n\n\n<p>8). cd certbot<\/p>\n\n\n\n<p>9). .\/certbot-auto certonly &#8211;webroot -w \/var\/www\/mywebsite.com -d mywebsite.com<\/p>\n\n\n\n<p>10).  vi \/etc\/httpd\/conf.d\/mywebsite.conf <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80>\n    ServerName mywebsite.com\n    ServerAlias www.mywebsite.com\n    DocumentRoot \"\/var\/www\/mywebsite.com\"\n&lt;\/VirtualHost>\n&lt;VirtualHost *:443>\n    ServerName mywebsite.com\n    ServerAlias www.mywebsite.com\n    DocumentRoot \"\/var\/www\/mywebsite.com\"\n    SSLEngine on\n    SSLCertificateFile \"\/etc\/letsencrypt\/live\/mywebsite.com\/cert.pem\"\n    SSLCACertificateFile \"\/etc\/letsencrypt\/live\/mywebsite.com\/chain.pem\"\n    SSLCertificateKeyFile \"\/etc\/letsencrypt\/live\/mywebsite.com\/privkey.pem\"\n&lt;\/VirtualHost><\/code><\/pre>\n\n\n\n<p>11). systemctl restart httpd <\/p>\n\n\n\n<p>12). crontab -e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0 23 * * * \/etc\/certbot\/certbot\/certbot-auto renew --register-unsafely-without-email --post-hook \"apachectl -k restart\"<\/code><\/pre>\n\n\n\n<p>13). mysql -uroot -p<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Create DATABASE wp;\nCREATE USER 'wordpress'@'%' IDENTIFIED BY 'Xsfd2V^dg1';\nGRANT ALL PRIVILEGES ON *.* TO wordpress@'%' IDENTIFIED BY 'Xsfd2V^dg1' WITH GRANT OPTION;<\/code><\/pre>\n\n\n\n<p>14). cd \/var\/www\/mywebsite.com<\/p>\n\n\n\n<p>15). wget https:\/\/wordpress.org\/latest.zip<\/p>\n\n\n\n<p>16). yum install bsdtar<\/p>\n\n\n\n<p>17). bsdtar &#8211;strip-components=1 -xvf latest.zip<\/p>\n\n\n\n<p>18). chown -R apache:root \/var\/www\/mywebsite.com\/<\/p>\n\n\n\n<p>19). Go to mywebsite.com<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"567\" src=\"https:\/\/unsrewiki.1sys1.com\/wp-content\/uploads\/2019\/05\/1-1-1024x567.png\" alt=\"\" class=\"wp-image-390\" srcset=\"https:\/\/server-help.org\/wp-content\/uploads\/2019\/05\/1-1-1024x567.png 1024w, https:\/\/server-help.org\/wp-content\/uploads\/2019\/05\/1-1-300x166.png 300w, https:\/\/server-help.org\/wp-content\/uploads\/2019\/05\/1-1-768x425.png 768w, https:\/\/server-help.org\/wp-content\/uploads\/2019\/05\/1-1.png 1168w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>20). Complete the WordPress setup using the Database information used in Step 13.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Force HTTPS<\/h2>\n\n\n\n<p>1). Check to make sure HTTPS is working on your site, then perform the following: vi \/etc\/httpd\/conf\/httpd.conf<\/p>\n\n\n\n<p>In the section for Directory &#8220;\/var\/www\/html&#8221; edit the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AllowOverride All<\/code><\/pre>\n\n\n\n<p>2). vi \/etc\/httpd\/conf.d\/mywebsite.conf  <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Directory \"\/var\/www\/mywebsite.com\">\nRewriteEngine On\nRewriteCond %{HTTPS} off [OR]\nRewriteCond %{HTTP_HOST} ^www\\. [NC]\nRewriteCond %{HTTP_HOST} ^(?:www\\.)?(.+)$ [NC]\nRewriteRule ^(.*)$ https:\/\/mywebsite.com\/$1 [R=301,L]\n&lt;\/Directory>\n&lt;VirtualHost *:80>\n    ServerName mywebsite.com\n    ServerAlias www.mywebsite.com\n    DocumentRoot \"\/var\/www\/mywebsite.com\"\n&lt;\/VirtualHost>\n&lt;VirtualHost *:443>\n    ServerName mywebsite.com\n    ServerAlias www.mywebsite.com\n    DocumentRoot \"\/var\/www\/mywebsite.com\"\n    SSLEngine on\n    SSLCertificateFile \"\/etc\/letsencrypt\/live\/mywebsite.com\/fullchain.pem\"\n    SSLCertificateKeyFile \"\/etc\/letsencrypt\/live\/mywebsite.com\/privkey.pem\"\n&lt;\/VirtualHost><\/code><\/pre>\n\n\n\n<p>3). vi \/var\/www\/mywebsite.com\/.htaccess<\/p>\n\n\n\n<p>Add this to the top of your .htacess file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On\nRewriteCond %{HTTPS} off [OR]\nRewriteCond %{HTTP_HOST} ^www\\. [NC]\nRewriteCond %{HTTP_HOST} ^(?:www\\.)?(.+)$ [NC]\nRewriteRule ^(.*)$ https:\/\/mywebsite.com\/$1 [R=301,L]<\/code><\/pre>\n\n\n\n<p>4). apachectl -k restart<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SSL Security<\/h2>\n\n\n\n<p>1). Test your website&#8217;s SSL using: https:\/\/www.ssllabs.com\/ssltest\/<\/p>\n\n\n\n<p>It should look like the following.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/unsrewiki.1sys1.com\/wp-content\/uploads\/2019\/05\/1-2.png\" alt=\"\" class=\"wp-image-439\" width=\"746\" height=\"379\" srcset=\"https:\/\/server-help.org\/wp-content\/uploads\/2019\/05\/1-2.png 1013w, https:\/\/server-help.org\/wp-content\/uploads\/2019\/05\/1-2-300x153.png 300w, https:\/\/server-help.org\/wp-content\/uploads\/2019\/05\/1-2-768x391.png 768w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/figure>\n\n\n\n<p>2). We will now correct these issues. Typically this will be done in \/etc\/httpd\/conf.d\/ssl.conf however if these settings don&#8217;t have any effect add them into \/etc\/httpd\/conf\/httpd.conf instead:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SSLProtocol all -SSLv2 -SSLv3\nSSLHonorCipherOrder on\nSSLCipherSuite \"EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4\"<\/code><\/pre>\n\n\n\n<p>3). apachectl -k restart<\/p>\n\n\n\n<p>4). Retest your site and it should now look like the following.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/unsrewiki.1sys1.com\/wp-content\/uploads\/2019\/05\/2-2.png\" alt=\"\" class=\"wp-image-440\" width=\"756\" height=\"291\" srcset=\"https:\/\/server-help.org\/wp-content\/uploads\/2019\/05\/2-2.png 1004w, https:\/\/server-help.org\/wp-content\/uploads\/2019\/05\/2-2-300x116.png 300w, https:\/\/server-help.org\/wp-content\/uploads\/2019\/05\/2-2-768x296.png 768w\" sizes=\"(max-width: 756px) 100vw, 756px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Site performance improvements<\/h2>\n\n\n\n<p>These actions will further speed up the site by enabling compression and static asset caching.<\/p>\n\n\n\n<p>1). vi  \/etc\/httpd\/conf.d\/mod_deflate.conf <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;filesMatch \"\\.(js|html|css)$\">\n    SetOutputFilter DEFLATE\n&lt;\/filesMatch><\/code><\/pre>\n\n\n\n<p>2). vi \/etc\/httpd\/conf.d\/expires.conf <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ExpiresActive on\nExpiresDefault \"access plus 14 days\"\nExpiresByType image\/jpg \"access plus 1 month\"\nExpiresByType image\/gif \"access plus 1 month\"\nExpiresByType image\/jpeg \"access plus 1 month\"\nExpiresByType image\/png \"access plus 1 month\"\nExpiresByType text\/css \"access plus 1 month\"\nExpiresByType application\/pdf \"access plus 1 month\"\nExpiresByType text\/javascript \"access plus 1 month\"\nExpiresByType text\/x-javascript \"access plus 1 month\"\nExpiresByType application\/javascript \"access plus 1 month\"\nExpiresByType application\/x-shockwave-flash \"access plus 1 month\"\nExpiresByType text\/css \"now plus 1 month\"\nExpiresByType image\/ico \"access plus 1 month\"\nExpiresByType image\/x-icon \"access plus 1 month\"\nExpiresByType text\/html \"access plus 1 days\"\n<\/code><\/pre>\n\n\n\n<p>3). apachectl -k restart <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion of Part 1<\/h2>\n\n\n\n<p>In Part 1 we have got a brand new WordPress site setup and configured on a single Cloud Server. It is light, lean, and should function well.<\/p>\n\n\n\n<p>For further performance improvements and redundancy you can now setup with a 3rd-party CDN such as Cloudflare and\/or increase your server&#8217;s available CPU\/RAM resources as needed.<\/p>\n\n\n\n<p>You may also want to configure a cache\/minify plugin for WordPress such as W3TotalCache.<\/p>\n\n\n\n<p>Also be sure to test the site metrics with tools such as webpagetest.org to see if there are any additional minor improvements you can perform such as compressing images.<\/p>\n\n\n\n<p>In Part 2 we will improve this setup by including multiple servers for additional performance, scalability, and redundancy in order to handle large amount of traffic.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Basics In Part 1 of this guide we will show you how to increase your website performance using the most basic and typical server setup. This guide assumes that you have a single Cloud Server running CentOS 7 where you plan on hosting a single WordPress site that you will scale in the future&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,4,1],"tags":[],"_links":{"self":[{"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/posts\/378"}],"collection":[{"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/comments?post=378"}],"version-history":[{"count":24,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/posts\/378\/revisions"}],"predecessor-version":[{"id":527,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/posts\/378\/revisions\/527"}],"wp:attachment":[{"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/media?parent=378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/categories?post=378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/tags?post=378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}