Skip to content

Instantly share code, notes, and snippets.

@tigercosmos
Forked from y2468101216/php-deploy.md
Created July 14, 2017 14:40
Show Gist options
  • Save tigercosmos/44bca2af306cd0dc480e9fecdee3045b to your computer and use it in GitHub Desktop.
Save tigercosmos/44bca2af306cd0dc480e9fecdee3045b 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 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 -y"

apache 2.4

  1. "sudo apt-get install apache2 -y"
  2. "sudo a2dismod php7.0" disabled apache use php7.0
  3. "sudo a2enmod php7.1" enable apache use php7.1
  4. "cd /etc/apache2/site-enabled"
  5. "vim account-service-write.conf"
  6. paste
<VirtualHost *:80>
	ServerName {your IP}
	DocumentRoot /home/{user}/{your application}/public
	<Directory "/home/{user}/{your application}">
    		AllowOverride all
	</Directory>

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
  1. "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. "GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '{mysql_root_password}';"
  5. "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 ~/lnb-account-service-write"
  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