CentOS通过源码安装PHP
安装必要的库文件和工具
sudo yum install autoconf libtool re2c bison libxml2-devel bzip2-devel libcurl-devel libpng-devel libicu-devel gcc-c++ libmcrypt-devel libwebp-devel libjpeg-devel openssl-devel -y
下载PHP并上传到服务器中,解压到制定文件夹中
- php下载地址
- 上传到服务器中
scp ./php.tar.gz user@centos:~/php
- 登录到服务器中,进行相关的操作
ssh -i ./ssh_key user@centos
cd ~/php && tar-xzvf php.tar.gz
创建
configure
文件sudo ./buildconf --force
使用
configure
1 | sudo ./configure \ |
编译php文件并安装
sudo make clean && sudo make && sudo make install
配置php-fpm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23cd /usr/local/php/etc/
sudo cp ./php-fpm.conf.default ./php-fpm.conf
sudo vi php-fpm.conf
//[insert]
include =etc/fpm.d/*.conf
pid = /var/run/php-fpm.pid
error_log = /var/log/php-fpm.log
cd php-fpm.d
sudo cp www.conf.default www.conf
vi www.conf
//[insert]
[www]
user = nginx
group = nginx
listen = 127.0.0.1:9000
catch_workers_output = yes
slowlog = /var/log/php-fpm.slow.log
request_slowlog_timeout = 30s
php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/php-fpm.error.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 64M
;php_admin_value[open_basedir] = /var/www配置php.ini文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24sudo cp ~/php/php.ini-develop /usr/local/php/lib/php.ini
cd /usr/local/php/lib
sudo vi php.ini
//[insert]
short_open_tag = On
;open_basedir = /var/www
disable_functions = exec,passthru,shell_exec,system,proc_open,popen
expose_php = Off
max_execution_time = 30
memory_limit = 64M
date.timezone = Europe/Warsaw
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
post_max_size = 5M
upload_max_filesize = 4M
opcache.enable=1
opcache.memory_consumption=64
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=7000
opcache.validate_timestamps=0 ;set this to 1 on production server
opcache.fast_shutdown=1创建php-fpm启动脚本
1
2
3
4
5
6
7
8
9cd /etc/init.d
sudo cp ~/php/sapi/fpm/init.php-fpm ./php-fpm && sudo chmod +x php-fpm
sudo vi php-fpm
//[insert]
prefix=/usr/local/php
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.d/*.conf
php_fpm_PID=/var/run/php-fpm.pid创建php-fpm服务
sudo chkconfig -add php-fpm
sudo chkconfig php-fpm on
测试php-fpm并启动
sudo /etc/init.d/php-fpm configtest
sudo systemctl start php-fpm
配置nginx支持php
1
2
3
4
5
6
7
8
9
10cd /etc/nginx && sudo cp nginx.conf nginx.conf.old
sudo vi nginx.conf
//[insert]
location ~ \.php$ {
root /var/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}- 重启nginx服务
sudo service nginx restart
- 重启nginx服务
参考