Difference between revisions of "User:Saul/linode"

From Organic Design wiki
(Created the linode setup reference and added initial setup commands.)
 
(Added LAMP stack section)
Line 26: Line 26:
 
PasswordAuthentication no # this stops anyone from logging in without authentication keys
 
PasswordAuthentication no # this stops anyone from logging in without authentication keys
 
sudo service ssh restart # reboots ssh and applies changes
 
sudo service ssh restart # reboots ssh and applies changes
 +
</source>
 +
== Setting Up The LAMP Stack ==
 +
=== Install And Configure Apache ===
 +
<source lang="bash">
 +
sudo apt-get install apache2
 +
sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.backup.conf # backup the configuration file before editing
 +
sudo nano /etc/apache2/apache2.conf
 +
# Modify this line like so:
 +
KeepAlive Off # keepalive allows fast connections to those who are already connected but may hold up other clients
 +
# Append these lines to the end of the file:
 +
<IfModule mpm_prefork_module>
 +
StartServers 4
 +
MinSpareServers 20
 +
MaxSpareServers 40
 +
MaxClients 200
 +
MaxRequestsPerChild 4500
 +
</IfModule>
 +
sudo service apache2 restart # restart apache to apply changes
 +
</source>
 +
=== Configure Virtual Hosts For Apache ===
 +
<source lang="bash">
 +
sudo a2dissite *default # Disable the default Apache virtual host
 +
cd /var/www/html
 +
sudo mkdir example.com
 +
sudo mkdir example.com/public_html
 +
sudo mkdir example.com/log
 +
sudo mkdir example.com/backups
 +
sudo nano /etc/apache2/sites-available/example.com.conf
 +
# domain: example.com
 +
# public: /var/www/html/example.com/public_html/
 +
 +
<VirtualHost *:80>
 +
# Admin email, Server Name (domain name), and any aliases
 +
ServerAdmin webmaster@example.com
 +
ServerName example.com
 +
ServerAlias www.example.com
 +
 +
# Index file and Document Root (where the public files are located)
 +
DirectoryIndex index.html index.php
 +
DocumentRoot /var/www/html/example.com/public_html
 +
 +
# Log file locations
 +
LogLevel warn
 +
ErrorLog /var/www/html/example.com/log/error.log
 +
CustomLog /var/www/html/example.com/log/access.log combined
 +
</VirtualHost>
 +
sudo a2ensite example.com.conf # adds a link in the correct location to the configuration file
 +
sudo service apache2 restart
 +
# Rince and repeat for any other websites to host.
 +
 +
# Optional:
 +
#sudo nano /etc/hosts # This is to test the virtual hosts and is done on the local computer
 +
# Append a line like this
 +
IP.ADRRESS.OF.THE.LINODE example.com
 +
</source>
 +
=== Install And COnfigure MySQL ===
 +
<source lang="bash">
 +
sudo apt-get install mysql-server
 +
sudo mysql_secure_installation # set a unique password, remove anonymous user accounts, disable remote root login, and remove the test database
 +
sudo nano /etc/mysql/my.cnf # for optimising mysql
 +
max_allowed_packet = 1M
 +
sudo service mysql restart
 +
</source>
 +
=== Install And Configure PHP ===
 +
<source lang="bash">
 +
sudo apt-get install php7.0 php-pear # PHP may update - change php7.0 to the current version number
 +
sudo apt-get install php7.0-mysql
 +
mkdir -p /var/log/php # create the folder for error logging
 +
chown www-data /var/log/php # changes the group of the file we created with the group www-data
 +
service apache2 restart
 +
 +
# Optional install php gd - this is an add-on allows php to manipulate image files - often used by gallery plugins in Wordpress.
 +
sudo apt-get install php7.0-gd
 
</source>
 
</source>

Revision as of 05:50, 14 March 2018

Linode Setup Reference:

Initial Setup

Update And Configure Timezone

apt-get update
apt-get upgrade
dpkg-reconfigure tzdata

Creating A New User

adduser saul # create the user saul
adduser saul sudo # adds saul to the sudo group
sudo usermod -a -G www-data saul # add saul to the www-data group

Setting up Authentication Keys

ssh-keygen -b 4096 # create the keyfile - do this on the client (watch you don't overwrite your existing one if you have done this before!)
ssh-copy-id saul@LINODE_IP # uploads the public key to linode

Configure SSH

sudo nano /etc/ssh/sshd_config
	# Modify these lines to look like this:
	PermitRootLogin no # this stops root from logging in
	PasswordAuthentication no # this stops anyone from logging in without authentication keys
sudo service ssh restart # reboots ssh and applies changes

Setting Up The LAMP Stack

Install And Configure Apache

sudo apt-get install apache2
sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.backup.conf # backup the configuration file before editing
sudo nano /etc/apache2/apache2.conf
	# Modify this line like so:
	KeepAlive Off # keepalive allows fast connections to those who are already connected but may hold up other clients
	# Append these lines to the end of the file:
	<IfModule mpm_prefork_module>
		StartServers 4
		MinSpareServers 20
		MaxSpareServers 40
		MaxClients 200
		MaxRequestsPerChild 4500
	</IfModule>
sudo service apache2 restart # restart apache to apply changes

Configure Virtual Hosts For Apache

sudo a2dissite *default # Disable the default Apache virtual host
cd /var/www/html
sudo mkdir example.com
sudo mkdir example.com/public_html
sudo mkdir example.com/log
sudo mkdir example.com/backups
sudo nano /etc/apache2/sites-available/example.com.conf
	# domain: example.com 
	# public: /var/www/html/example.com/public_html/ 
	
	<VirtualHost *:80>
		# Admin email, Server Name (domain name), and any aliases
		ServerAdmin webmaster@example.com
		ServerName example.com
		ServerAlias www.example.com
		
		# Index file and Document Root (where the public files are located) 
		DirectoryIndex index.html index.php
		DocumentRoot /var/www/html/example.com/public_html

		# Log file locations 
		LogLevel warn
		ErrorLog /var/www/html/example.com/log/error.log
		CustomLog /var/www/html/example.com/log/access.log combined
	</VirtualHost>
sudo a2ensite example.com.conf # adds a link in the correct location to the configuration file
sudo service apache2 restart
# Rince and repeat for any other websites to host.

# Optional:
#sudo nano /etc/hosts # This is to test the virtual hosts and is done on the local computer
	# Append a line like this
	IP.ADRRESS.OF.THE.LINODE example.com

Install And COnfigure MySQL

sudo apt-get install mysql-server
sudo mysql_secure_installation # set a unique password, remove anonymous user accounts, disable remote root login, and remove the test database
sudo nano /etc/mysql/my.cnf # for optimising mysql
	max_allowed_packet = 1M
sudo service mysql restart

Install And Configure PHP

sudo apt-get install php7.0 php-pear # PHP may update - change php7.0 to the current version number
sudo apt-get install php7.0-mysql
mkdir -p /var/log/php # create the folder for error logging
chown www-data /var/log/php # changes the group of the file we created with the group www-data
service apache2 restart

# Optional install php gd - this is an add-on allows php to manipulate image files - often used by gallery plugins in Wordpress.
sudo apt-get install php7.0-gd