When migrating servers to AWS, its great to be able to set them up easily and quickly. This is effectively a lovely cheat-sheet. By running the scripts below you can have a full LAMP Stack running on an EC2 instance running Ubuntu in less than 5 minutes.
/* Set locale to UK – V IMPORTANT!! */
sudo locale-gen en_GB.UTF-8
/* Run update and upgrades */
sudo apt-get update
sudo apt-get upgrade
/* Install Apache 2 */
sudo apt-get install apache2
/* Server internal firewall config */
sudo ufw allow OpenSSH
sudo ufw allow in “Apache Full”
sudo ufw enable
/* Install MySQL */
sudo apt-get install mysql-server
/* Install php and associated plugins as needed */
sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
sudo apt-get install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc
/* Restart services */
sudo systemctl restart apache2
/* Update Apache2 config to allow .htaccess files and modified file permissions */
sudo nano /etc/apache2/apache2.conf
AllowOverride (Change None to All)
/* Turn on rewrite rules for Apache2 */
sudo a2enmod rewrite
sudo systemctl restart apache2
/* Update permissions so that FTP can write to the web root folder */
sudo chown -R ubuntu:www-data /var/www/html
/* Reboot server */
Recently we have had several servers run out of hard drive space causing inaccessibility and crashing. On further investigation the hard drive was full so many operations were complaining. The hard drive was being consumed by a very large file within the /var/lib/mysql directory called ibtmp1.
ibtmp1 is a temporary working file for MySQL. When you turn the MySQL server off and on again the file is deleted and the server runs again without issue until the file becomes too large again.
After some quick research we found that adding or editing a few settings in the MySQL configuration allows you to limit the size of this file and prevent this issue from reoccurring.
Open the mysqld.cnf file. The location of our mysqld.cnf was in /etc/mysql/mysql.conf.d/mysqld.conf. According to the file you can also copy this configuration to /etc/mysql/my.cnf. Our my.cnf just had an include to the mysqld.cnf file.
The file should have some sections like:
There should be a section for InnoDB settings. If not, it is fine to add these configuration settings at the bottom of the file.
Here is the configuration variable:
innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:1G
This value can be tweaked based on your server setup and needs but these are the settings we used for our server to set the file to start at 12 MB and limit it to 1 GB.
While setting this we also set a few other variables for optimisation:
To access MySQL that has been installed as part of MAMP:
1. Click on File, Edit Template and then MySQLmy.cnf
2. On line 37 (normally) you will see the bind-address = 127.0.0.1 (localhost) by default. Change this to: 0.0.0.0
3. Open phpMyAdmin on the local machine, click on the Users tab and then Add user
4. Enter details of the username and password. On the Database for user section choose Grant all privileges on wildcard name. Check all privileges for the user. (Ensure that Grant is ticked under Administration)
Click on Add user.
5. Restart the MAMP servers.
I was finding that the server hosting my blog was running slowly, so the very nice people at Brinkster upgraded the site to a new faster server last night – to great effect 🙂
The blog now has a new faster MySQL database server as well – shame they wont support running it from Microsoft SQL Server – would work much better under load!