创建用户和组
useradd -s /sbin/nologin -M www
安装组件
yum install -y libxml2 libxml2-devel libxml2-python curl curl-devel libjpeg libjpeg-devel libpng libpng10 libpng10-devel libpng-devel freetype-devel libmcrypt libmcrypt-devel gd gd-devel gcc-c++ gcc openssl openssl-devel
开始安装
wget -O php7.tar.gz http://cn2.php.net/get/php-7.2.0.tar.gz/from/this/mirror tar zxvf php7.tar.gz -C /usr/src/ cd /usr/src/php-7.2.0 ./configure --prefix=/usr/local/php \ --enable-opcache \ --with-config-file-path=/usr/local/php/etc \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --enable-fpm \ --enable-static \ --enable-inline-optimization \ --enable-sockets \ --enable-wddx \ --enable-zip \ --enable-calendar \ --enable-bcmath \ --enable-soap \ --enable-mbstring \ --with-zlib \ --with-iconv \ --with-gd \ --with-xmlrpc \ --enable-mbstring \ --with-curl \ --with-freetype-dir \ --with-mysql-sock=/tmp/mysql.sock \ --with-jpeg-dir \ --with-png-dir \ --disable-ipv6 \ --disable-debug \ --with-openssl \ --disable-maintainer-zts \ --disable-fileinfo make make install
wordpress必要的PHP扩展
若你的服务器上只有一个wordpress网站,那么我们就没必要开启过多的PHP扩展,用下面的编译参数就能把wordpress跑起来,其实configure的参数就是在开启或者关闭一些PHP的附加功能,功能少,运行起来占用的内存就小。
./configure --prefix=/usr/local/php \ --enable-opcache \ --with-config-file-path=/usr/local/php/etc \ --with-curl \ --enable-fpm \ --enable-ftp \ --with-gd \ --with-iconv \ --enable-mbstring \ --with-mysqli=mysqlnd \ --with-openssl \ --enable-static \ --enable-sockets \ --enable-inline-optimization \ --with-zlib \ --disable-ipv6 \ --disable-fileinfo \ --disable-debug make make install
复制配置文件以及启动脚本
cp php.ini-production /usr/local/php/etc/php.ini #adjust php.ini sed -i 's#; extension_dir = \"\.\/\"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/"#' /usr/local/php/etc/php.ini sed -i 's/post_max_size = 8M/post_max_size = 64M/g' /usr/local/php/etc/php.ini sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 64M/g' /usr/local/php/etc/php.ini sed -i 's/;date.timezone =/date.timezone = PRC/g' /usr/local/php/etc/php.ini sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /usr/local/php/etc/php.ini #adjust php-fpm cd /usr/local/php/etc cp php-fpm.conf.default php-fpm.conf [root@hqidi etc]# grep ^[a-Z] php-fpm.conf pid = run/php-fpm.pid include=/usr/local/php/etc/php-fpm.d/*.conf cd /usr/local/php/etc/php-fpm.d cp www.conf.default www.conf sed -i 's,user = nobody,user = www,g' /usr/local/php/etc/php-fpm.d/www.conf sed -i 's,group = nobody,group = www,g' /usr/local/php/etc/php-fpm.d/www.conf sed -i 's,listen.mode = 0660,listen.mode = 0666,g' /usr/local/php/etc/php-fpm.d/www.conf sed -i 's,^pm.min_spare_servers = 1,pm.min_spare_servers = 8,g' /usr/local/php/etc/php-fpm.d/www.conf sed -i 's,^pm.max_spare_servers = 3,pm.max_spare_servers = 20,g' /usr/local/php/etc/php-fpm.d/www.conf sed -i 's,^pm.max_children = 5,pm.max_children = 23,g' /usr/local/php/etc/php-fpm.d/www.conf sed -i 's,^pm.start_servers = 2,pm.start_servers = 12,g' /usr/local/php/etc/php-fpm.d/www.conf sed -i 's,;pid = run/php-fpm.pid,pid = run/php-fpm.pid,g' /usr/local/php/etc/php-fpm.d/www.conf sed -i 's,;error_log = log/php-fpm.log,error_log = /data/log/php/php-fpm.log,g' /usr/local/php/etc/php-fpm.d/www.conf sed -i 's,;slowlog = log/$pool.log.slow,slowlog = /data/log/php/\$pool.log.slow,g' /usr/local/php/etc/php-fpm.d/www.conf echo "listen = /usr/local/php/var/run/php-fpm.sock" >>/usr/local/php/etc/php-fpm.d/www.conf
服务管理
➤centos 6
install -v -m755 /usr/src/php-7.2.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chkconfig --add php-fpm chkconfig --level 35 php-fpm on
➤centos 7
cp /usr/src/php-7.2.0/sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service systemctl enable php-fpm.service
原创文章,转载请注明: 转载自笛声
本文链接地址: Centos 6.5 x64安装php 7.2
4 条评论
不要报错信息,整理出一个能直接复制粘贴就能安装好的文档比较好。
文中没有开启opcache .
yum install -y libxml2 libxml2-devel libxml2-python curl curl-devel libjpeg libjpeg-devel libpng libpng12 libpng12-devel libpng-devel freetype-devel libmcrypt libmcrypt-devel gd gd-devel gcc-c++ gcc openssl openssl-devel
[…] 当你照着 此文 安装好PHP,并做好systemd服务管理文件,你会发现用systemctl start php-fpm 无法正常启动php-fpm 报了一个很奇怪的错。ERROR: failed to open error_log (/usr/local/php/var/log/php-fpm.log): Read-only file system (30)此时,selinux是关闭状态,普通用户对这个文件也可写,问题就迷离了。解决方法:打开 /usr/lib/systemd/system/php-fpm.service 把ProtectSystem=true改成ProtectSystem=false […]