here we will go through creating a LEMP stack. We've already installed nginx, now we will install & configure PHP and MYSQL
We will use wordpress as an example for this lesson.
sudo apt-get install php-fpm php-mysql mysql-server -y
Now we need to adjust a few PHP configurations
sudo ratom /etc/php/7.0/fpm/php.ini
Find the line with
;cgi.fix_pathinfo=1
change it to
cgi.fix_pathinfo=0
Save and exit
Now restart PHP
sudo systemctl restart php7.0-fpm
- Secure the root account with a password
- Set up a new user for website access
- Give that user the least amount of DB permissions needed to run wordpress
Run secure installation
sudo mysql_secure_installation
- current pass is empty (just hit return)
- yes for new password
- enter new pass
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y
test logging in
sudo mysql -uroot -p
exit
let's edit the config file
sudo ratom /etc/mysql/my.cnf
add the top of the configuration file
# The MariaDB configuration file
[mysqld]
bind-address=127.0.0.1
local-infile=0
log=/var/log/mysql.log
save and close
- we said that we only accept connections from the local machine
- then a directive to disable this ability to load local files
- then we set a location for the log file
Log back into mysql
CREATE USER 'brent'@'localhost' IDENTIFIED BY '15cakesmashes';
We are going to start installing wordpress as an example here.
We want to add other folders that will work as a server root for a specific domain name.
sudo ratom /etc/nginx/sites-available/default
This is the file that you can configure blocks of availble sites. So we can have more than just /var/www/html
The top block is being served out of /var/www/html
Let's configure another to serve out of /var/www/wordpress
Down towards the bottom of the file you will see # Virtual Host configuration for example.com
We're going to copy this block and uncomment it. Don't just uncomment and modify the existing block. Leave it for reference.
# Wordpress.Debian
server {
listen 80;
listen [::]:80;
server_name wordpress.debian;
root /var/www/wordpress;
index index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
and restart nginx
sudo service nginx restart
Download wordpress to your local share folder on host
rename the wp-config-sample.php
to wp-config.php
Log back into mysql
Now let's create the wordpress database
and then give our new user permissions to use it
in mysql
CREATE DATABASE wordpress;
show databases;
You can see that wordpress is there now
GRANT SELECT , INSERT , UPDATE , DELETE, ALTER, CREATE , DROP , INDEX ON `wordpress` . * TO 'brent'@'localhost';
GRANT ALTER, CREATE , DROP , INDEX ON `wordpress` . * TO 'brent'@'localhost';
SHOW GRANTS FOR 'brent'@'localhost';
Now rename the configuration file and edit it
mv wp-config-sample.php wp-config.php
ratom wp-config.php
You should now have a copy of wordpress in the /var/www
that you downloaded on the host side.
in the wordpress/config.php file edit in your database user details
in your local (host side) hosts file, add a domain name for wordpress
sudo atom /etc/hosts
mine looks something like this (fix it for your ip and whatever you want the fake domain name to be)
192.168.56.107 debian.server wordpress.debian
Then open up http://wordpress.debian in your browser.
To create a new site as a vhost you need to:
- Create a new directory for it in the shared folder
- edit the sites-available/default file to make an nginx block
- Modify your Host OSs /etc/hosts file with the new name