linux下编译安装npm服务
PHP安装
1、安装依赖
apt-get install curl vim wget unzip apt-transport-https lsb-release ca-certificates build-essential autoconf automake libtool bison re2c libxml2-dev libssl-dev libbz2-dev libjpeg-dev libpng-dev libxpm-dev libfreetype6-dev libgmp-dev libgmp3-dev libmcrypt-dev libpspell-dev librecode-dev libcurl4-gnutls-dev libgmp-dev libgmp3-dev librecode-dev libpspell-dev libmcrypt-dev libreadline-dev libtidy-dev libxslt1-dev gcc make libxml2 default-libmysqlclient-dev libzip4 libzip-dev
2、下载并解压php源码
3、配置安装
./configure --prefix=/usr/local/src/php --with-config-file-path=/etc/php --with-fpm-user=www-data --with-fpm-group=www-data --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-freetype-dir --with-libxml-dir --with-xmlrpc --with-openssl --with-mhash --with-pcre-regex --with-sqlite3 --with-pdo-sqlite --with-readline --with-zlib --with-gettext --with-pear --with-mysqli --with-pdo-mysql --with-xsl --with-iconv --with-bz2 --with-curl --with-libzip --with-libmbfl --with-onig --with-zlib-dir --with-cdb --with-gmp --with-pcre-dir --with-ldap --with-ldap-sasl --disable-debug --disable-rpath --enable-opcache --enable-fpm --enable-inline-optimization --enable-shared --enable-soap --enable-bcmath --enable-dom --enable-pcntl --enable-exif --enable-fileinfo --enable-filter --enable-ftp --enable-gd-jis-conv --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --enable-pdo --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --enable-zip --enable-mysqlnd-compression-support --enable-opcache --enable-calendar
--prefix #指定php安装目录
--with-mysql #指定mysql安装目录
--with-mysqli #添加mysqli扩展支持
--with-openssl #指定openssl安装目录
--with-png-dir #GD所需的png库
--with-jpeg-dir #GD所需的jpeg库
--with-freetype-dir #指定freetype字体库
--with-iconv-dir #指定iconv函数库,用于字符集转换
--with-gd #指定GD库目录
--enable-gd-native-ttf #添加TrueType字符串函数库
--with-libxml-dir #指定libxml2库目录
--with-zlib #压缩库目录
--with-mhash #指定哈希函数库目录
--with-mcrypt #指定mcrypt加密函数库
--with-ldap #指定ldap库
--with-curl #指定cURL库
--with-curlwrappers #运用curl工具打开url流
--enable-bcmath #高精度数学函数支持
--enable-calendar #开启对日历的支持
--enable-mbstring #多字节、字符串支持
--enable-ftp #开启对ftp的支持
--enable-zip #开启对zip的支持
--enable-sockets #开启sockets支持
--enable-exif #图片元数据支持
--enable-zend-multibyte #zend多字节的支持
--enable-fpm #开启FastCGI的进程管理支持
--with-fpm-user #运行fpm的用户
--with-fpm-user #运行fpm的组
make && make install
配置 php-fpm
cp /usr/local/src/php/etc/php-fpm.conf.default /usr/local/src/php/etc/php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
开机自动重启 php-fpm
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
update-rc.d php-fpm defaults
php-fpm指定php.ini路径(适用于nginx访问)
/usr/local/php/sbin/php-fpm(install dir) -y /etc/php-fpm.conf(配置文件) -c /etc/php.ini(php.ini地址)
php-fpm和nginx使用unix socket方式通信
cd /tmp
touch php-fpm.sock
进入php-fpm.d找到www.conf,在里面修改listen = 127.0.0.1:9000为
listen = /tmp/php-fpm.sock
然后到nginx修改配置文件
把fastcgi_pass 127.0.0.1:9000;改为fastcgi_pass unix:/tmp/php-fpm.sock;
*错误configure: error: no acceptable C compiler found in $PATH,执行
apt-get install build-essential
安装c,gcc之类的东西
*错误configure: error: Cannot find OpenSSL's libraries,解决方案
ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/
或者编译安装
wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz tar zxf openssl-1.0.2k.tar.gz cd openssl-1.0.2k ./config make && make install
*错误configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/,解决方案:
1.sudo apt-get install libcurl4-gnutls-dev 2.cd /usr/include sudo ln -s x86_64-linux-gnu/curl *错误configure: error: freetype-config not found.,解决方案:
apt-get install libfreetype6-dev
*错误configure: error: Unable to locate gmp.h解决方案:
apt-get install libgmp-dev
*错误configure: error: Please reinstall readline - I cannot find readline.h,解决方案:
apt-get install libreadline-dev
nginx开机启动脚本
#!/bin/bash
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
# Author: licess
# website: http://lnmp.org
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
NGINX_BIN=/usr/local/nginx/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/$NAME.pid
case "$1" in
start)
echo -n "Starting $NAME... "
if netstat -tnpl | grep -q nginx;then
echo "$NAME (pid `pidof $NAME`) already running."
exit 1
fi
$NGINX_BIN -c $CONFIGFILE
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Stoping $NAME... "
if ! netstat -tnpl | grep -q nginx; then
echo "$NAME is not running."
exit 1
fi
$NGINX_BIN -s stop
if [ "$?" != 0 ] ; then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;;
status)
if netstat -tnpl | grep -q nginx; then
PID=`pidof nginx`
echo "$NAME (pid $PID) is running..."
else
echo "$NAME is stopped"
exit 0
fi
;;
force-quit)
echo -n "Terminating $NAME... "
if ! netstat -tnpl | grep -q nginx; then
echo "$NAME is not running."
exit 1
fi
kill `pidof $NAME`
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
reload)
echo -n "Reload service $NAME... "
if netstat -tnpl | grep -q nginx; then
$NGINX_BIN -s reload
echo " done"
else
echo "$NAME is not running, can't reload."
exit 1
fi
;;
configtest)
echo -n "Test $NAME configure files... "
$NGINX_BIN -t
;;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
exit 1
;;
esac
exit 0