Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ubuntu 18.04 - PHP development (php 7.2, MySQL 5.7, apache 2.4)
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Ubuntu 18.04 dev Server
# Run like - bash install_lamp.sh
# Script should auto terminate on errors
echo -e "\e[96m Adding PPA \e[39m"
sudo add-apt-repository -y ppa:ondrej/apache2
sudo add-apt-repository -y ppa:ondrej/php
#sudo apt-get update
echo -e "\e[96m Installing apache \e[39m"
sudo apt-get -y install apache2
echo -e "\e[96m Installing php \e[39m"
sudo apt-get -y install php7.2 libapache2-mod-php7.2
# Install some php exts
sudo apt-get -y install curl php7.2-mysql php7.2-curl php7.2-json php7.2-mbstring php7.2-gd php7.2-intl php7.2-xml php7.2-zip php-gettext php7.2-pgsql
#sudo apt-get -y install php-xdebug
sudo phpenmod curl
# Enable some apache modules
sudo a2enmod rewrite
sudo a2enmod ssl
#sudo a2enmod headers
#sudo a2enmod gzip
echo -e "\e[96m Restart apache server to reflect changes \e[39m"
sudo service apache2 restart
echo -e "\e[96m Installing 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
# Download and install composer
echo -e "\e[96m Installing composer \e[39m"
# Notice: Still using the good old way
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
# Add this line to your .bash_profile
# export PATH=~/.composer/vendor/bin:$PATH
# 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 "\nYour PHP installation is working fine.\n";'
# Fix composer folder permissions
sudo chown -R $USER $HOME/.composer
# Check composer version
composer --version
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 18.04+, apache2.4, php 7.x
# Run like - bash install_phpmyadmin.sh
# You should have MySQL pre-installed
echo -e "\e[96m Begin silent install phpMyAdmin \e[39m"
# Add phpMyAdmin PPA for latest version
# Warning!!! Don't add this PPA if you are running php v5.6
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"
echo -e "\e[92m Remember: password for root user is root \e[39m"
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Ubuntu 18.04 +
# Script will auto terminate on errors
# run like - bash script_name.sh
# Install latest git
sudo add-apt-repository -y ppa:git-core/ppa
#sudo apt-get update
sudo apt-get -y install git gitk
# My Git Configs
git config --global --add merge.ff false
git config --global push.followTags true
git config --global core.autocrlf false
git config --global push.default simple
git config --global color.ui auto
git config --global branch.autosetuprebase always
git config --global core.compression 9
git config --global credential.helper 'cache --timeout 28800'
git config --global core.filemode false
git config --global core.editor "nano"
git config --global core.excludesfile '~/.gitignore'
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.logout 'credential-cache exit'
# Clean up
sudo apt-get clean
# Check for git version
git --version

Postgresql on Ubuntu 16.04

Add PPA Source

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" >> /etc/apt/sources.list.d/pgdg.list.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt update

Install

sudo apt install postgresql-10

Start/stop postgresql service

sudo service postgresql start
sudo service postgresql stop
sudo service postgresql restart

Access psql prompt

sudo -u postgres psql

Type \q and enter to exit prompt.

Create a new postgres user

  • By default postgres comes with a special user named postgres but we will not be using this for our web apps.
  • This user is to perform administration only. So lets create a new user with the help of this user.
sudo -u postgres createuser --interactive --pwprompt

Answer the questions asked.

Create a new database

sudo -u postgres createdb --owner=user_name db_name_goes_here

If you dont have the user_name as a linux user in your machine then you need to add, otherwise you will get unable to initialize policy plugin error on terminal. This is called Ident authentication in postgres.

# create missing linux user
sudo adduser user_name

You can omit --owner=user_name parameter if db_name is same as user_name.

Login to psql prompt via this user

sudo -u user_name psql db_name

Connect to database

Host: 127.0.0.1
Post: 5432
User: user_name_you_created_above
Password: this_should_be_the_postgres_user_password
Database: db_name_you_just_created

Delete database

sudo -u postgres dropdb db_name

Delete user

sudo -u postgres dropuser user_name

Import/export database

# export
pg_dump -U user_name db_name > dbexport.pgsql
# import 
pg_dump -U user_name db_name < dbexport.pgsql

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.