225 lines
13 KiB
Markdown
225 lines
13 KiB
Markdown
---
|
||
slug: Easy Installation Guide Building Your Website with LAMP Stack on Debian 8
|
||
title: Easy Installation Guide Building Your Website with LAMP Stack on Debian 8
|
||
authors: [slorber, yangshun]
|
||
tags: [hola, docusaurus]
|
||
---
|
||
|
||
<!-- truncate -->
|
||
|
||
import CodeBlock from '@site/src/components/CodeBloack'
|
||
import debian from '@site/static/img/debian.png';
|
||
import php from '@site/static/img/php5.6.9.png';
|
||
|
||
<div className="head">Introduction</div>
|
||
|
||
<div className="text">The LAMP stack is like a super toolbox for building websites and apps. It's made up of Linux (the operating system), Apache (the web server), MySQL (a database), and PHP (a scripting language). When you put all these tools together, your computer becomes a superhero that can host cool and dynamic websites.</div><br/>
|
||
|
||
<div className="text">In this guide, we'll help you set up the LAMP stack on a Debian 8 server. Let's get started!</div><br/>
|
||
|
||
<div className="head">Debian 8 Setup Guide</div>
|
||
|
||
<div className="text">Before we start, make sure you have a Debian 8 server and a special user account that can do important things (we call it 'sudo-enabled'). If you haven't set this up yet, no worries! Just check out our simple guide at the beginning.</div><br/>
|
||
|
||
<div className="text">Also, it's like putting a protective shield around your server by creating a basic firewall. We'll show you how to do that in an easy step-by-step tutorial. You can find it in our guide for setting up Ubuntu and Debian, and it's really simple to follow!</div><br/>
|
||
|
||
|
||
<div className="head">Step 1 — Getting the Latest Updates</div>
|
||
|
||
<div className="text">Before adding any new programs, let's make sure your system is all caught up. To do that, type:</div>
|
||
|
||
<CodeBlock code={`sudo apt-get update`} /><br/>
|
||
|
||
<div className="text">This command checks if there are any newer versions of the software on your computer. It's like looking for updates to make sure you have the latest and greatest stuff from the place where your computer gets its software.</div><br/>
|
||
|
||
<div className="text">If your server is important for work or projects, be careful when updating. Check each update to make sure it's really needed for your computer. In our example, we installed everything just for this tutorial.Once you're sure the updates are necessary, go ahead and update your server using the command below:</div><br/>
|
||
|
||
<div className="text">If you decide the updates are important for your computer, go ahead and update your server. Just type in the following command:</div>
|
||
|
||
<CodeBlock code={`sudo apt-get dist-upgrade`} /><br/>
|
||
|
||
<div className="text">This process might take a bit, depending on your computer's setup and internet speed. If it's a new server, it should be quick, just a few seconds.<br/><br/>
|
||
Now your computer is all updated and ready for the next step – installing the Apache web server to handle your internet connections. Let's get started!</div>
|
||
|
||
<div className="head">Step 2 — Putting Apache and updating the firewall in place</div>
|
||
|
||
<div className="text">Now, let's move on to the next step of setting up our LAMP stack: installing the Apache web server. Apache is a popular and trusted web server that helps your computer show web pages. To install Apache, just type this command:</div>
|
||
|
||
<CodeBlock code={`sudo apt-get install apache2 apache2-doc`} /><br/>
|
||
<div className="text">This will install the basic Apache web server along with its documentation. It might take a little bit as it sets everything up. Once it's finished, apt-get will let you know, and that's it!</div><br/>
|
||
|
||
<div className="text">Now, if you've set up a firewall using UFW like we showed you before, you need to make sure it allows traffic for web browsing.</div><br/>
|
||
|
||
<div className="text">On Debian 8, UFW comes with pre-made settings for apps, making it easy to adjust your firewall. To see all the app profiles available, just run this command:</div>
|
||
|
||
<CodeBlock code={`sudo ufw app list`} /><br/>
|
||
|
||
<div className="text">These WWW profiles help control the ports used by web servers:</div>
|
||
|
||
<CodeBlock code={`Output
|
||
Available applications:
|
||
. . .
|
||
WWW
|
||
WWW Cache
|
||
WWW Full
|
||
WWW Secure
|
||
. . .
|
||
`} /><br/>
|
||
|
||
<div className="text">If you look at the WWW Full profile, it's like a set of instructions that says it allows traffic to go through on ports 80 and 443:</div>
|
||
|
||
<CodeBlock code={`sudo ufw app info "WWW Full"`} /><br/>
|
||
|
||
<CodeBlock code={`Output
|
||
Profile: WWW Full
|
||
Title: Web Server (HTTP,HTTPS)
|
||
Description: Web Server (HTTP,HTTPS)
|
||
|
||
Ports:
|
||
80,443/tcp
|
||
`} /><br/>
|
||
|
||
|
||
<div className="text">Let data come into your computer for web browsing. This profile lets you allow incoming traffic for both regular web (HTTP) and secure web (HTTPS) connections.</div>
|
||
|
||
<CodeBlock code={`sudo ufw allow in “WWW Full”`} /><br/>
|
||
|
||
<div className="text">Now that we've given permission for internet traffic through our security wall, let's check if our web server is working by making sure it can show a simple web page. First, find the address of your server. To do this, type the following command in the terminal you're using to connect to your server:</div>
|
||
|
||
<CodeBlock code={`sudo ifconfig eth0`} /><br/>
|
||
|
||
<div className="text">Look at your screen, and you'll see some lines of information. We're interested in finding your server's address, which is like its home on the internet. Look for a number that has four parts separated by dots (like xxx.xxx.xxx.xxx). It usually comes after the words "inet addr:" in the output. That's your server's IP address!</div>
|
||
|
||
<CodeBlock code={`Output
|
||
inet addr:111.111.111.111
|
||
`} /><br/>
|
||
|
||
<div className="text">Remember the number you found (the IP address)? Now, open your web browser, like the one you use to visit websites and type that number into the address bar at the top, just like you do when you visit any other website. Press Enter, and let's see if your server responds!</div>
|
||
|
||
<CodeBlock code={`http://111.111.111.111`} /><br/>
|
||
|
||
<div className="text">Once you're finished, you'll see the basic Apache 2 web page, like this:</div>
|
||
|
||
<img src={debian} alt="Debain" />
|
||
|
||
<div className="text">Now that Apache is installed on your server, you can put your website's content in the /var/www/html folder. If you want to make more than one website, you can learn how with virtual hosts in this guide.</div><br/>
|
||
|
||
<div className="text">For more help and tips on keeping your Apache server secure, check out Debian’s Apache information.</div><br/>
|
||
|
||
<div className="text">With your web server set up, you're ready to create a spot for your website's data. You can do this using MySQL</div><br/>
|
||
|
||
|
||
<div clssName="head">Step 3: Configuring MySQL and securing it</div>
|
||
|
||
<div className="text">Now, let's talk about MySQL. This is like a digital filing cabinet for your website. It helps store and organize all the information your site needs to run smoothly. Lots of popular software, like WordPress and Joomla, rely on MySQL to work.</div><br/>
|
||
|
||
<div className="text">To get MySQL installed and ready to go with PHP support, just follow these steps:</div><br/>
|
||
|
||
<CodeBlock code={`sudo apt-get install mysql-server php5-mysql`} /><br/>
|
||
|
||
<div className="text">This will set up MySQL and install everything else it needs. During the installation, you'll be asked to create a new password for the main MySQL user, called "root." Just choose a strong password and remember it!</div>
|
||
|
||
|
||
|
||
|
||
<!-- <need to add the image> -->
|
||
|
||
|
||
<div className="text">After setting up MySQL, remember that "root" is the special username used for important tasks, like managing your database. Choose a strong password for it, with a mix of letters and numbers.</div><br/>
|
||
|
||
<div className="text">Once you've done this, your MySQL installation is complete.</div><br/>
|
||
|
||
<div className="text">To make sure your database server stays safe, you'll need to run one more script. Just follow these steps:</div>
|
||
|
||
<CodeBlock code={`sudo mysql_secure_installation`} /><br/>
|
||
|
||
<div className="text">Now, the script will ask you some questions. When it asks, type in the password you set for the root MySQL account. Then, the system will ask you:</div>
|
||
|
||
<CodeBlock code={`Interactive
|
||
Change the root password? [Y/n] n
|
||
`} /><br/>
|
||
|
||
<div className="text">Since you've already set the password for the root MySQL account during installation, you can just say "no" when it asks. After that, the script will then ask:</div>
|
||
|
||
<CodeBlock code={`Interactive
|
||
Remove anonymous users? [Y/n] y
|
||
`} /><br/>
|
||
|
||
<div className="text">Choose "yes" to remove the anonymous users option for safety.</div><br/>
|
||
|
||
<div className="text">Next, you'll be asked whether to allow or disallow remote logins for the root account. For safety reasons, it's best to disallow remote logins for root unless absolutely necessary for your setup</div> <br/>
|
||
|
||
<div className="text">Then, you'll be prompted to remove the test database and reload the privilege tables. Respond with "yes" to both of these. This will get rid of the test database and apply the security changes.</div><br/>
|
||
|
||
<div className="text">Once everything is done correctly, the script will confirm with:</div>
|
||
|
||
<CodeBlock code={`Output
|
||
All done! If you have completed all of the above steps, your MySQL installation should now be secure.
|
||
`} /><br/>
|
||
|
||
<div className="text">Let's make sure our new MySQL server is up and running. Just type in this command:</div>
|
||
|
||
<CodeBlock code={`mysql -u root -p`} /><br/>
|
||
|
||
<div claasName="text">Now, enter the password you chose for MySQL during the installation process. Remember, this is different from the main root account used for server administration. Once you're in, just type the following to check the server status, version information, and more:</div>
|
||
|
||
<CodeBlock code={`status`} /><br/>
|
||
|
||
<div className="text">This is a great way to confirm that MySQL is installed and ready for more setup. Once you're done checking the information, simply exit the application by typing:</div>
|
||
|
||
<CodeBlock code={`exit`} /><br/>
|
||
|
||
<div className="text">Once you've made sure that MySQL is up and running, the next thing to do is install PHP. This will allow you to run scripts and handle code on your server</div><br/>
|
||
|
||
<div className="head">Step 4: Adding PHP Support</div>
|
||
|
||
<div className="text">Now, let's install PHP. PHP stands for PHP: Hypertext Preprocessor. It's a widely used scripting language that's crucial for creating dynamic web content, which many developers rely on.</div><br/>
|
||
|
||
<div className="text">To install PHP, just follow these steps:</div><br/>
|
||
|
||
<CodeBlock code={`sudo apt-get install php5-common libapache2-mod-php5 php5-cli`} /><br/>
|
||
|
||
<div className="text">Once you've agreed to the installation, PHP will be added to your server. You'll notice several packages being installed, not just PHP. No need to worry, though. Your system is simply making sure PHP works smoothly with your Apache2 setup and other programs.</div><br/>
|
||
|
||
<div className="text">To apply all the changes from the PHP installation, it's important to restart Apache on your server. Just follow these steps:</div>
|
||
|
||
<CodeBlock code={`sudo service apache2 restart`} /><br/>
|
||
|
||
<div className="text">Now, let’s check if the PHP software is working properly after installation. Go to the folder where your website's files are stored:</div>
|
||
|
||
<CodeBlock code={`cd /var/www/html`} /><br/>
|
||
|
||
<div className="text">Once you're in the public web directory, open a text editor from your computer. Create a new file named info.php using the following steps:</div>
|
||
|
||
<CodeBlock code={`sudo nano info.php`} /><br/>
|
||
|
||
<div className="text">This command will open a simple text editor called nano and create a new blank file with the name "info.php." In this file, you'll type some code to display information about your PHP configuration on a web page. Here's how to do it:</div>
|
||
|
||
<CodeBlock code={`<?php phpinfo(); ?>`} /><br/>
|
||
|
||
<div className="text">To save your changes and exit the file, press CTRL-X, then press Y to confirm saving, and finally press ENTER to confirm the file name.</div><br/>
|
||
|
||
<div className="text">Now, to see the configuration information, open your web browser and type in the following URL, but make sure to replace the highlighted part with your server’s IP address:</div>
|
||
|
||
<CodeBlock code={`http://111.111.111.111/info.php`} /><br/>
|
||
|
||
<div className="text">If you've followed the steps correctly, you'll see a page displaying basic PHP information, similar to the one below:</div>
|
||
|
||
|
||
<img src={php} alt="php5.9" /><br/>
|
||
|
||
<div className="text">When you're finished checking the test PHP page, it's important to remove it for security reasons. To do that, just run this command:</div>
|
||
|
||
<CodeBlock code={`sudo rm -i /var/www/html/info.php`} /><br/>
|
||
|
||
<div className="text">The system will ask if you want to delete the test file you created. Say "yes" to remove it. Once that's done, you've finished installing PHP!</div><br/>
|
||
|
||
|
||
<div className="con">Conclusions:</div>
|
||
|
||
<div className="text">Congratulations! You've successfully set up the basic LAMP stack on your server, which means you're ready to start building various websites and web applications. But that's just the beginning! There are plenty of ways to customize and expand your server's capabilities. If you want to learn how to keep your Linux server secure, check out "An Introduction to Securing Your Linux VPS."</div>
|
||
|
||
<div className="text">And if you're interested in hosting multiple websites on your server, follow the Apache virtual hosts tutorial.</div><br/>
|
||
|
||
<div className="text"><strong>Ready to take your server to the next level? Let's dive in and explore!</strong></div>
|