安装
云安装
yum install php //安装php(云安装的版本php5,其他版本需要手动下载安装)
手动安装: php版本 http://www.php.net/downloads.php
// 下载 wget http://cn2.php.net/distributions/php-7.0.30.tar.gz // 创建php目录 cd /usr/local mkdir php
安装php依赖库
configure: error: xml2-config not found. Please check your libxml2 installation. // 报错
yum install libxml2
yum install libxml2* -y
configure: error: png.h not found. // 报错
yum install libpng
yum install libpng-devel
configure: error: mcrypt.h not found. Please reinstall libmcrypt. // 报错
yum install -y epel-release
yum install -y libmcrypt-devel
两个不能一起安装,因为CentOs6默认的yum源没有 libmcrypt-devel这个包,只能借助epel的yum源,所以先安装epel,再安装
libmcrypt。
编译安装php
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-mysql --with-mysqli --with-gd --with-zlib --with-mcrypt --enable-fpm
make && make install
安装完成后,别忘记 make test
【注意:下载的php,容易出现解压报错和php地址不对】
nginx配置php 路径/usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.html index.htm index.php;
}
2.
cd /down/ ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-libxml-dir=/usr/local/libxml2 //检测是否满足安装 make // 编译 make install // 安装
方法二:
// 优先装epel yum install -y epel-release
两个不能一起安装,因为CentOs6默认的yum源没有 libmcrypt-devel这个包,只能借助epel的yum源,所以先安装epel,再安装
libmcrypt。
//须要安装须要的模块,直接yum一并安装依赖库 yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel libmcrypt-devel
// 配置 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-mysql --with-mysqli --with-gd --with-zlib --with-mcrypt --enable-fpm // 编译安装 make && make install
方法三:
// 优先装epel yum install -y epel-release // 安装依赖库 yum install libxml2* libpng libpng-devel libmcrypt-devel // 配置 (此操作必须要进入 cd /down/php-7.0.30 目录下) ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-mysql --with-mysqli --with-gd --with-zlib --with-mcrypt --enable-fpm // 编译并且安装 make && make install
// 安装完成后会有提示让你make test
make test
// make test完成后 会提示
Thank you for helping to make PHP better.
方法四:
// 优先装epel
yum install -y epel-release
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel libmcrypt-devel
// 配置 (此操作必须要进入 cd /down/php-7.0.30 目录下)
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-mysql --with-mysqli --with-gd --with-zlib --with-mcrypt --enable-fpm
make && make install
方法五(已测试):
安装依赖库
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel
注意:安装php7beta3的时候有几处配置只是去,须要yum一下。如今php-7.0.2已经不用这样了。
# yum -y install curl-devel
# yum -y install libxslt-devel
如果提示 可以安装curl-devel
configure: error: cURL version 7.10.5 or later is required to compile php with cURL support
配置
./configure --help
./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
// 编译 & 安装
make && make install
配置文件
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
# /etc/init.d/php-fpm
#location ~ .php$ { 找到 # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} location ~ .php$ { 改为 root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
建立index.php 内容为
<?php
phpinfo()
?>
最后重启
service nginx restart 或者./nginx -s reload 重启nginx
service php-fpm restart 或者 /etc/init.d/php-fpm 重启 php-fpm
报错:
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/down/php-7.0.30/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/
参考:https://blog.csdn.net/sayyy/article/details/78556860?locationNum=3&fps=1
故障:
重启nginx报错,提示:
[emerg] open() “/var/run/nginx/nginx.pid” failed (2: No such file or directory)
解决:在var/run/下建立一个文件夹命名为nginx,然后:
[root@localhost ~]# /usr/local/nginx/sbin/nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload
或者
解决方法:
1. 重新运行一下 sudo /usr/share/nginx/sbin/nginx
2. 重启nginx:sudo /usr/share/nginx/sbin/nginx -s reload