Skip to content

Instantly share code, notes, and snippets.

@y2468101216
Last active March 7, 2018 07:10
Show Gist options
  • Save y2468101216/36dab352235a4f9363f47f76ea7efc24 to your computer and use it in GitHub Desktop.
Save y2468101216/36dab352235a4f9363f47f76ea7efc24 to your computer and use it in GitHub Desktop.
how to deploy php mysql apache2

php-deploy

required

  1. ubuntu 16.04
  2. php 7.1
  3. apache 2.4
  4. mysql 5.7
  5. git & composer

ubuntu

  1. "sudo dpkg-reconfigure tzdata" : set system timezone
  2. "sudo apt-get update"

php

  1. "sudo add-apt-repository ppa:ondrej/php" : add php offical repository
  2. "sudo apt-get update"
  3. "sudo apt-get -y install php7.1 php7.1-common php7.1-zip php7.1-xml php7.1-mbstring php7.1-mysql php7.1-mcrypt php7.1-cli libapache2-mod-php7.1"

apache 2.4

  1. "sudo apt-get -y install apache2"
  2. "sudo a2dismod php5" : disabled apache use php5
  3. "sudo a2dismod php7.0" : disabled apache use php7.0
  4. "sudo a2enmod php7.1" : enable apache use php7.1
  5. "sudo a2enmod rewrite" : enable apache use rewrite
  6. "cd /etc/apache2/sites-available"
  7. "vim {name}.conf"
  8. paste
<VirtualHost *:80>
	ServerName {your IP}
	DocumentRoot /path/to/public
	<Directory "/path/to/{your application}">
    		AllowOverride all
	</Directory>

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
  1. (option) http to https
<VirtualHost *:80>

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

</VirtualHost>
  1. "ln -s /etc/apache2/sites-available/{name}.conf /etc/apache2/sites-enabled/{name}.conf"
  2. "rm /etc/apache2/sites-enabled/000-default.conf" : remove default conf
  3. "sudo service apache2 restart"

mysql

suggest use different account for application and root

  1. "sudo apt-get install mysql-server"
  2. "mysql -u root -p"
  3. after into mysql : "create database {your database name}"
  4. CREATE USER 'application'@'%' IDENTIFIED BY 'application';
  5. "GRANT ALL ON {your database name}.* TO 'application'@'%';"
  6. "FLUSH PRIVILEGES;"

mysql master-slave (option)

  1. first build master mysql & slave mysql
  2. master mysql : "GRANT REPLICATION SLAVE ON . TO 'repl'@'%' IDENTIFIED BY 'repl';"
  3. master : "sudo vim /etc/my.cnf"
  4. paste :
server-id = 1
default-character-set = utf8
default-storage-engine = innodb
bind-address = 0.0.0.0
log-bin = mysql-bin
binlog_format = row
log_slave_updates = 1
expire_logs_days = 7
gtid-mode = ON
enforce-gtid-consistency = ON
  1. master : "sudo service mysql restart"
  2. slave : "sudo vim /etc/my.cnf"
  3. paste :
server-id = 2
default-character-set = utf8
default-storage-engine = innodb
bind-address = 0.0.0.0
log-bin = mysql-bin
binlog_format = row
log_slave_updates = 1
expire_logs_days = 7
gtid-mode = ON
enforce-gtid-consistency = ON
  1. slave mysql : "CHANGE MASTER TO MASTER_HOST='{master_mysql_ip}', MASTER_PORT={master_mysql_port},MASTER_USER='repl', MASTER_PASSWORD='repl',MASTER_AUTO_POSITION = 1;"
  2. slave mysql : "START SLAVE;"
  3. check mysql salve is ok : "show slave status\G"

git and composer (on php server)

  1. "sudo apt-get install git -y"
  2. "sudo curl -sS https://getcomposer.org/installer -o composer-setup.php"
  3. "sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer"
  4. "sudo rm composer-setup.php"

deploy

  1. "sudo mkdir ~/{your application}"
  2. "cd ~/{your application}"
  3. "git clone {remote git repository}"
  4. "composer install"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment