重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
原有的项目都为java项目 所以现有的环境为nginx+tomcat
创新互联是一家专业提供陇西企业网站建设,专注与做网站、成都做网站、H5建站、小程序制作等业务。10年已为陇西众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。
现在要添加一个php环境
在编译安装php前,要先查看下nginx的运行用户,php也用用同样的用户
编译安装php
根据自己想需求选择相应的软件环境
for packages in patch make cmake gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap;do yum -y install $packages; done
在这里我选择php5.3的版本
wget -c http://soft.vpser.net/web/php/php-5.3.17.tar.gz
选择php5.3版本编译MySQL时不需要指定mysql路径,可用以下参数进行编译
--with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-mysql=mysqlnd
开始编译
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=nobody --with-fpm-group=nobody --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo
编译完后
make&&make install
编译时报错信息及解决方法
在Linux下安装PHP过程中,编译时出现configure: error: libjpeg.(a|so) not found 错误的解决办法
检查之后发现已经安装了libjpeg,但是在/usr/lib目录下没有libjpeg.so这个文件,在/usr/lib64下是有的
所以建立个软链接
ln -s /usr/lib64/libjpeg.so /usr/lib/libjpeg.so
问题解决, libpng 报的错误解决方法一样
ln -s /usr/lib64/libjpeg.so /usr/lib/libjpeg.so
configure: error: freetype.h not found.
gamedb:/data/soft/php-5.2.17 # zypper install freetype2-devel
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
gamedb:/data/soft/php-5.2.17 # zypper install libmcrypt libmcrypt-devel
configure: error: Please reinstall libmhash - I cannot find mhash.h
gamedb:/data/soft/php-5.2.17 # zypper install mhash-devel
拷贝配置文件到安装目录中
cp php-5.3.17/php.ini-production /usr/local/php/etc/php.ini
配置文件放错位置的话也会导致项目异常
cd /usr/local/php/etc/ # 切换到安装目录下的配置文件目录 cp php-fpm.conf.default php-fpm.conf
vi php-fpm.conf
启用如下几行,即去掉前面的分号(;)
pid = run/php-fpm.pid error_log = log/php-fpm.log log_level = notice listen = 127.0.0.1:9000 listen.allowed_clients = 127.0.0.1 pm = dynamic pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp
wq保存退出
# /usr/local/php/sbin/php-fpm (启动PHP)
# netstat -antpl (如果看到9000端口,PHP-FPM配置成功)
注意:如果修改php.ini文件,则需要重启php-fpm进程使生效。
最后配置项目的nginx的配置文件使php和nginx链接
gamedb:/opt/nginx/conf/vhost # cat gzqq_2014.conf server { listen 81; server_name www.abc.net; index index.php index.html index.htm; root /data/web/abc/default; #root /data/web/abc; location ~ .*\.(php|php5)?$ { try_files $uri =404; #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } location /status { stub_status on; access_log off; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } #access_log /home/wwwlogs/access.log access; #error_log /home/wwwlogs/qzqq_erro.log; }