tutorial-cloud/blog/2019-05-29-blog-11.md
2024-10-25 10:05:08 +05:30

121 lines
8.3 KiB
Markdown

---
slug: Building Your Web Server Installing Apache
title: Building Your Web Server Installing Apache, MySQL, PHP (LAMP) Stack on Ubuntu 12.04
authors: [slorber, yangshun]
tags: [hola, docusaurus]
---
<!-- truncate -->
import CodeBlock from '@site/src/components/CodeBloack';
<div className="head">What is LAMP?</div>
<div className="text">LAMP stack is a bundle of free software that helps set up web servers. The name stands for Linux, Apache, MySQL, and PHP. Since your virtual private server is already using Ubuntu (which is a type of Linux), you've got one part covered. Now, let's see how to install the rest.</div>
<div className="head">Getting Started</div>
<div className="text">To follow this tutorial, you'll need to have administrator access on your VPS. If you're unsure how to set this up, check out the "Initial Server Setup" guide for instructions on getting started.</div>
<div className="head">Setting Up Apache</div>
<div className="text">Apache is a popular, free software used to run many websites.</div><br/>
<div className="text">To install Apache, follow these steps:</div>
<div className="text"><ol><li>Open the terminal on your computer.</li><li>Type in the following commands:</li></ol></div>
<CodeBlock code={`sudo apt-get update sudo apt-get install apache2`} /><br/>
<div className="text">That's all there is to it! To make sure Apache is installed correctly, just open your web browser and enter your server's IP address (e.g., http ://12.34.56.789). If everything's set up right, you'll see a page with the words "It works!" on it.</div>
<div className="head">How to Check Your Server's IP Address</div>
<div className="text">To find out your server's IP address, you can use the following command:</div>
<CodeBlock code={`ifconfig eth0 | grep inet | awk '{ print $2 }'`} /><br/>
<div className="head">MySQL Setup</div>
<div className="text">MySQL is a system that helps you manage your data, making it easier to organize and find information.</div><br/>
<div className="text">To install MySQL, follow these steps in your terminal:</div>
<CodeBlock code={`sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql`} /><br/>
<div className="text">After the installation, MySQL will prompt you to set a root password. If you didn't set the password during the installation, don't worry. You can easily set it later from inside the MySQL shell.</div>
<div className="text">Once MySQL is installed, let's activate it with this command:</div>
<CodeBlock code={`sudo mysql_install_db`} /><br/>
<div className="text">To complete the process, run the MySQL setup script:</div>
<CodeBlock code={`sudo /usr/bin/mysql_secure_installation`} /><br/>
<div className="text">You'll be asked to enter your current root password.
Just type it in.</div>
<div className="text">Enter current password for root (enter for none): OK, successfully used password, moving on…</div>
<div className="text">Next, the prompt will inquire if you wish to change the root password. Select "N" to keep the current password and proceed to the following steps.</div><br/>
<div className="text">It's simplest to say "Yes" to all the options. Once you've done that, MySQL will reload and apply the updates.</div>
<CodeBlock code={`By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up...`} /><br/>
<div className="text">After completing those steps, you can wrap up by installing PHP.</div>
<div className="head">Getting PHP installed</div>
<div className="text">PHP is an open source web scripting language that is widely used to build dynamic web pages.<br/> To add PHP to your system, open your terminal and type in this command.</div>
<CodeBlock code={`sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt`} /><br/>
<div className="text">Once you've confirmed "yes" to the prompt twice, PHP will install itself automatically.</div><br/>
<div className="text">You might also want to include PHP in the directory index, so it can serve the appropriate PHP index files:</div>
<CodeBlock code={`sudo nano /etc/apache2/mods-enabled/dir.conf`} /><br/>
<div className="text">Make sure to include "index.php" at the start of your index files. Your page should now appear like this:</div>
<CodeBlock code={`<IfModule mod_dir.c> DirectoryIndex index.php index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule>`} /><br/>
<div className="head">PHP Extensions</div>
<div className="text">In addition to its core functionality, PHP offers various libraries and extensions that you can install on your virtual server. You can view the available extensions to enhance PHP's capabilities.</div>
<CodeBlock code={`apt-cache search php5-`} /><br/>
<div className="text">The terminal will show you a list of modules you can choose from. It will look something like this:</div>
<CodeBlock code={`php5-cgi - server-side, HTML-embedded scripting language (CGI binary) php5-cli - command-line interpreter for the php5 scripting language php5-common - Common files for packages built from the php5 source php5-curl - CURL module for php5 php5-dbg - Debug symbols for PHP5 php5-dev - Files for PHP5 module development php5-gd - GD module for php5 php5-gmp - GMP module for php5 php5-ldap - LDAP module for php5 php5-mysql - MySQL module for php5 php5-odbc - ODBC module for php5 php5-pgsql - PostgreSQL module for php5 php5-pspell - pspell module for php5 php5-recode - recode module for php5 php5-snmp - SNMP module for php5 php5-sqlite - SQLite module for php5 php5-tidy - tidy module for php5 php5-xmlrpc - XML-RPC module for php5 php5-xsl - XSL module for php5 php5-adodb - Extension optimising the ADOdb database abstraction library php5-auth-pam - A PHP5 extension for PAM authentication [...]`} /><br/>
<div className="text">When you've chosen the module you want to install, type the following command:</div>
<CodeBlock code={`sudo apt-get install name of the module`} /><br/>
<div className="text">You can install multiple libraries simultaneously by listing each module's name with a space in between.</div> <br/>
<div className="text">Great job! Your droplet now has a fully functional LAMP stack!</div>
<div className="head">Your PHP server's results - Viewing PHP</div>
<div className="text">Even though LAMP is installed, let's confirm by creating a simple PHP info page.
To do this, start by making a new file:</div>
<CodeBlock code={`sudo nano /var/www/info.php`} /><br/>
<div className="text">Now, include the following line:</div>
<CodeBlock code={`<?php phpinfo(); ?>`} /><br/>
<div className="text">After that, save your changes and close the file.<br/><br/>
Next, restart Apache to make sure all the changes are applied:</div>
<CodeBlock code={`sudo service apache2 restart`} /><br/>
<div className="text">Finally, open your web browser and go to your PHP info page. Make sure to replace "12.34.56.789" with the correct IP address of your server: http://your_server_ip_address/info.php</div><br/>
<div className="con">Conclusion -</div>
<div className="text">Awesome job! You've built a solid foundation for your website using LAMP on Ubuntu. With Apache for serving pages, MySQL for managing data, and PHP for dynamic content, your server is ready to go. To do even more with your server, you can try adding new features with PHP extensions or explore different tools and frameworks that work well with LAMP.</div><br/>
<div className="text"><strong>Excited to start creating your website or app? Let's dive in!</strong></div>