centos下编译安装lnmp
centos下编译安装lnmp
本文以centos为背景在其中编译安装nginx搭建lnmp环境。
编译安装nginx时,需要事先安装 开发包组"Development Tools"和"Server Platform Development",同时还需专门安装pcre-devel包。
安装命令
yum -y groupinstall "Development Tools"
yum -y groupinstall "Development Tools"
yum -y groupinstall "Server Platform Development"
创建nginx运行的用户和用户组
groupadd -r nginx
useradd -g nginx -r nginx
创建编译安装时需要的目录( --http-client-body-temp-path=)
mkdir -pv /var/tmp/nginx/client
下载nginx源码 此处我下载的是nginx-1.4.7
cd /usr/local/src
wget http://mirrors.sohu.com/nginx/nginx-1.4.7.tar.gz
tar xf nginx-1.4.7.tar.gz
cd nginx-1.4.7
./configure \--prefix=/usr/local/nginx \--sbin-path=/usr/local/nginx/sbin/nginx \--conf-path=/etc/nginx/nginx.conf \--error-log-path=/var/log/nginx/error.log \--http-log-path=/var/log/nginx/access.log \--pid-path=/var/run/nginx/nginx.pid \--lock-path=/var/lock/nginx.lock \--user=nginx \--group=nginx \ --with-http_ssl_module \--with-http_flv_module \--with-http_stub_status_module \--with-http_gzip_static_module \--http-client-body-temp-path=/var/tmp/nginx/client/ \--http-proxy-temp-path=/var/tmp/nginx/proxy/ \--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \--http-scgi-temp-path=/var/tmp/nginx/scgi \--with-pcre
make && make install
创建nginx SysVinit脚本
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
为脚本添加可执行权限
chmod +x /etc/rc.d/init.d/nginx
添加nginx开机自启动
chkconfig --add nginx
chkconfig nginx on
编辑nginx配置文件
vi /etc/nginx/nginx.conf
location ~ \.php$ {
fastcgi_pass 10.170.2.90:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
}
在server内添加网站的根目录 /var/www/html
启动nginx
/etc/init.d/nginx start
测试是否启动成功
curl 127.0.0.1
应该看到 welcome to nginx
此时nginx告一段落
安装php切换到源码目录
cd /usr/local/src
wget http://am1.php.net/distributions/php-5.6.28.tar.bz2
tar xf php-5.6.28.tar.bz2
cd php-5.6.28
./configure --prefix=/usr/local/php5 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
如果有错误提示根据相应的提示安装
我这里提示了2个问题
xml2-config not found. Please check your libxml2 installation.
按如下命令安装yum install libxml2-devel -ymcrypt.h not found. Please reinstall libmcrypt
按照如下方法解决 源码安装libmcryptcd /usr/local/src
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure --prefix=/usr/local
make
make install
继续切换到php源码目录
cd /usr/local/src/php-5.6.28
make
make install
有可能在make过程中出现
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
看网上文章解释 这是由于机器内存过小造成的 解决办法
在./configure加上选项:--disable-fileinfo
所以完整的命令为
cd /usr/local/src/php-5.6.28
./configure --prefix=/usr/local/php5 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --disable-fileinfo
拷贝php.ini
cp php.ini-production /etc/php.ini
配置php-fpm
cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
编辑 /usr/local/php5/etc/php-fpm.conf
vi /usr/local/php5/etc/php-fpm.conf
修改以下值
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /usr/local/php5/var/run/php-fpm.pid
测试是否安装成功 写入php文件
vi /var/www/html/index.php
输入如下
<?php
phpinfo();
?>
启动php-fpm
/etc/init.d/php-fpm start
curl 127.0.0.1
此时应该得到回应
安装mysql
yum install -y mysql-server mysql mysql-deve
初始化
service mysqld start
设置root密码
/usr/bin/mysqladmin -u root password '123456'
重新启动mysql
service mysqld restart
此时root密码为123456php应该可以连接了
centos下编译安装lnmp的更多相关文章
- CentOS下编译安装LNMP环境
一.卸载系统预安装的LAMP软件 rpm -qa|grep httpd rpm -e httpd httpd-tools rpm -qa|grep mysql rpm -e mysql mysql-l ...
- 转:在CentOS下编译安装GCC
转:https://teddysun.com/432.html 在CentOS下编译安装GCC 技术 秋水逸冰 发布于: 2015-09-02 更新于: 2015-09-02 6519 次围观 ...
- CentOS 下编译安装Apache
CentOS 下编译安装Apache 卸载原有的apache 首先从 http://httpd.apache.or 下载apache源码包httpd-2.4.4.tar.gz然后从 http://ap ...
- centos下编译安装mysql5.6
CentOS 6.4下编译安装MySQL 5.6.14 参考:http://www.cnblogs.com/xiongpq/p/3384681.html 概述: CentOS 6.4下通过yum安装的 ...
- CentOS下编译安装MySQL 5.6.21
一.编译安装MySQL前的准备工作 安装编译源码所需的工具和库 yum install gcc gcc-c++ ncurses-devel perl 安装cmake:http://www.cnblog ...
- centos6.7下编译安装lnmp
很多步骤不说明了,请参照本人的centos6.7下编译安装lamp,这次的架构是nginx+php-fpm一台服务器,mysql一台服务器 (1)首先编译安装nginx: 操作命令: yum -y g ...
- CentOS 下编译安装MySQL
CnetOS 下编译安装 MySql 查看是否存在旧版本: rpm -qa | grep mysql 卸载旧版本: rpm -e mysql #普通删除模式 rpm -e --nodeps mys ...
- CentOS 7 下编译安装lnmp之PHP篇详解
一.安装环境 宿主机=> win7,虚拟机 centos => 系统版本:centos-release-7-5.1804.el7.centos.x86_64 二.PHP下载 官网 http ...
- CentOS 7 下编译安装lnmp之nginx篇详解
一.安装环境 宿主机=> win7,虚拟机 centos => 系统版本:CentOS Linux release 7.5.1804 (Core),ip地址 192.168.1.168 ...
随机推荐
- 爬取https页面遇到“SSLError: hostname 'xxx' doesn't match either of”的解决方法
使用python requests 框架包访问https://itunes.apple.com 页面是遇到 SSLError: hostname 'itunes.apple.com' doesn't ...
- Sicily 1051: 魔板(BFS+排重)
相对1150题来说,这道题的N可能超过10,所以需要进行排重,即相同状态的魔板不要重复压倒队列里,这里我用map储存操作过的状态,也可以用康托编码来储存状态,这样时间缩短为0.03秒.关于康托展开可以 ...
- WPF之命名空间和资源
1.参考: https://msdn.microsoft.com/zh-cn/library/ms747086(v=vs.110).aspx http://www.cnblogs.com/cww201 ...
- 按钮button的css样式(扁平化底色)
.button { background-color: #ff0000; /* Green */ border: none; color: white; font-family:Arial; padd ...
- Python3.5之TuShare
这部分是直接搬运过来的,官方网站http://tushare.waditu.com/ TuShare是一个免费.开源的python财经数据接口包.主要实现对股票等金融数据从数据采集.清洗加工 到 数据 ...
- Android JNI总结
@Dlive 0x01 JNI介绍 JNI是Java Native Interface的缩写,JNI不是Android专有的东西,它是从Java继承而来,但是在Android中,JNI的作用和重要性大 ...
- curses.h的安装和使用
gcc test.c -o test 用以上命令编译包含curses.h头文件的程序时会出现各种引用未定义的错误,并且已经安装了 kernel-devel ncurese-devel ncurese- ...
- rsync参数及通信
rsync 支持: 本机数据 <-------> 远程数据/本地数据 意义: 支持增量拷贝 --> 备份,节省带宽,时间 rsync -avL 一.常用选项 ******* ...
- Quartz.net Trigger触发器下 Cron表达式的格式
有位博主写的不错,样式标准好理解,借鉴下. foamflower 1. CronTrigger时间格式配置说明 CronTrigger配置格式: 格式: [秒] [分] [小时] [日] [月] ...
- 高德地图纯js和html
<!doctype html> <html> <head> <meta content="" charset="utf-8&qu ...