{"id":1238,"date":"2022-11-22T06:49:06","date_gmt":"2022-11-22T06:49:06","guid":{"rendered":"https:\/\/zhuoyao.net\/?p=1238"},"modified":"2022-11-22T06:52:24","modified_gmt":"2022-11-22T06:52:24","slug":"install-wordpress-with-apache-and-lets-encrypt-ssl-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2022\/11\/22\/install-wordpress-with-apache-and-lets-encrypt-ssl-on-ubuntu-22-04\/","title":{"rendered":"Install WordPress with Apache and Let\u2019s Encrypt SSL on Ubuntu 22.04"},"content":{"rendered":"\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-itzgeek wp-block-embed-itzgeek\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"IeGi8UCBKX\"><a href=\"https:\/\/www.itzgeek.com\/how-tos\/linux\/ubuntu-how-tos\/install-wordpress-with-apache-and-lets-encrypt-ssl-on-ubuntu-22-04.html\">Install WordPress with Apache and Let&#8217;s Encrypt SSL on Ubuntu 22.04<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Install WordPress with Apache and Let&#8217;s Encrypt SSL on Ubuntu 22.04&#8221; &#8212; ITzGeek\" src=\"https:\/\/www.itzgeek.com\/how-tos\/linux\/ubuntu-how-tos\/install-wordpress-with-apache-and-lets-encrypt-ssl-on-ubuntu-22-04.html\/embed#?secret=kvkiXIKjfH#?secret=IeGi8UCBKX\" data-secret=\"IeGi8UCBKX\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><a href=\"https:\/\/wordpress.org\/\">WordPress<\/a> is one of the most popular content management systems on the internet. It is open-source CMS and works well with almost any web hosting service, making it one of the easiest to install and use for building any type of website.<\/p>\n\n\n\n<p>We recommend installing WordPress on VPS (virtual private server) over regular web hosting for traffic-intensive websites.<\/p>\n\n\n\n<p>Here, we will see how to install <a href=\"https:\/\/www.itzgeek.com\/tag\/wordpress\">WordPress<\/a> with <a href=\"https:\/\/www.itzgeek.com\/tag\/apache\">Apache<\/a> on <a href=\"https:\/\/www.itzgeek.com\/tag\/ubuntu-22.04\">Ubuntu 22.04<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Set up LAMP Stack<\/h2>\n\n\n\n<p>Follow the below link to install the LAMP stack on your Ubuntu 22.04 system<\/p>\n\n\n\n<p><a href=\"https:\/\/www.itzgeek.com\/how-tos\/linux\/ubuntu-how-tos\/install-lamp-stack-apache-mariadb-php-on-ubuntu-22-04.html\" target=\"_blank\" rel=\"noreferrer noopener\">Install AMP (Apache, MariaDB, and PHP) on Ubuntu 22.04<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Set up PHP for WordPress<\/h2>\n\n\n\n<p>WordPress requires a few extensions for a WordPress installation. So, install them using the <code>apt<\/code> command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install -y php-curl php-xml php-common php-imagick php-json php-mbstring php-mysql php-zip php-bcmath php-gd<\/pre>\n\n\n\n<p>Additionally, you may need to change PHP values based on the requirement. You may start with the below values now and increase or decrease them later when required.<\/p>\n\n\n\n<p><strong>max_connection_time<\/strong> = <em>300<\/em><\/p>\n\n\n\n<p><strong>upload_max_filesize<\/strong> = <em>64M<\/em><\/p>\n\n\n\n<p><strong>post_max_size<\/strong> = <em>64M<\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo sed -i 's\/^max_execution_time \\= .*\/max_execution_time \\= 300\/g' \/etc\/php\/8.1\/apache2\/php.ini\n\nsudo sed -i 's\/^upload_max_filesize \\= .*\/upload_max_filesize \\= 64M\/g' \/etc\/php\/8.1\/apache2\/php.ini\n\nsudo sed -i 's\/^post_max_size \\= .*\/post_max_size \\= 64M\/g' \/etc\/php\/8.1\/apache2\/php.ini<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Setup Apache Virtual Host<\/h2>\n\n\n\n<p>We will start with creating an Apache virtual host for a WordPress installation. Typically virtual host files contain a domain name, port number, document root, log location, fast CGI, etc.<\/p>\n\n\n\n<p>Assume the following,<\/p>\n\n\n\n<p>Domain name: <strong>www.itzgeek.net<\/strong><br>Port No: <strong>80<\/strong><br>Document root: <strong>\/var\/www\/html\/www.itzgeek.net\/<\/strong><\/p>\n\n\n\n<p>First, create a virtual host configuration file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/apache2\/sites-available\/www.itzgeek.net.conf<\/pre>\n\n\n\n<p>Then, place the following virtual host information into the above configuration file. You will need to change <code>ServerName<\/code> and other values as per your requirement.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;VirtualHost *:80&gt;\n\n   ServerName <strong>itzgeek.net<\/strong>\n   ServerAlias <strong>www.itzgeek.net<\/strong>\n   ServerAdmin admin@itzgeek.net\n   DocumentRoot <strong>\/var\/www\/html\/www.itzgeek.net<\/strong>\n\n\n   ErrorLog ${APACHE_LOG_DIR}\/www.itzgeek.net_error.log\n   CustomLog ${APACHE_LOG_DIR}\/www.itzgeek.net_access.log combined\n\n\n   &lt;Directory <strong>\/var\/www\/html\/www.itzgeek.net<\/strong>&gt;\n      Options FollowSymlinks\n      AllowOverride All\n      Require all granted\n   &lt;\/Directory&gt;\n\n&lt;\/VirtualHost&gt;<\/pre>\n\n\n\n<p>Next, create a document root directory to place WordPress files.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo mkdir -p \/var\/www\/html\/www.itzgeek.net\/\n<\/pre>\n\n\n\n<p>Then, enable the virtual host and SSL, and rewrite modules.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo a2ensite www.itzgeek.net\n\nsudo a2enmod rewrite ssl\n<\/pre>\n\n\n\n<p>Finally, restart the Apache service.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl restart apache2<\/pre>\n\n\n\n<p>If you do not plan to set up an SSL certificate for WordPress, then proceed to <a href=\"https:\/\/www.itzgeek.com\/how-tos\/linux\/ubuntu-how-tos\/install-wordpress-with-apache-and-lets-encrypt-ssl-on-ubuntu-22-04.html#Install_WordPress_with_Apache_on_Ubuntu_2204\">install WordPress directly<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install Let\u2019s Encrypt SSL Certificate<\/h2>\n\n\n\n<p>Skip this SSL installation if you are installing WordPress on a local system i.e, a laptop or on a virtual machine.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create DNS Record<\/h3>\n\n\n\n<p>Visit your domain registrar\u2019s DNS management page and create an A and CNAME (if you want to use www subdomain) record for your domain. Typically you will have to make two records for your WordPress website.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Non-www Domain Name (Ex. itzgeek.net) &gt;&gt; <strong>A<\/strong> record point to your server IP<\/li>\n\n\n\n<li>www Domain Name (Ex. www.itzgeek.net) &gt;&gt; <strong>CNAME<\/strong> record point to itzgeek.net<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_538087\"><a href=\"https:\/\/www.itzgeek.com\/wp-content\/uploads\/2021\/10\/DNS-Records.png\"><img decoding=\"async\" src=\"https:\/\/www.itzgeek.com\/wp-content\/uploads\/2021\/10\/DNS-Records.png?ezimgfmt=rs:834x89\/rscb2\/ng:webp\/ngcb2\" alt=\"DNS Records\" class=\"wp-image-538087\"\/><\/a><figcaption class=\"wp-element-caption\">DNS Records<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Install Certbot client<\/h3>\n\n\n\n<p>The <a href=\"https:\/\/certbot.eff.org\/\">Certbot client<\/a>, which helps us generate and install the Let\u2019s Encrypt SSL certificate, is now available as a snap package for Ubuntu operating system. So, first, install snapd daemon on your system.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt update\n\nsudo apt install -y snapd<\/pre>\n\n\n\n<p>Then, update snapd to the latest version.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo snap install core &amp;&amp; sudo snap refresh core<\/pre>\n\n\n\n<p>Finally, install the Certbot client using the below command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo snap install --classic certbot\n\nsudo ln -s \/snap\/bin\/certbot \/usr\/bin\/certbot<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install SSL Certificate<\/h3>\n\n\n\n<p>Use the <code>certbot<\/code> command to generate and install the Let\u2019s Encrypt SSL certificate on the Apache webserver.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo certbot --apache<\/pre>\n\n\n\n<p>1. <strong>Enter email address<\/strong> to receive notification on urgent renewal and security notices<br>2. Type <strong>Y and press Enter<\/strong> to register with the ACME server<br>3. Type <strong>Y or N<\/strong> to receive emails about EFF news, campaigns, and newsletters.<br>4. Certbot will automatically detect the WordPress domain and ask you permission to <strong>activate HTTPS<\/strong> for your WordPress website. Type <strong>1 or appropriate numbers separated by a comma<\/strong> if you have multiple websites.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Which names would you like to activate HTTPS for?\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n1: itzgeek.net\n2: www.itzgeek.net\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nSelect the appropriate numbers separated by commas and\/or spaces, or leave input\nblank to select all options shown (Enter 'c' to cancel): <strong>1,2\n<\/strong><\/pre>\n\n\n\n<p>Wait for the SSL installation to complete.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Redirect non-www HTTP requests to www HTTPS with Apache<\/h3>\n\n\n\n<p>The Certbot client will place the required rules to redirect the traffic from HTTP to the HTTPS website.<\/p>\n\n\n\n<p>1. http:\/\/itzgeek.net &gt;&gt; https:\/\/itzgeek.net<\/p>\n\n\n\n<p>2. http:\/\/www.itzgeek.net &gt;&gt; https:\/\/www.itzgeek.net<\/p>\n\n\n\n<p>As you can see, the first domain is not reaching www HTTPS with rules placed by Certbot. So, you will have to add a rule manually to <a href=\"https:\/\/www.itzgeek.com\/how-tos\/linux\/debian\/how-to-install-lets-encrypt-ssl-certificate-in-apache-on-debian-11.html#Redirect_non-www_HTTP_requests_to_www_HTTPS_with_Apache\" target=\"_blank\" rel=\"noreferrer noopener\">redirect traffic from non-www HTTP to www HTTPS<\/a> domain if required, I.e., http:\/\/itzgeek.net &gt;&gt; https:\/\/www.itzgeek.net.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Auto-Renew SSL Certificate<\/h3>\n\n\n\n<p>The Certbot client comes with a systemd service that renews SSL certificates automatically. So, you will not have to renew the certificates manually.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install WordPress with Apache on Ubuntu 22.04<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Create WordPress Database<\/h3>\n\n\n\n<p>First, login into MariaDB\/MySQL database server.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo mysql -u root -p<\/pre>\n\n\n\n<p>Then, create the database for WordPress installation and the database user and password.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">CREATE DATABASE wpdatabase;\n\nCREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'wppassword';\n\nGRANT ALL PRIVILEGES ON wpdatabase.* TO 'wpuser'@'localhost';\n\nEXIT<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Download WordPress<\/h3>\n\n\n\n<p>First, <a href=\"https:\/\/wordpress.org\/download\/\">download the latest version of the WordPress<\/a> files using the <code>wget<\/code> command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">wget https:\/\/wordpress.org\/latest.tar.gz<\/pre>\n\n\n\n<p>Then, extract the downloaded file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">tar -zxvf latest.tar.gz<\/pre>\n\n\n\n<p>And then, move the files to your website document root directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo mv wordpress\/* \/var\/www\/html\/www.itzgeek.net\/<\/pre>\n\n\n\n<p>Next, update the ownership and a group of the WordPress directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo chown -R www-data:www-data \/var\/www\/html\/www.itzgeek.net\/<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install WordPress<\/h3>\n\n\n\n<p>Open your browser and visit your WordPress website domain to perform the WordPress installation.<\/p>\n\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/your-wordpress-website\n<\/div><\/figure>\n\n\n\n<p>1. Choose the <strong>Installation Language<\/strong> and click <strong>Continue<\/strong><\/p>\n\n\n\n<p>2. Click <strong>Let\u2019s go!<\/strong><\/p>\n\n\n\n<p>3. Enter the <strong>WordPress database details<\/strong> and then click <strong>Submit<\/strong><\/p>\n\n\n\n<p>4. Click <strong>Run the installation<\/strong><\/p>\n\n\n\n<p>5. Enter the <strong>WordPress website information<\/strong> and then click <strong>Install WordPress<\/strong><\/p>\n\n\n\n<p>6. Click <strong>Log In<\/strong> to access the WordPress admin backend to manage WordPress installation. Alternatively, you can access the WordPress backend by going to <strong>https:\/\/your-wordpress-website\/wp-admin<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Access WordPress Website<\/h2>\n\n\n\n<p>Now, you will be able to access the site with your domain name.<\/p>\n\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/your-wordpress-website\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>WordPress is one of the most popular content management systems on the internet. It is open-source CMS and works well with almost any web hosting&hellip; <\/p>\n","protected":false},"author":1,"featured_media":964,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-1238","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/1238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=1238"}],"version-history":[{"count":1,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/1238\/revisions"}],"predecessor-version":[{"id":1239,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/1238\/revisions\/1239"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media\/964"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=1238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=1238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=1238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}