Skip to content

Latest commit

 

History

History
74 lines (64 loc) · 5.15 KB

Project2.md

File metadata and controls

74 lines (64 loc) · 5.15 KB

LEMP STACK IMPLIMENTATION

Install Nginx Server

  1. Update package index using sudo apt update and install nginx using sudo apt install nginx
  2. Verify ngix has been sucessfully installed. nginx server
  3. Check to see we can access our server locally by running a ``curl` command curl
  4. We check to see if our server would is accesible online via the public IP address. Check nginx page

Install MySQL

  1. We acquire and install the MySQL using sudo apt install mysql-server
  2. Once done, run sudo mysql_secure_installation The interactive script that removes inscure setting.
  3. Test if you can access MySQL console by typing sudo mysql mysql
  4. To exit the console, we type exit

Install PHP

  1. To get PHP working, we running the sudo apt install php-fpm php-mysql command.

Congifure Nginx to use PHP

  1. We create a root directory for our project -projectLEMP using sudo mkdir /var/www/projectLEMP
  2. We assign ownership of the directory with the $USER environment variable by typing sudo chown -R $USER:$USER /var/www/projectLEMP
  3. We create a new configuration file in Nginx’s sites-available directory by typing sudo nano /etc/nginx/sites-available/projectLEMP
  4. This will create a new blank file. we copy the configuration below inside. configuration
  5. Link the configuration file to the sites-enabled directory sudo ln -s /etc/nginx/sites-available/projectLEMP /etc/nginx/sites-enabled/
  6. To make sure there a no errors, test configuration sudo nginx -t ngix syntax
  7. We disable the defualt Nginx host which is configured to listen on port 80 sudo unlink /etc/nginx/sites-enabled/default
  8. We reload Nginx by typing sudo systemctl reload nginx
  9. We creat an index.html file in /var/www/projectLEMP since it's still empty. sudo echo 'Hello LEMP from hostname' $(curl -s http://169.254.169.254/latest/meta-data/public-hostname) 'with public IP' $(curl -s http://169.254.169.254/latest/meta-data/public-ipv4) > /var/www/projectLEMP/index.html We validate this on our web browser.

Test PHP with Nginx

  1. Now we make sure Nginx can correctly server files to PHP processor, we do this by a test document named info.php we type nano /var/www/projectLEMP/info.php
  2. We type
?php
phpinfo();
  1. We go to our browser to make sure we can access the page.
  2. Since this file contains sensitive information about our server, we remove it by typing sudo rm /var/www/your_domain/info.php

Retrieve data from MySQL database using PHP

  1. We create a test “To do list” database and configure access to it, so our Nginx website would be able to query data from the DB and display it.
  2. we loging to the mysql sudo mysql
  3. We create a new database
  4. We create a new user and password for the database
  5. We give our new user permission over the database we created earlier
  6. We exit mysql shell using exit To log into mysql with the new user and password, we type mysql -u example_user -p
  7. Type SHOW DATABASES;
  8. We then create a test table named todo_list
  9. We insert a few rows in the table using different values.
  10. Exit mysql
  11. We create a PHP script that will connect to MySQL and query for our content. We create a new PHP file in your custom web root directory nano /var/www/projectLEMP/todo_list.php
  12. The paste the following content in the new file. . We save and close the file when done editing.
  13. We access the page through our public ip address and add /todo_list.php to view our to-d0 list page.