lnmp源码编译安装
2015-05-28 18:09
495 查看
首先来介绍一下Nginx.Nginx是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。Nginx不仅可以作为web服务器,也可以作为负载均衡器,之前也有文章介绍,大家可以看一下.
MySQL是一款开源免费的数据软件,MySQL是一个小型关系型数据库管理系统,其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库.
PHP,是英文超级文本预处理语言Hypertext Preprocessor的缩写。PHP 是一种 HTML 内嵌式的语言,是一种在服务器端执行的嵌入HTML文档的脚本语言,语言的风格有类似于C语言,被广泛的运用。
首先我们下载nginx,在Linux下执行下面命令:
首先我们解压源码包:
然后我们进行预编译,一般预编译会带上一些参数,已达到我们想要安装的效果,比如启用某个功能,禁用某个功能:
进入源码包目录进行预编译:
安装MySQL:
安装依赖:
加入chkconfig
chkconfig --add mysqld
chkconfig mysqld --level 235 on
配置完毕后我们启动mysql:
MySQL安装完毕下面我们就来安装PHP,安装PHP前首先要安装几个源码包依赖:
libmcrypt mhash mcrypt
首先来安装几个源码包依赖:
MySQL是一款开源免费的数据软件,MySQL是一个小型关系型数据库管理系统,其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库.
PHP,是英文超级文本预处理语言Hypertext Preprocessor的缩写。PHP 是一种 HTML 内嵌式的语言,是一种在服务器端执行的嵌入HTML文档的脚本语言,语言的风格有类似于C语言,被广泛的运用。
首先我们下载nginx,在Linux下执行下面命令:
cd /usr/src # 一般软件源码放在这个目录下 wget http://nginx.org/download/nginx-1.0.13.tar.gz # 下载nginx会有几个依赖包,我们首先安装依赖,不要安装过程中会报错:
yum -y install zlib-devel pcre-devel openssl-devel perl perl-devel perl-ExtUtils-Embed gd gd-devel
首先我们解压源码包:
tar -zxvf nginx-1.0.13.tar.gz
然后我们进行预编译,一般预编译会带上一些参数,已达到我们想要安装的效果,比如启用某个功能,禁用某个功能:
进入源码包目录进行预编译:
cd nginx-1.0.13 ./configure --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_image_filter_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_degradation_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-pcre
make && make install 编写sysv启动脚本 vim /etc/init.d/nginx #!/bin/sh # # nginx - this script starts and stops the nginx daemin # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /usr/local/nginx/conf/nginx.conf # pidfile: /usr/local/nginx/logs/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="/usr/local/nginx/conf/nginx.conf" lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 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 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/init.d/nginx 加入开机启动管理 chkconfig --add nginx chkconfig --level 35 nginx on好了,下面我们启动nginx:
service nginx start
安装MySQL:
安装依赖:
yum -y install ncurses-devel cmake创建MySQL用户:
useradd -M -s /sbin/nologin mysql # -M不创建home目录,-s指定shell为不登录然后进行安装:
tar -zxvf mysql-5.0.95.tar.gz cd mysql-5.0.95 cmake -DCMAKE_INSTALL_PREFIX=/data/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 make make install安装完成后复制配置文件和启动脚本:
cp support-files/my-medium.cnf /etc/my.cnf # 复制配置文件 cp support-files/mysql.server /etc/init.d/mysqld # 复制启动脚本 chmod +x /etc/init.d/mysqld # 给启动脚本执行权限为了以后方便我们为所有的二进制可执行文件和动态链接库文件做一个软连接:
ln -s /usr/local/mysql/bin/* /usr/local/bin/ # 为可执行的二进制文件做软连接 ln -s /usr/local/mysql/lib/mysql/lib* /usr/lib/ # 为动态链接库做一个软连接然后我们初始化数据库:
mysql_install_db --user=mysql # 用MySQL用户安装数据库为了MySQL能正常使用我们需要更改一下MySQL安装目录和MySQL的数据库目录的属主和属组:
chown -R root.mysql /usr/local/mysql/ # 更改安装目录属主为root,属组为mysql chown -R mysql.mysql /usr/local/mysql/var/ # 更改数据库目录属主和属组都为mysql这里的-R参数用来应用到所有子目录和文件
加入chkconfig
chkconfig --add mysqld
chkconfig mysqld --level 235 on
配置完毕后我们启动mysql:
service mysqld start现在我们查看MySQL是否启动成功,MySQL占用TCP的3306端口,我们查看端口是否被占用:
netstat -antlp grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 32143/mysqld
MySQL安装完毕下面我们就来安装PHP,安装PHP前首先要安装几个源码包依赖:
libmcrypt mhash mcrypt
首先来安装几个源码包依赖:
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2/download tar -jxvf libmcrypt-2.5.8.tar.bz2 # 这个包是bz2的 使用-j参数解压 cd libmcrypt-2.5.8 ./configure make make install #################################################### wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2/download tar -jxvf mhash-0.9.9.9.tar.bz2 cd mhash-0.9.9.9 ./configure make make install # 这两个包安装完成后要把动态链接库做一个软连接到/usr/lib,以为接下来的mcrypt依赖于这两个包 ln -s /usr/local/lib/libmcrypt* /usr/lib ln -s /usr/local/lib/libmhash.* /usr/lib/ ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config ########################################################### wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download tar -zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8 ./configure make make install然后下载php:
wget http://cn2.php.net/get/php-5.4.0.tar.bz2/from/this/mirror[/code]安装依赖:yum –y install libxml2-devel curl-devel libpng-devel openldap-devel gd gd-devel openssl openssl-devel我们使用nginx调用php的时候使用fpm的方式,在php 5.4中加入了对php-fpm的支持,所以就不需要打补丁了.安装PHP:tar -jxvf php-5.4.0.tar.bz2 cd php-5.4.0 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --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 --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到这里整个LNMP已经安装完成.下面我们就配置php和nginx能运行php网站:
首先为php创建配置文件:cp php.ini-production /usr/local/php/php.ini # 如果是开发就复制php.ini-development cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf ln -s /usr/local/php/bin/php /usr/bin/
编写sysv的启动脚本
#!/bin/sh
# chkconfig: - 84 16
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
phpfpm="/usr/local/php/sbin/php-fpm"
prog=$(basename ${phpfpm})
lockfile=/var/lock/subsys/phpfpm
start() {
[ -x ${phpfpm} ] || exit 5
echo -n $"Starting $prog: "
daemon ${phpfpm}
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
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc ${phpfpm} -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
${phpfpm} -t
}
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
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"
exit 2
esac
保存退出。
配置php-fpm,编辑php-fpm.confvi /usr/local/php/etc/php-fpm.conf找到listen那一行,修改成如下内容:listen = /var/run/php-fpm/php-fpm.sock # 使用unix socket启动php-fpmmkdir /var/run/php-fpm /usr/local/php/sbin/php-fpm然后配置nginx,编辑nginx配置文件vi /usr/local/nginx/conf/nginx.conf修改nginx配置文件支持php:server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.php index.html index.htm; # 添加index.php的首页文件 } # 添加下面内容 location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; include fastcgi_params; include fastcgi.conf; }修改完毕后保存退出重启nginx:pkill -9 nignx /usr/local/nginx/sbin/nginx然后在/usr/local/nginx/html下创建index.php,vi /usr/local/nginx/html/index.php添加下面内容:
<?php
phpinfo();
?>
到这里我们的LNMP环境就完全搭建成功,运行你的网站或者学习你的PHP吧.
相关文章推荐
- centos6源码编译安装lnmp环境
- lnmp源码编译安装zabbix
- CentOS7最小化安装下源码编译搭建LAMP, LNMP环境及搭建discuz论坛
- LNMP 源码编译安装
- saltstack源码编译安装lnmp
- lnmp环境源码编译安装记录
- lnmp环境安装(4)-php源码编译安装
- LNMP源码编译安装
- 源码编译安装LNMP
- 源码编译安装LNMP
- ubuntu14或Ubuntu16 下 源码配置、编译安装Lnmp环境
- 源码编译安装LNMP环境及配置基于域名访问的多虚拟主机
- Nginx实战基础篇六 通过源码包编译安装部署LNMP搭建Discuz论坛 推荐
- CentOS 7源码编译安装PHP5.6和Nginx1.7.9及MySQL(搭建LNMP环境)
- Lnmp 源码编译安装
- LNMP源码编译安装(centos7+nginx1.9+mysql5.6+php7)
- LNMP源码编译安装(centos7+nginx1.9+mysql5.6+php7)
- 源码编译lnmp之简介与nginx安装
- lnmp源码编译安装Linux(6.4)+Nginx(1.4.1)+Mysql(5.6.12)+Php(5.5.0)
- lnmp源码编译安装过程