1. Connect to the Linux instance using SSH or the console terminal on Lightsail.
Under Networking, under IPv4 Firewall, click ‘add rule’, under the Applications dropdown menu, choose HTTPS. This will open port 443 for secured connection.
2. Setup Nginx
3. Create a config file called fady.conf in /etc/nginx/conf.d
sudo nano /etc/nginx/conf.d/fady.conf
then, paste the following server block into the file, then save it using Ctrl-x, Ctrl-Y.
server {
server_name fadylab1.constantin.gallery;
server_name_in_redirect off;
access_log /var/log/nginx/fadylab1.access_log;
error_log /var/log/nginx/fadylab1.error_log info;
root /opt/fady/fadylab1;
client_max_body_size 100M;
autoindex off;
index index.php index.html index.htm default.html default.htm;
# Support Clean (aka Search Engine Friendly) URLs
location / {
try_files $uri $uri/ /index.php?$args;
}
# deny running scripts inside writable directories
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}
location ~ \.php$ {
# include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi.conf;
fastcgi_busy_buffers_size 512k;
fastcgi_buffer_size 512k;
fastcgi_buffers 16 512k;
}
location ~* \.(ico|pdf|flv)$ {
expires 1y;
}
location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
expires 14d;
}
listen 80; # managed by Certbot
}
Unlike Apache, Nginx doesn’t have a built in support for processing PHP files so we need to install a separate application such as PHP FPM (“fastCGI process manager”) which will handle PHP files.
To install the PHP and PHP FPM packages run the following command:
sudo apt install php8.1-fpm
Once the packages are installed you can check the status of the PHP FPM service with:
systemctl status php8.1-fpm
* php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2018-06-30 23:56:14 PDT; 1min 28s ago
Docs: man:php-fpm7.4(8)
Main PID: 10080 (php-fpm7.4)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
Tasks: 3 (limit: 2321)
CGroup: /system.slice/php7.4-fpm.service
|-10080 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
You can now edit the Nginx server block and add the following lines so that Nginx can process PHP files:
server {
# . . . other code
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
}
Do not forget to restart the Nginx service so that the new configuration take effect:
sudo service nginx restart
5. install packages required by PHP
sudo apt-get install php8.1-fpm php8.1-common php8.1-mbstring php8.1-xml php8.1-xmlrpc php8.1-soap php8.1-gd php8.1-xml php8.1-intl php8.1-cli php8.1-ldap php8.1-zip php8.1-curl php8.1-intl php8.1-mysql mysql-server mysql-client
6. Configure the MySql serverfollow the above instructions to set up MySQL. pick a root password.
mysql --user=root --password=<password>
show databases;
// select user from mysql.user;
create user 'fady'@'localhost' identified by '<fady's password>';
create database fadylab1_wp;
grant all on fadylab1_wp.* to 'fady'@'localhost' with grant option;
flush privileges;
exit;
Note, if MySQL needs to be restarted:
- systemctl status mysql.service
- sudo service start mysql
7. Download WordPress
create a temp directory to store the downloaded file:
cd /opt
sudo mkdir temp
cd temp
Then download the compressed release with the following curl command:
curl -O https://wordpress.org/latest.tar.gz
Extract the compressed file to create the WordPress directory structure:
tar xzvf latest.tar.gz
8. Configure the wordpress directory
cd /opt
sudo mkdir fady
cd fady
sudo mkdir fadylab1
copy the wordpress files into the newly created directory
sudo cp -R /opt/temp/wordpress/* .
change file ownership to www-data:www-data
sudo chown -R www-data:www-data /opt/fady/fadylab1
Next, run two find commands to set the correct permissions on the WordPress directories and files. This first find command sets every directory within the /opt/fady/fadylab1> directory and sets each one’s permissions to 755:
sudo find /opt/fady/fadylab1/ -type d -exec chmod 755 {} \;
This one finds each file within the directory and sets their permissions to 755:
sudo find /opt/fady/fadylab1/ -type f -exec chmod 755 {} \;
9. Setup WordPress
follow the on-screen instructions to set up WordPress
database name: fadylab1_wp
user: fady
password: from step 6
10. Install free SSL certificates using Certbot so the website is using the encrypted https:// protocol
If copying nginx conf file from a previous server, you will need to remove all the previous letsencrypt added lines first before you run certbot and let it insert those lines again.
Optional:
If you want to run express server, you can also install nvm to manage node js:
11. Setup nvm (not nodejs directly)