Lab 3 Lamp Stackif You Are Brave And Intrepid Try This Lab Prior To ✓ Solved
LAB #3: LAMP Stack If you are brave and intrepid, try this lab prior to class. If you are less confident, we will review these slides in class session for week 4. Package Installers â— â— â— â— â— We will be using the built-in package installer apt-get and you should get to know it. apt is a newer and simpler version, btw. We will also use pip, which is a program that merely finds and installs software for you. Although frameworks exist to streamline some of this, today’s lesson will have us installing many pieces manually, so follow along.
If you should encounter a problem, let me know, but it is ultimately your responsibility to get this to work, much like you would in a job within the IT industry. Google for help, and you may have to solve particular challenges related to your laptop, OS, settings that are unique to you, disk space, conflicts, etc. This should work well if you have a clean Ubuntu instance to work with. If you have cloned your instance, you have a safe “sandbox †Getting Up To Date â— â— â— â— â— â— â— Because your installation of Ubuntu might not be fully patched up, let’s start there. Ubuntu comes from Debian, which has apt-get and apt (Advanced Package Tool) sudo apt-get update (same as) sudo apt update this command will pull down all the updates you need for installed packages sudo moves you into super user (do this as super user = sudo) Now, let’s upgrade what we just pulled down: sudo apt-get upgrade You may have to respond Y)es to get it to complete, and it may take a few minutes to complete all the updates Python 3 vs.
Python 2 â— â— â— â— â— â— Since Python 2 is often the default in Linux distributions, we’ll start by making Python 3 our default. Python 2 has been deprecated, but is still widely available. Check python version: python --version If you get an error saying that python doesn’t exist, but python3 does, you’ll need to create a symbolic link. To create a symbolic link to python 3: sudo ln -s /usr/bin/python3 /usr/bin/python This will capture “python†commands and send them to python 3 To test, re-run python --version and you should see the correct answer (python 3.8.2 or later) Install Pip â— â— â— â— â— Pip is a package installer and will help you throughout this and other labs. sudo apt install python3-pip This will install a simple tool that will allow you to better use python tools and packages later on.
As with all installs, Ubuntu will likely ask you to approve the use of additional space for this new tool, with a simple “y†response. It may take a few minutes Install MySQL â— â— â— â— â— â— MySQL is a very popular database. MariaDB is the open source fork from it. (To use MySQL in production environments does cost.) sudo apt install mysql-server When this completes... sudo mysql_secure_installation Select whatever strength of password you like, but respond to other prompts with y to maximize security. This will help remove hackable components and ensure password protection is in place. You may wish to select a LOW security password for testing, but write it down or remember it.
You can choose to enforce some of the suggestions or we can do that later. TEST db might be helpful to some of you. Let’s Increase Security... These commands will help us work around the problem: $> sudo mysql mysql> select user, authentication_string, plugin, host from mysql.user; mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NewPassword'; (NewPassword is one that you make up) mysql> flush privileges mysql> exit Test your work: sudo mysql (this should fail to let you in) mysql -u root -p (this should let you enter MySQL) Connect Python and MySQL Easily â— â— â— PyMySQL is a connector utility to allow Python to easily connect to MySQL and to enforce transactional integrity Run the following to help you connect from Python to MySQL: sudo pip3 install pymysql Install Apache Webserver â— â— â— â— â—‹ â—‹ â—‹ â—‹ The world’s most popular web server, and it’s free! sudo apt install apache2 To test this, you should be able to open a browser, point it to and get a page indicating that it works!
Optionally, you can learn more by doing this: cd /var/www/html look at contents using ls -l sudo nano index.html (sudo is required since root owns Apache) (exit nano with CTRL-X as shown at the bottom of the page) Play with the Apache Webserver â— â— â— â— â— â— Let’s see how Apache would install a simple hello world web In the html directory, sudo nano hw.html type Hello World, it’s me, <yournamehere>! Then from your browser, point to and see what comes up. Critical Thinking: Why does this work when we put in no official HTML tags?? Stretch Goal: Create a resume.html file that you create yourself, outlining your resume. Use HTML tags (minimal ones should suffice) Create Apache Test Directory â— â— â— â— â— â— â— Create a test directory: sudo mkdir /var/www/test Register Python with Apache, enable multi-processing module and allow CGI scripts to run sudo a2dismod mpm_event sudo a2enmod mpm_prefork cgi You will have to restart apache using sudo systemctl restart apache2 TEST by rechecking your localhost call in browser.
Fix problems that might have been caused by sloppy command entry on this page. Make some apache modifications â— â— â— sudo nano /etc/apache2/sites-enabled/000-default.conf You are now in the nano editor. Simple, easy, and commands listed on the bottom as CTRL+? key strokes. Add the following right after the first line, which reads “<VirtualHost *:80\>†using tabs for indentation, not just spaces <Directory /var/www/test> Options +ExecCGI DirectoryIndex index.py </Directory> AddHandler cgi-script .py [note the space!] Further configure Apache: â— â— Prior steps told Apache to work from the test directory, that it contains executables, that index.py is the default. Now go to the part of the document that reads DocumentRoot /var/www/html and change the characters “html†to be “test†so the result looks like: DocumentRoot /var/www/test Result Should look like this: <VirtualHost *:80> <Directory /var/www/test> Options +ExecCGI DirectoryIndex index.py </Directory> AddHandler cgi-script .py … DocumentRoot /var/www/test Further configure Apache: â— â— â— â— Save (CTRL-o) and Exit (CTRL-x) Restart apache to effect those changes as follows: sudo systemctl restart apache2 now, if you retry the from browser, and you’ll see that the default Apache welcome screen no longer appears, since we’ve told Apache to look in a new directory for a file which we have yet to create.
Now let’s have some database fun! â— â— â— â— â— â— â— â— First let’s create a database: mysql -u root -p this will prompt you for the password you gave it during install. Your prompt should now indicate you’re in MySQL and will change from a standard terminal prompt (“$â€) to “mysql>†Create the database mysql> CREATE DATABASE yoga; Switch to use that database: mysql> USE yoga MySQL â— â— â— â— â— â— â— â— Let’s create a table and add some values: mysql> create table instructors (id INT, name VARCHAR(20)); Insert some records: mysql> insert into instructors values (1, ‘Erin’); mysql> insert into instructors values (2, ‘Caroline’); mysql> insert into instructors values (3, ‘<your name here>’); (use YOUR name…) test your table: mysql> select * from instructors; exit mysql by pressing CTRL+D or typing quit And now let’s connect all the dots! â— â— â— â— â— â— Now we’ll create our Python program Type in the content shown on the following page into the file called /var/www/test/index.py (MANY have trouble with copy-and-paste) Do not create this file in your home directory sudo nano /var/www/test/index.py Cutting and pasting from the following slide could introduce hidden characters, so I recommend typing it in, remembering to use TABS for indentation, not spaces! index.py #!/usr/bin/python # Debug mode on import cgitb cgitb.enable() #Print html headers print (“Content-Type: text/html\n\nâ€) #Connect to the db import pymysql con = pymysql.connect( db=’yoga’, user=’root’, passwd=’yourpassword’, host=’localhost’) #print contents try: with con.cursor() as cur: cur.execute(“Select * from instructorsâ€) rows = cur.fetchall() for row in rows: print(f’{row[0]} {row[1]}’) finally: con.close() Connect all the dots! â— â— Make this file executable! sudo chmod 755 /var/www/test/index.py Exit Criteria: Test our work 1.
2. a. b. 3. 4. 5. 6.
7. test at O/S level: python index.py if errors, correct there first See the on-screen error. This is testing Python and MySQL work only. Make sure this isolation test works before testing under Apache if you successfully get data, test using browser: http:// localhost if errors, see log: tail /var/log/apache2/error.log if continued errors, review code snippets provided on Blackboard Discussion Board “Lab Support†if you cannot debug using existing support and threads, post a new thread so all of us can support one another If you still have trouble, attend office hours with GTA or Professor What does success look like? So what just happened? â— When we pointed a browser to we used Apache to handle our request, which by default went to our Python script, which executed a select of rows of data from MySQL Deliverables & Next Steps â— â— Create a single file submission containing a screen shot of your application running in your browser.
The web page data MUST contain YOUR full name to receive credit. Review the steps to understand how we installed the various components, how we updated our installation using apt and apt-get, how we built a small database, how we inserted data, how we created a simple web program, and, how that resulted in the working web page pulling data. Stretch Goals â— â— â— â— Consider doing some digging into the ways in which Apache Webserver can serve up different types of files. Consider digging deeper into the various components, such as MySQL and Python to become better versed in their technologies, which will help you at job interviews, even for non-developer jobs. Look into the vast library of Apache projects that would be good to know about.
Just knowing they exist will help a conversation in a job interview or where you’re considering technology stacks. Consider where some vulnerabilities exist, and how we might secure and quantify our technology stack to make it suitable for production. Last week, you completed the first step in your assignment by selecting a controversial contemporary issue. This week, you will complete the next step by using scholarly research tools to locate and write about three academic articles or books that are relevant to the topic you chose. Carefully read each source.
If one of your sources is a book, just read the relevant chapter or chapters. Take notes. What are the article's main points? What key terms, concepts, or arguments does the article's author use to make those points? How can you use the article's main points to develop your own thoughts and opinions on the issue you have chosen?
Here is how your response should be structured. 1. Open with a paragraph that contains a brief overview of the issue and why it is important to you. In a broad way, indicate why you feel the sources you have chosen are relevant to your topic choice. 2.
In the second, third, and fourth paragraphs, provide a summary of each source in your own words. In other words, each source summary should be one paragraph long. If appropriate, include brief quotations of no longer than a sentence, but no more than one quotation per source. 3. In the fifth and final paragraph, conclude by noting similarities and differences, as well as strengths and weaknesses of each source.
Which source do you think will be most helpful to you? 4. Include a references page in APA format. Be sure to include all of the required publication information and to list the sources alphabetically. The total length of this response should be approximately 600–800 words.
ETHC445 Ethics and Contemporary Issues Project: Academic Scholarship Criteria Ratings Pts Introduction: It provides an overview of the topic and indicates the relevance of the sources to the chosen topic in a broad fashion. This area will be used by the assessor to leave comments related to this criterion. 20 pts Source Summaries: A one-paragraph summary of each source is provided. The summaries are written in the student's own words. Any brief quotations are properly placed in quotation marks and cited in APA format.
This area will be used by the assessor to leave comments related to this criterion. 50 pts Similarities and Differences: Response notes similarities and differences among the sources and assesses strengths and weaknesses. This area will be used by the assessor to leave comments related to this criterion. 20 pts ETHC445 Ethics and Contemporary Issues Project: Academic Scholarship Criteria Ratings Pts References: References are provided in APA format. Careful attention is paid to the order of information, capitalization, and italics.
This area will be used by the assessor to leave comments related to this criterion. 10 pts Total Points: 100 To this point in the class we have focused on the study of ethics from ancient times through the Enlightenment period, and in upcoming lessons we will continue with this historical approach into modern times. This week, however, you will begin working on a multistep assignment that will focus on a contemporary ethical issue, and you will apply ideas from throughout the course to reach an ethical stance on it. This assignment will consist of four main pieces. • Topic Selection: See directions below (Week 3) • Academic Research: (Week 4) • Introduction, Background, and Ethical Challenges: (Week 5) • Solutions and Conclusion: (Week 6) • Presentation: (Week 7) For more details, consult the Ethics and Contemporary Issues Project Overview.
As a reminder, here are the possible topics for your project. • Changing the names of schools or taking down statues named after controversial historical figures • Using race or ethnicity as a factor in hiring decisions or college admissions • "Canceling" people or organizations who have made controversial or insensitive remarks • Encouraging businesses to become more politically active • Allowing people who have undergone gender reassignment to participate in competitive sports • Providing people with disabilities reasonable accommodations in the workplace • Teaching critical race theory or the 1619 Project in schools • Compelling private businesses to serve customers they do not wish to • Debating the merits of various immigration policies, such as open borders, the building of walls, and so on • Doing away with cash bail for many criminal offenses • Eliminating harassment in the workplace • Reallocating money from the police to other city agencies and services • Reforming or eliminating the Electoral College • Implementing a wealth tax on millionaires and billionaires who pay little or no income tax • Forgiving student loans or making college tuition free • Giving everyone a universal basic income • Requiring voters to provide identification This week you will begin by choosing your topic.
You will complete this assignment by answering the following questions in complete sentences and submitting them in a Word document. • What is your topic? • Why did you choose it? • What ethical dilemmas does your topic raise? • Based on what you have learned about ethics so far, how do you imagine some of the famous ethicists of the past, such as Aristotle, Aquinas, or Locke, would have to say about your topic? Finally, find one good contemporary source related to your topic choice. Ideally, this will be a scholarly source from a journal, but it may also be a good-quality source from a contemporary periodical publication as well. Provide the full reference for this source in APA style, followed by a quick summary of a few sentences written in your own words.
ETHC445 Ethics and Contemporary Issues Project Topic Selection Criteria Ratings Pts Introduction: Response explains which topic was chosen and why it was chosen using complete sentences. This area will be used by the assessor to leave comments related to this criterion. 10 pts Ethical Dilemmas: Response discusses at least one potential ethical dilemma related to the topic. This area will be used by the assessor to leave comments related to this criterion. 10 pts Ethical Theories: Response discusses at least one ethical theory or ethical theorist relevant to the topic.
This area will be used by the assessor to leave comments related to this criterion. 10 pts Quality Source: Provides summary and full reference in APA style for a relevant source. This area will be used by the assessor to leave comments related to this criterion. 20 pts Total Points: 50
Paper for above instructions
Lab 3: LAMP Stack Implementation
The LAMP stack, comprising of Linux, Apache, MySQL, and PHP/Python (or Perl), forms a ubiquitous framework for building dynamic websites and applications. This lab assignment centers on installing and configuring these components manually, focusing on establishing a foundational understanding of how they work together. It is intended for beginners willing to take the initiative in troubleshooting, a crucial skill in a career in IT.
Getting Started with Installation
Updating the System
To begin, it is essential to ensure that your Ubuntu instance is fully up to date. Using `apt-get` or the simplified version `apt` is imperative in managing packages on Debian-based systems. The commands to execute this are:
```bash
sudo apt-get update
sudo apt-get upgrade
```
These commands update the package index and upgrade all installed packages, respectively. Responding with ‘Y’ when prompted confirms your intention to proceed (Ubuntu, 2023).
Setting Python Version
Due to the deprecation of Python 2, transitioning to Python 3 is important. First, check your Python version with:
```bash
python --version
```
If Python 2 appears, create a symbolic link using the command:
```bash
sudo ln -s /usr/bin/python3 /usr/bin/python
```
Test again using `python --version` to confirm the switch.
Installing Pip
To facilitate package management for Python, install Pip with the command:
```bash
sudo apt install python3-pip
```
This tool aids in managing additional Python packages necessary for future developments (Van Rossum & Drake, 2022).
Database Installation
Installing MySQL
Next, install MySQL, an integral relational database management system, with:
```bash
sudo apt install mysql-server
```
After installation, execute the security script:
```bash
sudo mysql_secure_installation
```
This script enhances security by removing default settings and passwords. Create a password and remember this for later use (MySQL, 2023).
Testing and Configuring the Database
Connect and configure your database for security and access:
```bash
sudo mysql
SELECT user, authentication_string, plugin, host FROM mysql.user;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NewPassword';
FLUSH PRIVILEGES;
EXIT;
```
Testing your database connection should now allow access through:
```bash
mysql -u root -p
```
Web Server Setup
Installing Apache
Apache is one of the most widely used web servers. Install it by executing:
```bash
sudo apt install apache2
```
Test your installation by pointing your browser to `http://localhost`. You should see the Apache default page (Apache Software Foundation, 2023).
Creating a Sample Web Page
In your web root directory, create a simple HTML file:
```bash
cd /var/www/html
sudo nano hw.html
```
Insert the following HTML code:
```html
Hello World, it’s me,
```
Save and exit. Testing by refreshing the browser should now show your message.
Connecting Python and MySQL
Using PyMySQL as a Connector
Install PyMySQL to allow Python to connect with MySQL:
```bash
sudo pip3 install pymysql
```
Configuring Apache for Python Scripts
Creating a Test Directory
Create an additional directory to host Python scripts:
```bash
sudo mkdir /var/www/test
```
Next, enable necessary modules and restart Apache:
```bash
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork cgi
sudo systemctl restart apache2
```
Editing Apache Configuration
Edit Apache's configuration file to point to the new directory:
```bash
sudo nano /etc/apache2/sites-enabled/000-default.conf
```
Insert the following configuration block after `
```apache
Options +ExecCGI
DirectoryIndex index.py
AddHandler cgi-script .py
DocumentRoot /var/www/test
```
Restart Apache for these changes to take effect.
Implementing the Database and Python Integration
Creating the Database
To create a simple database and a table:
```bash
sudo mysql -u root -p
CREATE DATABASE yoga;
USE yoga;
CREATE TABLE instructors (id INT, name VARCHAR(20));
INSERT INTO instructors VALUES (1, 'Erin'), (2, 'Caroline'), (3, '
SELECT * FROM instructors;
EXIT;
```
Creating the Python Script
Set up your Python script using the command:
```bash
sudo nano /var/www/test/index.py
```
Ensure this script includes the connection to MySQL and output logic:
```python
#!/usr/bin/python
import cgitb
cgitb.enable()
print ("Content-Type: text/html\n\n")
import pymysql
con = pymysql.connect(db='yoga', user='root', passwd='yourpassword', host='localhost')
try:
with con.cursor() as cur:
cur.execute("SELECT * FROM instructors")
rows = cur.fetchall()
for row in rows:
print(f'{row[0]} {row[1]}')
finally:
con.close()
```
Ensure the script is executable:
```bash
sudo chmod 755 /var/www/test/index.py
```
Testing the Setup
To validate everything is working correctly, first test at the command line using:
```bash
python /var/www/test/index.py
```
Lastly, test via your browser by visiting `http://localhost`. If successful, you should see the database output displayed.
Conclusion
In summary, this lab assignment successfully guided through the installation and integration of a LAMP stack. The key components work in unison to facilitate dynamic content delivery via web applications. The challenges faced during setup mimicked real-world scenarios encountered in IT, thereby providing valuable troubleshooting experience. Additional research on Apache server configurations and Python's capabilities can enhance knowledge further, preparing for future endeavors in technology sectors.
References
1. Apache Software Foundation. (2023). Apache HTTP Server Documentation. https://httpd.apache.org/docs/2.4/
2. MySQL. (2023). MySQL 8.0 Reference Manual. https://dev.mysql.com/doc/refman/8.0/en/
3. Ubuntu. (2023). Ubuntu documentation. https://help.ubuntu.com/
4. Van Rossum, G., & Drake, F. L. (2022). Python 3 Reference Manual. CreateSpace Independent Publishing Platform.
5. W3C. (2023). HTML Specification. https://www.w3.org/TR/html52/
6. PyMySQL. (2023). PyMySQL Documentation. https://pymysql.readthedocs.io/en/latest/
7. Linux Foundation. (2023). Linux Fundamentals. https://training.linuxfoundation.org/training/linux-fundamentals/
8. LAMP Stack. (2023). LAMP Stack Overview. https://www.digitalocean.com/community/tutorials/understanding-the-lamp-stack
9. GNU. (2023). Bash Reference Manual. https://www.gnu.org/software/bash/manual/bash.html
10. Stack Overflow Documentation. (2023). Understanding the LAMP Stack. https://stackoverflow.com/documentation/lamp/2827/understanding-the-lamp-stack
This guide provided foundational implementations of a LAMP stack, leading to dynamic website functionalities. All participants are encouraged to explore advanced configurations and optimizations for deeper proficiency.