{"id":72,"date":"2021-08-08T18:13:59","date_gmt":"2021-08-08T18:13:59","guid":{"rendered":"https:\/\/jasonisenhart.com\/?p=72"},"modified":"2021-08-08T18:19:15","modified_gmt":"2021-08-08T18:19:15","slug":"lamp-stack-tutorial","status":"publish","type":"post","link":"https:\/\/jasonisenhart.com\/index.php\/2021\/08\/08\/lamp-stack-tutorial\/","title":{"rendered":"Lamp Stack Tutorial"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"258\" src=\"https:\/\/jasonisenhart.com\/wp-content\/uploads\/2021\/08\/LAMP-Image.jpeg\" alt=\"\" class=\"wp-image-73\" srcset=\"https:\/\/jasonisenhart.com\/wp-content\/uploads\/2021\/08\/LAMP-Image.jpeg 693w, https:\/\/jasonisenhart.com\/wp-content\/uploads\/2021\/08\/LAMP-Image-300x112.jpeg 300w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/figure><\/div>\n\n\n\n<p>LAMP stack is a great way to get started with your first website using WordPress or other application that uses SQL, Apache, and PHP. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 1 &#8211; Apache Install &amp; Firewall Rules<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install apache2<\/code><\/pre>\n\n\n\n<p>The above command refreshes the repositories on Linux.<\/p>\n\n\n\n<p>Now let&#8217;s make sure your ufw firewall is allowing traffic. You have 3 options Apache, Apache Full, and Apache Secure<br>Apache = Port 80<br>Apache Full = Port 80, 443<br>Apache Secure = Port 443<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw app list<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>## <em>Output<\/em>\nAvailable applications:\n  Apache\n  Apache Full\n  Apache Secure\n  OpenSSH<\/code><\/pre>\n\n\n\n<p>Now let&#8217;s use Apache Full since we will use Lets Encrypt to secure our website behind HTTPS. Remember this is Linux so it&#8217;s case sensitive.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow \"Apache Full\"<\/code><\/pre>\n\n\n\n<p>Now browse to either IP or domain and you should see the Apache2 default page. To find your public IP address you can go to www.whatismyipaddress.com or through Linux terminal type.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dig +short myip.opendns.com @resolver1.opendns.com<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 2 &#8211; MYSQL<\/strong><\/h2>\n\n\n\n<p>Let&#8217;s get started with another repository update and then install MySQL<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install mysql-server<\/code><\/pre>\n\n\n\n<p>Now let&#8217;s configure MySQL<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysql_secure_installation<\/code><\/pre>\n\n\n\n<p>The installation will ask if you want to configure VALIDATE PASSWORD PLUGIN. This plugin requires certain criteria for passwords but oftentimes this just causes issues in other areas. Just press enter to skip and make sure when creating passwords to document them and use strong passwords.<br><br>For the rest of the prompts just press Y to remove default users and database.<\/p>\n\n\n\n<p>Now let&#8217;s test to make sure MySQL is working properly<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysql<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>## <em>Output<\/em>\nWelcome to the MySQL monitor.  Commands end with ; or \\g.\nYour MySQL connection id is 1254\nServer version: 8.0.26-0ubuntu0.20.04.2 (Ubuntu)\n\nCopyright (c) 2000, 2021, Oracle and\/or its affiliates.\n\nOracle is a registered trademark of Oracle Corporation and\/or its\naffiliates. Other names may be trademarks of their respective\nowners.\n\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n\nmysql&gt;\n<\/code><\/pre>\n\n\n\n<p>If the above is what you see you can exit MySQL<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt; <strong>exit<\/strong><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 3 &#8211; PHP Install<\/strong><\/h2>\n\n\n\n<p>Setting up PHP can be daunting because there are so many different plugins used for many different applications. We will set up the basics.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install php libapache2-mod-php php-mysql<\/code><\/pre>\n\n\n\n<p>Now let&#8217;s restart apache2 and check its status.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart apache2\nsudo systemctl status apache2<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\u25cf apache2.service - The Apache HTTP Server\n     Loaded: loaded (\/lib\/systemd\/system\/apache2.service; enabled; vendor preset: enabled)\n     Active: active (running) since Sun 2021-08-08 05:59:29 UTC; 11h ago\n       Docs: https:\/\/httpd.apache.org\/docs\/2.4\/\n    Process: 22902 ExecStart=\/usr\/sbin\/apachectl start (code=exited, status=0\/SUCCESS)\n   Main PID: 22906 (apache2)\n      Tasks: 11 (limit: 9257)\n     CGroup: \/system.slice\/apache2.service\n             \u251c\u250022906 \/usr\/sbin\/apache2 -k start\n             \u251c\u250023059 \/usr\/sbin\/apache2 -k start\n             \u251c\u250023534 \/usr\/sbin\/apache2 -k start\n             \u251c\u250024779 \/usr\/sbin\/apache2 -k start\n             \u251c\u250024821 \/usr\/sbin\/apache2 -k start\n             \u251c\u250024886 \/usr\/sbin\/apache2 -k start\n             \u251c\u250025286 \/usr\/sbin\/apache2 -k start\n             \u251c\u250025373 \/usr\/sbin\/apache2 -k start\n             \u251c\u250025565 \/usr\/sbin\/apache2 -k start\n             \u251c\u250025590 \/usr\/sbin\/apache2 -k start\n             \u2514\u250025594 \/usr\/sbin\/apache2 -k start\n<\/code><\/pre>\n\n\n\n<p>If your screen looks similar to the above we can move forward.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 4 &#8211; Virtual Hosts in Apache<\/strong><\/h2>\n\n\n\n<p>Virtual hosts help direct your domain to the correct directory within Apache. For this tutorial, we will use the domain lampsetup.com<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir \/var\/www\/lampsetup<\/code><\/pre>\n\n\n\n<p>Now let&#8217;s change ownership from the webserver to you.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chown -R $USER:$USER \/var\/www\/lampsetup<\/code><\/pre>\n\n\n\n<p>Now permissions<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chmod -R 755 \/var\/www\/lampsetup<\/code><\/pre>\n\n\n\n<p>We should go ahead and create the index.html file to verify everything is working correctly.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/var\/www\/lampsetup\/index.html<\/code><\/pre>\n\n\n\n<p>Insert HTML<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;html&gt;\n    &lt;head&gt;\n        &lt;title&gt;LAMP SETUP!&lt;\/title&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n        Well we know APACHE IS WORKING!\n    &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p>Creating the sites-available will help point your domain to the correct directory<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/apache2\/sites-available\/lampsetup.conf<\/code><\/pre>\n\n\n\n<p>Copy the below code with your own information<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80&gt;\n    ServerAdmin webmaster@lampsetup.com\n    ServerName lampsetup.com\n    ServerAlias www.lampsetup.com\n    DocumentRoot \/var\/www\/lampsetup\n    ErrorLog ${APACHE_LOG_DIR}\/error.log\n    CustomLog ${APACHE_LOG_DIR}\/access.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n\n\n\n<p>We need to enable your configuration and disabled any configuration currently defaulted.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo a2ensite lampsetup.conf\nsudo a2dissite 000-default.conf<\/code><\/pre>\n\n\n\n<p>Let&#8217;s restart Apache and then test PHP<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart apache2\nsudo apache2ctl configtest<\/code><\/pre>\n\n\n\n<p>Config test output might have a localhost error but that&#8217;s fine and can be ignored. What we want to see is Syntax OK<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>Output<\/em>\nAH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message\nSyntax OK\n<\/code><\/pre>\n\n\n\n<p>Let&#8217;s remove that default index file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo rm \/var\/www\/lampsetup\/index.html<\/code><\/pre>\n\n\n\n<p>Let&#8217;s test PHP!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/var\/www\/lampsetup\/info.php<\/code><\/pre>\n\n\n\n<p>Paste the below code into the info.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nphpinfo();<\/code><\/pre>\n\n\n\n<p>Should see the PHP Version page with all of the configurations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 5 &#8211; Lets Encrypt<\/strong><\/h2>\n\n\n\n<p>Now let&#8217;s secure our website behind HTTPS.<\/p>\n\n\n\n<p>We need to install the certbot for apache<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install python3-certbot-apache<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 6 &#8211; SSL Cert Installation<\/strong><\/h2>\n\n\n\n<p>Let&#8217;s request the SSL Cert from Lets Encrypt<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo certbot --apache -d lampsetup.com -d www.lampsetup.com<\/code><\/pre>\n\n\n\n<p>Once you do this you will be asked if you want redirection or not. I prefer redirection if you always want users to use HTTPS. This choice is up to you.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>Output<\/em>\nPlease choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.\n-------------------------------------------------------------------------------\n1: No redirect - Make no further changes to the webserver configuration.\n2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for\nnew sites, or if you're confident your site works on HTTPS. You can undo this\nchange by editing your web server's configuration.\n-------------------------------------------------------------------------------\nSelect the appropriate number &#91;1-2] then &#91;enter] (press 'c' to cancel):<\/code><\/pre>\n\n\n\n<p>From here you will get confirmation that your certificate is installed. Certbot will auto-renew this certificate and email you if there are any problems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Thats it! <\/strong><\/h2>\n\n\n\n<p>Now you are ready to move on to installing WordPress or whatever other application\/web host you want to set up. Feel free to contact me if you have any questions and I will try to answer them.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LAMP stack is a great way to get started with your first website using WordPress or other application that uses SQL, Apache,\u2026<\/p>\n","protected":false},"author":1,"featured_media":78,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[6,5,7,8],"class_list":["post-72","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-it-how-to","tag-apache","tag-lamp","tag-mysql","tag-php"],"_links":{"self":[{"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/posts\/72","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/comments?post=72"}],"version-history":[{"count":7,"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/posts\/72\/revisions"}],"predecessor-version":[{"id":81,"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/posts\/72\/revisions\/81"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/media\/78"}],"wp:attachment":[{"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/media?parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/categories?post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/tags?post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}