遇到的问题一、
discuz合适的安装版本是php5.3 ,由于我安装的是最新版的php7.1,所以导致运行时会报错134 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to undefined function set_magic_quotes_runtime() in /usr/local/nginx/html/bbs/install/index.php:12,
解决办法,在install/index.php 中12行删除掉set_magic_quotes_runtime(0) 这个函数。前台页面就可以显示了。其实discuz3.2适合安装的版本是php5.3,
本次安装用的是nginx 源码包、php7.1源码包、mysql用的是二进制包, nginx继上一篇安装
php-7.1.7.tar、nginx-1.8.1.tar php-5.6.31.tar
nginx默认站点目录是:/usr/local/nginx/sbin/nginx
php默认站点目录是:/usr/local/php/sbin/php-fpm
权限设置:chown nginx.nginx/usr/local/nginx/html/ -R
MySQL数据库目录是:/var/lib/mysql
权限设置:chown mysql.mysql -R /var/lib/mysql
卸载了php7.1 后重新安装了php5.6版本,就没有遇到此问题。
一、下载php源码
下载地址:http://cn.PHP.net/downloads.php
二、安装
1、将下载的二进制包移动到/usr/local目录,解压缩文件包
tar zxvf php-5.6.31.tar.gz
2、进入解压的php文件夹下/usr/local/php-5.6.31,安装依赖,编译安装
安装依赖
apt-get install libxml2-dev libssl-dev libbz2-dev libcurl3-dev libdb5.1-dev libjpeg-dev libpng-dev libXpm-dev libfreetype6-dev libt1-dev libgmp3-dev libc-client-dev libldap2-dev libmcrypt-dev libmhash-dev freetds-dev libz-dev libmysqlclient15-dev ncurses-dev libpcre3-dev unixODBC-dev postgresql-server-dev-9.1 libsqlite-dev libaspell-dev libreadline6-dev librecode-dev libsnmp-dev libtidy-dev libxslt-dev libt1-dev
yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel jemalloc jemalloc-devel
yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel jemalloc jemalloc-devel
安装依赖包的时候可能会有提示yun库里面没有这个包,所以要更新下 yum扩展包,和yum源
yum install epel-release //扩展包更新包
yum update //更新yum源
yum install libmcrypt libmcrypt-devel mcrypt mhash
创建 www 用户
groupadd www
useradd -g www -s /sbin/nologin -M www
编译安装
cd /usr/local/test/upload/php-5.6.31
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline
参数说明:
""" 安装路径 """
--prefix=/usr/local/php56 \
""" php.ini 配置文件路径 """
--with-config-file-path=/usr/local/php56/etc \
""" 优化选项 """
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
""" 启用 opcache,默认为 ZendOptimizer+(ZendOpcache) """
--enable-opcache \
""" FPM """
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
""" MySQL """
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
""" 国际化与字符编码支持 """
--with-gettext \
--enable-mbstring \
--with-iconv \
""" 加密扩展 """
--with-mcrypt \
--with-mhash \
--with-openssl \
""" 数学扩展 """
--enable-bcmath \
""" Web 服务,soap 依赖 libxml """
--enable-soap \
--with-libxml-dir \
""" 进程,信号及内存 """
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
""" socket & curl """
--enable-sockets \
--with-curl \
""" 压缩与归档 """
--with-zlib \
--enable-zip \
--with-bz2 \
""" GNU Readline 命令行快捷键绑定 """
--with-readline
make clean
# make && make install
编译安装php时遇到virtual memory exhausted: Cannot allocate memory
php时日志中有如下错误记录:
virtual memory exhausted: Cannot allocate memory
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
将PHP安装配置文件中加了引号中的配置
--disable-fileinfo
做了上述修改后终于编译安装通过
:
cp /usr/local/test/upload/php-5.6.31/php.ini-development /usr/local/php/etc/php.ini
php
-fpm 服务
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/test/upload/php-5.6.31/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
启动 php-fpm
/usr/local/php/sbin/php-fpm
添加 PHP 命令到环境变量
vi /etc/profile
打开后,在文档最下方添加如下配置:
export PATH=/usr/local/php/bin:$PATH
:wq!保存退出,执行如下命令,使更改生效
source /etc/profile
1、配置nginx支持php
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.confbak #备份原有配置文件
vi /usr/local/nginx/conf/nginx.conf #编辑
user root; # nginx 用户修改为root
:wq! #保存退出
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak #备份原有配置文件
vi /usr/local/nginx/conf/nginx.conf #编辑
index index.php index.html index.htm; #增加index.php
# pass the PHPscripts to FastCGI server listening on 127.0.0.1:9000
#
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;
}
#取消FastCGI server下location的注释,并要注意fastcgi_param行的参数,/scripts改为$document_root 或者使用绝对路径
/usr/local/nginx/sbin/nginx -t #检查Nginx配置
/usr/local/nginx/sbin/nginx -s reload # 平滑重启
2、PHP配置
在源码包解压文件里复制出来
cp /usr/local/test/upload/php-5.6.31/php.ini-development /usr/local/php/etc/php.ini
vi /usr/local/php/etc/php.ini #编辑
date.timezone = PRC #在946行 把前面的分号去掉,改为date.timezone = PRC
expose_php = Off #在432行 禁止显示php版本的信息
:wq! #保存退出
2、配置php-fpm
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #备份原有配置文件
vi /usr/local/php/etc/ php-fpm.conf #编辑
user = www #为用户为nginx
group = www #为组为nginx
/etc/init.d/mysqld restart #重启MySql
/usr/local/nginx/sbin/nginx -s reload # 平滑重启 nginx
/usr/local/php/sbin/php-fpm restart #重启php-fpm
5、启动php测试
#启动
/usr/local/php/sbin/php-fpm
#测试php
cd /usr/local/nginx/html
vi test.php
添加如下内容:
<?php
echo phpinfo();
?>
:wq!保存退出。
浏览器输入:http://XXXXXXXX/test.php
如果出现:PHP Version 5.6.31 界面,显示php详细的配置的界面,说明安装正确
6、php重启、停止
/usr/local/php/sbin/php-fpm
2.解压Discuz_X3.2_SC_UTF8.zip,得到3个文件夹(readme,upload,utility)
3.把upload里所有文件复制到/usr/local/nginx/html/bbs/
4.chmod -R 777 /usr/local/nginx/html
bbs 是新建的目录
备注
nginx默认站点目录是:/usr/local/nginx/sbin/nginx
php默认站点目录是:/usr/local/php/sbin/php-fpm
权限设置:chown nginx.nginx/usr/local/nginx/html/ -R
MySQL数据库目录是:/var/lib/mysql
权限设置:chown mysql.mysql -R /var/lib/mysql