-
Notifications
You must be signed in to change notification settings - Fork 1
/
lightsail-centos-lemp.sh
135 lines (107 loc) · 4.33 KB
/
lightsail-centos-lemp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# This bash script installs LEMP on centos7 (tested with version 1901-01
# provided by lightsail service).
# Implements prerequisite steps from:
# https://devdocs.magento.com/guides/v2.3/install-gde/prereq/nginx.html#centos-7
# read command line params
# default PHP version (7.3 may be requested by using
# --php-version 7.3 command-line switch)
PHP_VERSION=7.2
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--php-version)
if [ $2 == '7.3' ]; then
PHP_VERSION=7.3
fi
shift; # past argument
shift; # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
# install required tools
yum -y install unzip wget
# install and start nginx
yum -y install epel-release
yum -y install nginx
systemctl start nginx
systemctl enable nginx
# install php 7.0
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# yum -y install php70w-fpm php70w
# yum -y install php70w-pdo php70w-mysqlnd php70w-opcache php70w-xml php70w-gd php70w-devel php70w-mysql php70w-intl php70w-mbstring php70w-bcmath php70w-json php70w-iconv php70w-soap
# install php. 7.2 is the default, 7.3 can be requested by adding
# --php-version 7.3 command line param.
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install -y yum-utils
yum-config-manager --disable remi-php54
yum-config-manager --enable remi-php${PHP_VERSION//.}
yum -y install php-fpm php
yum -y install php-pdo php-mysqlnd php-opcache php-xml php-gd php-devel php-mysql php-intl php-mbstring php-bcmath php-json php-iconv php-soap php-pecl-zip
# reconfigure php
cp /etc/php.ini /etc/php.ini.0
sed -i '/cgi.fix_pathinfo\s*=/s/^\s*;//g' /etc/php.ini
sed -i '/cgi.fix_pathinfo\s*=/s/=.*$/=1/g' /etc/php.ini
sed -i '/memory_limit\s*=/s/=.*$/=2G/g' /etc/php.ini
sed -i '/max_execution_time\s*=/s/=.*$/=1800/g' /etc/php.ini
sed -i '/zlib.output_compression\s*=/s/=.*$/=On/g' /etc/php.ini
sed -i '/^;session.save_path\s*=/s/^;//g' /etc/php.ini
sed -i '/^session.save_path\s*=/s/=.*$/="\/var\/lib\/php\/session"/g' /etc/php.ini
# reconfigure php-fpm
cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.0
sed -i '/^user\s*=/s/=.*$/= nginx/g' /etc/php-fpm.d/www.conf
sed -i '/^group\s*=/s/=.*$/= nginx/g' /etc/php-fpm.d/www.conf
sed -i '/^listen\s*=/s/=.*$/= \/run\/php-fpm\/php-fpm.sock/g' /etc/php-fpm.d/www.conf
sed -i '/listen.owner\s*=/s/^\s*;//g' /etc/php-fpm.d/www.conf
sed -i '/^listen.owner\s*=/s/=.*$/= nginx/g' /etc/php-fpm.d/www.conf
sed -i '/listen.group\s*=/s/^\s*;//g' /etc/php-fpm.d/www.conf
sed -i '/^listen.group\s*=/s/=.*$/= nginx/g' /etc/php-fpm.d/www.conf
sed -i '/listen.mode\s*=/s/^\s*;//g' /etc/php-fpm.d/www.conf
sed -i '/^listen.mode\s*=/s/=.*$/= 0660/g' /etc/php-fpm.d/www.conf
sed -i '/^;env\[\(HOSTNAME\|PATH\|TMP\|TMPDIR\|TEMP\)\]/s/^;//g' /etc/php-fpm.d/www.conf
mkdir -p /var/lib/php/session/
chown -R nginx:nginx /var/lib/php/
mkdir -p /run/php-fpm/
chown -R nginx:nginx /run/php-fpm/
# allow login as nginx and change home directory
service nginx stop
usermod --shell /bin/bash --home /var/www/html nginx
service nginx start
# chown the target directory to nginx
chown nginx.nginx /var/www/html
# start php-fpm
systemctl start php-fpm
systemctl enable php-fpm
cd /root
# install mysql 5.7 (only if the data directory doesn't exist yet)
if [ ! -d /var/lib/mysql ]; then
wget https://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum -y localinstall mysql57-community-release-el7-7.noarch.rpm
yum -y install mysql-community-server
# reset root password in mysql
service mysqld stop
ls -l /var/lib/mysql > /root/mysql-dir.lst
bck_dir=/var/lib/mysql-`date +%s`
mkdir $bck_dir
mv /var/lib/mysql/* $bck_dir/
mysqld --initialize-insecure --user=mysql
# TODO: may need to add performance enhancements in my.cnf
# start mysql and add magento database and user (w/o password)
service mysqld start
systemctl enable mysqld
mysql -u root <<SQL
create database magento;
create user magento;
GRANT ALL PRIVILEGES ON magento.* TO magento;
flush privileges;
SQL
fi
# install composer globally
curl -s https://getcomposer.org/installer > /root/composer_installer.php
HOME=/root/ /bin/php /root/composer_installer.php --install-dir=/usr/bin --filename=composer > /root/composer_install.log 2>&1