Skip to content

Instantly share code, notes, and snippets.

@jacksonfdam
Forked from ankurk91/install_lamp_ubuntu.sh
Created September 23, 2016 14:44
Show Gist options
  • Save jacksonfdam/7bc05b9a37461fb55e1cb5aed167eaa3 to your computer and use it in GitHub Desktop.
Save jacksonfdam/7bc05b9a37461fb55e1cb5aed167eaa3 to your computer and use it in GitHub Desktop.
Prepare Ubuntu 16.04 for PHP development (php 7.0, Maria DB 10, MySQL 5.6, apache 2.4)

Install MySQL 5.6 on Ubuntu 16.04

  • Ubuntu 16.4 allows only MySQL v5.7.13 (as of now) which has a memory leak bug
  • According to release notes this bug was fixed with v5.7.14
  • The idea here is to install MySQL v5.6 that was built for Ubuntu 15.10 (wily)
  • Remove previous MySQL versions if any
sudo apt remove mysql-client mysql-server libmysqlclient-dev mysql-common
  • Check if anything left installed and remove if any
dpkg -l | grep mysql
  • Download and install apt_config-debian package ~20 kb
# Installing an old version instead
wget --retry-connrefused --tries=0 http://repo.mysql.com/mysql-apt-config_0.7.2-1_all.deb
sudo dkpg -i mysql-apt-config_0.7.2-1_all.deb
  • This screen is a bit tricky (repeat if you failed) - Choose Ubuntu Wily and MySQL 5.6 when asked.
  • Check if MySQL 5.6 is in the apt index list
sudo apt-cache policy mysql-server | grep 5.6 
  • If not, check your /etc/apt/sources.list.d/mysql.list It should look roughly like this:
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out entries below, but any other modifications may be lost.
# Use command 'dpkg-reconfigure mysql-apt-config' as root for modifications.
deb http://repo.mysql.com/apt//ubuntu/ wily mysql-apt-config
deb http://repo.mysql.com/apt//ubuntu/ wily mysql-5.6
deb http://repo.mysql.com/apt//ubuntu/ wily mysql-tools
deb-src http://repo.mysql.com/apt//ubuntu/ wily mysql-5.6
  • You might have to replace xenial with wily
  • Create a new file /etc/apt/preferences.d/mysql with this content
Package: *
Pin: origin "repo.mysql.com"
Pin-Priority: 999
  • Above file will prevent apt from picking up mysql from Ubuntu servers
  • Update apt indexes
sudo apt update
  • Install MySQL 5.6 (no need to speficy version)
sudo apt install mysql-client mysql-server
  • Answer the asked questions, remember your root password
  • Check mysql version
mysql --version
  • Enjoy

Fix MariaDB login issue when it says - Access denied for user 'root'@'localhost'

MariaDB enables a plugin called unix_socket for the root user by default, this plugin prevents that the root user can log in to PHPMyAdmin and that TCP connections to MySQL are working for the root user. Therefore, lets deactivate that plugin with the following commands:

sudo mysql -u root
use mysql;
update user set plugin='' where User='root';
flush privileges;
quit;
sudo service mysql restart
# Now you can set password for root if you want 
mysql_secure_installation

Refrences

#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Ubuntu 16.04 Dev Server
# Don't source it, run like - bash install_lamp.sh
# Script will auto terminate on errors
# Prevent source
[[ "${BASH_SOURCE[0]}" != "${0}" ]] && echo -e "\e[91m This script is being sourced, will exit now \e[39m" && return
# Update indexes (optional)
sudo apt-get update
echo -e "\e[96m Install apache \e[39m"
sudo apt-get -y install apache2
echo -e "\e[96m Install php \e[39m"
sudo apt-get -y install php7.0 libapache2-mod-php7.0
# Enable php exts
sudo apt-get -y install mcrypt php7.0-mysql php7.0-mcrypt php7.0-curl php7.0-json php7.0-mbstring php7.0-gd php7.0-intl php-gettext php-xdebug
sudo phpenmod mcrypt
sudo phpenmod curl
# Enable some apache modules
sudo a2enmod rewrite
#sudo a2enmod headers
echo -e "\e[96m Restart apache server to reflect changes \e[39m"
sudo service apache2 restart
echo -e "\e[96m Install mysql server \e[39m"
echo -e "\e[93m User: root, Password: root \e[39m"
# Install MySQL Server in a Non-Interactive mode. Default root password will be "root"
echo "mysql-server-5.7 mysql-server/root_password password root" | sudo debconf-set-selections
echo "mysql-server-5.7 mysql-server/root_password_again password root" | sudo debconf-set-selections
sudo apt-get -y install mysql-server-5.7
### Run next command on production server
#sudo mysql_secure_installation
# Check php version
php -v
# Check apache version
apachectl -v
# Check mysql version
mysql --version
# Check if php is working or not
php -r 'echo "\nIt means your PHP installation is working fine.\n";'
echo -e "\e[92m Open http://localhost/ to check if apache is working or not. \e[39m"
# Clean up cache
sudo apt-get clean
#!/bin/bash
# Script will auto terminate on errors
set -euo pipefail
IFS=$'\n\t'
# Ubuntu 16.04, apache2.4
# Don't source it, run like - bash install_phpmyadmin.sh
# You should have MySQL pre-installed
# Prevent source
[[ "${BASH_SOURCE[0]}" != "${0}" ]] && echo -e "\e[91m This script is being sourced, will exit now \e[39m" && return
echo -e "\e[96m Begin silent install phpMyAdmin \e[39m"
# Add phpMyAdmin PPA for latest version
sudo add-apt-repository -y ppa:nijel/phpmyadmin
sudo apt-get update
echo -e "\e[93m User: root, Password: root \e[39m"
# Set non-interactive mode
sudo debconf-set-selections <<< 'phpmyadmin phpmyadmin/dbconfig-install boolean true'
sudo debconf-set-selections <<< 'phpmyadmin phpmyadmin/app-password-confirm password root'
sudo debconf-set-selections <<< 'phpmyadmin phpmyadmin/mysql/admin-pass password root'
sudo debconf-set-selections <<< 'phpmyadmin phpmyadmin/mysql/app-pass password root'
sudo debconf-set-selections <<< 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2'
sudo apt-get -y install phpmyadmin
# Restart apache server
sudo service apache2 restart
# Clean up
sudo apt-get clean
echo -e "\e[92m phpMyAdmin installed successfully \e[39m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment