编译安装

  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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# 查看老版本的php编译参数
/apps/php/bin/php -i | grep configure

# root 用户,安装依赖包
yum -y install \
libxml2-devel \
openssl-devel \
bzip2-devel \
libcurl-devel \
libjpeg-devel \
libpng-devel \
freetype-devel \
gmp-devel \
libmcrypt-devel \
readline-devel \
libxslt-devel \
sqlite-devel \
oniguruma-devel \
libzip-devel \
ImageMagick-devel

# ec2-user 用户安装php8
## 安装pcre2依赖
umask 002
cd /apps/src/
wget https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.40/pcre2-10.40.tar.gz
tar xf pcre2-10.40.tar.gz
cd pcre2-10.40
./configure --prefix=/apps/pcre2 \
--enable-pcre2-8 \
--enable-pcre2-16 \
--enable-pcre2-32 \
--enable-jit \
--enable-jit-sealloc

make -j4 && make install

export PKG_CONFIG_PATH=/apps/pcre2/lib/pkgconfig/

## 安装php8
cd /apps/src
wget https://www.zlib.net/zlib-1.2.12.tar.gz
tar xf zlib-1.2.12.tar.gz

wget https://www.php.net/distributions/php-8.1.9.tar.gz
tar xf php-8.1.9.tar.gz
cd php-8.1.9/

## 编译
./configure \
--prefix=/apps/php8 \
--with-config-file-path=/apps/php8/etc \
--with-config-file-scan-dir=/apps/php8/etc/php.d \
--with-mysqli \
--enable-mysqlnd \
--with-pdo-mysql \
--with-external-pcre \
--enable-fpm \
--with-fpm-user=ec2-user \
--with-fpm-group=ec2-user \
--enable-gd \
--with-iconv \
--with-zlib \
--enable-xml \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--with-openssl \
--enable-pcntl \
--enable-sockets \
--with-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg \
--enable-exif \
--with-freetype \
--enable-opcache \
--enable-bcmath \
--with-zlib-dir=/apps/src/zlib-1.2.12

## 安装
make -j4 && make install

## 查看版本
/apps/php8/bin/php -v
## 复制配置文件
cp php.ini-production /apps/php8/etc/php.ini
cp /apps/php8/etc/php-fpm.conf.default /apps/php8/etc/php-fpm.conf
cp /apps/php8/etc/php-fpm.d/www.conf.default /apps/php8/etc/php-fpm.d/www.conf

## 查看安装的模块
/apps/php8/bin/php -m


## 安装ImageMagick扩展
cd /apps/src/
wget https://pecl.php.net/get/imagick-3.7.0.tgz
tar xf imagick-3.7.0.tgz
cd imagick-3.7.0
/apps/php8/bin/phpize
./configure --with-php-config=/apps/php8/bin/php-config
make && make install
echo 'extension=imagick.so' >> /apps/php8/etc/php.ini

## 安装xlmrpc扩展
cd /apps/src/
wget https://pecl.php.net/get/xmlrpc-1.0.0RC3.tgz
tar xf xmlrpc-1.0.0RC3.tgz
cd xmlrpc-1.0.0RC3
/apps/php8/bin/phpize
./configure --with-php-config=/apps/php8/bin/php-config
make && make install
echo 'extension=xmlrpc.so' >> /apps/php8/etc/php.ini

## 查看扩展
/apps/php8/bin/php -m

