- Update package index using
sudo apt update
and install nginx usingsudo apt install nginx
- Verify ngix has been sucessfully installed.
- Check to see we can access our server locally by running a ``curl` command
- We check to see if our server would is accesible online via the public IP address.
- We acquire and install the MySQL using
sudo apt install mysql-server
- Once done, run
sudo mysql_secure_installation
The interactive script that removes inscure setting. - Test if you can access MySQL console by typing
sudo mysql
- To exit the console, we type
exit
- To get PHP working, we running the
sudo apt install php-fpm php-mysql
command.
- We create a root directory for our project -projectLEMP using
sudo mkdir /var/www/projectLEMP
- We assign ownership of the directory with the $USER environment variable by typing
sudo chown -R $USER:$USER /var/www/projectLEMP
- We create a new configuration file in Nginx’s
sites-available
directory by typingsudo nano /etc/nginx/sites-available/projectLEMP
- This will create a new blank file. we copy the configuration below inside.
- Link the configuration file to the
sites-enabled
directorysudo ln -s /etc/nginx/sites-available/projectLEMP /etc/nginx/sites-enabled/
- To make sure there a no errors, test configuration
sudo nginx -t
- We disable the defualt Nginx host which is configured to listen on port 80
sudo unlink /etc/nginx/sites-enabled/default
- We reload Nginx by typing
sudo systemctl reload nginx
- 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.
- Now we make sure Nginx can correctly server files to PHP processor, we do this by a test document named
info.php
we typenano /var/www/projectLEMP/info.php
- We type
?php
phpinfo();
- We go to our browser to make sure we can access the page.
- Since this file contains sensitive information about our server, we remove it by typing
sudo rm /var/www/your_domain/info.php
- 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.
- we loging to the mysql
sudo mysql
- We create a new database
- We create a new user and password for the database
- We give our new user permission over the database we created earlier
- We exit mysql shell using
exit
To log into mysql with the new user and password, we typemysql -u example_user -p
- Type
SHOW DATABASES;
- We then create a test table named todo_list
- We insert a few rows in the table using different values.
- Exit mysql
- 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
- The paste the following content in the new file. . We save and close the file when done editing.
- We access the page through our public ip address and add
/todo_list.php
to view our to-d0 list page.