## 修改php.ini配置
sed -i 's|^zend.exception_ignore_args = On|zend.exception_ignore_args = Off|g' /apps/php8/etc/php.ini
sed -i 's|^zend.exception_string_param_max_len = 0|zend.exception_string_param_max_len = 15|g' /apps/php8/etc/php.ini
sed -i 's|^max_execution_time = 30|max_execution_time = 100|g' /apps/php8/etc/php.ini
sed -i 's|^error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT|error_reporting = E_ALL|g' /apps/php8/etc/php.ini
sed -i 's|^display_errors = Off|display_errors = On|g' /apps/php8/etc/php.ini
sed -i 's|^display_startup_errors = Off|display_startup_errors = On|g' /apps/php8/etc/php.ini
sed -i 's|^default_socket_timeout = 60|default_socket_timeout = 300|g' /apps/php8/etc/php.ini
sed -i 's|^mysqlnd.collect_memory_statistics = Off|mysqlnd.collect_memory_statistics = On|g' /apps/php8/etc/php.ini
sed -i 's|^zend.assertions = -1|zend.assertions = 1|g' /apps/php8/etc/php.ini
sed -i 's|^upload_max_filesize = 2M|upload_max_filesize = 64M|g' /apps/php8/etc/php.ini
sed -i 's|^max_file_uploads = 20|max_file_uploads = 64|g' /apps/php8/etc/php.ini
sed -i 's|^post_max_size = 8M|post_max_size = 64M|g' /apps/php8/etc/php.ini
sed -i 's|^memory_limit = 128M|memory_limit = 512M|g' /apps/php8/etc/php.ini
sed -i 's|^zlib.output_compression = Off|zlib.output_compression = On|g' /apps/php8/etc/php.ini
sed -i 's|^;error_log = php_errors.log|error_log = php_errors.log|g' /apps/php8/etc/php.ini
#sed -i 's|^pdo_mysql.default_socket=|pdo_mysql.default_socket=/apps/mysql/mysql/logs/mysql.sock|g' /apps/php8/etc/php.ini
#sed -i 's|^mysqli.default_port = 3306|mysqli.default_port = 3336|g' /apps/php8/etc/php.ini
#sed -i 's|^mysqli.default_socket =|mysqli.default_socket = /apps/mysql/mysql/logs/mysql.sock|g' /apps/php8/etc/php.ini

grep -Ev '^$|;' /apps/php-8.0.21/etc/php.ini > /tmp/php.ini
grep -Ev '^$|;' /apps/php8/etc/php.ini > /tmp/php8.ini
diff /tmp/php.ini /tmp/php8.ini

## 修改php-fpm.conf配置
sed -i 's|^;error_log = log/php-fpm.log|error_log = log/php-fpm.log|g' /apps/php8/etc/php-fpm.conf
sed -i 's|^;log_level = notice|log_level = alert|g' /apps/php8/etc/php-fpm.conf

grep -Ev '^$|;' /apps/php-8.0.21/etc/php-fpm.conf > /tmp/php-fpm.conf
grep -Ev '^$|;' /apps/php8/etc/php-fpm.conf > /tmp/php-fpm8.conf
diff /tmp/php-fpm.conf /tmp/php-fpm8.conf

## 修改www.conf配置
sed -i 's|^pm.max_children = 5|pm.max_children = 64|g' /apps/php8/etc/php-fpm.d/www.conf
sed -i 's|^pm.start_servers = 2|pm.start_servers = 20|g' /apps/php8/etc/php-fpm.d/www.conf
sed -i 's|^pm.min_spare_servers = 1|pm.min_spare_servers = 5|g' /apps/php8/etc/php-fpm.d/www.conf
sed -i 's|^pm.max_spare_servers = 3|pm.max_spare_servers = 35|g' /apps/php8/etc/php-fpm.d/www.conf
sed -i 's|^;pm.max_requests = 500|pm.max_requests = 3000|g' /apps/php8/etc/php-fpm.d/www.conf
sed -i 's|^;php_flag[display_errors] = off|php_flag[display_errors] = off|g' /apps/php8/etc/php-fpm.d/www.conf
sed -i 's|^;rlimit_files = 1024|rlimit_files = 65535|g' /apps/php8/etc/php-fpm.d/www.conf
sed -i 's|^;listen.owner = ec2-user|listen.owner = ec2-user|g' /apps/php8/etc/php-fpm.d/www.conf
sed -i 's|^;listen.group = ec2-user|listen.group = ec2-user|g' /apps/php8/etc/php-fpm.d/www.conf
sed -i 's|^;access.log = log/$pool.access.log|access.log = var/log/$pool.access.log|g' /apps/php8/etc/php-fpm.d/www.conf

grep -Ev '^$|;' /apps/php-8.0.21/etc/php-fpm.d/www.conf > /tmp/www.conf
grep -Ev '^$|;' /apps/php8/etc/php-fpm.d/www.conf > /tmp/www8.conf
diff /tmp/www.conf /tmp/www8.conf

## 测试配置文件
/apps/php8/sbin/php-fpm -t

## 启动
/apps/php8/sbin/php-fpm

# 更换nginx配置
sed -i 's|unix:/apps/php8/run/fastcgi/fastcgi.socket|127.0.0.1:9000|g' /apps/nginx/conf/vhost/example.conf

sudo /apps/nginx/sbin/nginx -t
sudo /apps/nginx/sbin/nginx -s reload