一、安装软件版本
1、MySQL5.5.17
2、nginx1.6.2
3、php5.3
#! /bin/sh ### BEGIN INIT INFO # Provides: php-fpm # Required-Start: $remote_fs $network # Required-Stop: $remote_fs $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts php-fpm # Description: starts the PHP FastCGI Process Manager daemon ### END INIT INFO prefix=/usr/local/php exec_prefix=${prefix} php_fpm_BIN=${exec_prefix}/sbin/php-fpm php_fpm_CONF=${prefix}/etc/php-fpm.conf php_fpm_PID=${prefix}/var/run/php-fpm.pid php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID" wait_for_pid () { try=0 while test $try -lt 35 ; do case "$1" in 'created') if [ -f "$2" ] ; then try='' break fi ;; 'removed') if [ ! -f "$2" ] ; then try='' break fi ;; esac echo -n . try=`expr $try + 1` sleep 1 done } case "$1" in start) echo -n "Starting php-fpm " $php_fpm_BIN --daemonize $php_opts if [ "$?" != 0 ] ; then echo " failed" exit 1 fi wait_for_pid created $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit 1 else echo " done" fi ;; stop) echo -n "Gracefully shutting down php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -QUIT `cat $php_fpm_PID` wait_for_pid removed $php_fpm_PID if [ -n "$try" ] ; then echo " failed. Use force-quit" exit 1 else echo " done" fi ;; force-quit) echo -n "Terminating php-fpm " ;; restart) $0 stop $0 start ;; reload) echo -n "Reload service php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -USR2 `cat $php_fpm_PID` echo " done" ;; *) echo "Usage: $0 {start|stop|force-quit|restart|reload}" exit 1 ;; esac
1)安装MySQL
说明:在MySQL5.5这个版本中之后使用的是cmake编译,所以在安装MySQL之前一定要检查自己的服务器上是否安装了cmake。
源代码安装cmake:安装,解压缩、进入目录、./bootstrap,make && make install
yum安装:yum -y instll cmake*
a、首先需要创建一个用户组和用户名,因为在Linux中,运行每一个服务都是要以一个用户的身份来运行和管理的。
groupadd mysql useradd -g mysql -s /usr/sbin/nologin mysql
b、创建MySQL安装目录
groupadd mysql useradd -g mysql -s /usr/sbin/nologin mysql mkdir /usr/local/mysql mkdir /usr/local/mysql/data cd /usr/local/src tar zxvf mysql-5.5.17.tar.gz cd mysql-5.5.17 #在这编译的过程中可能会出现openSsl,ncurses-devel等安装包的依赖性,只要yum安装这些包就可以 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_unicode_ci -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_DEBUG=0 make && make install
c、安装成功就会出现my-medium.cnf,拷贝配置文件到/etc目录下
cp /usr/local/src/mysql-5.5.17/support-files/my-medium.cnf /etc/my.cnf
d、设置权限
chmod +x /usr/local/mysql chown -R mysql:mysql /usr/local/mysql
e、设置开机自启动
cp support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on
f、修改配置文件
vim /etc/my.cnf # [mysqld] 添加: datadir=/usr/local/mysql/data default-storage-engine=Innodb # 初始化数据库 /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data & # 启动MySQL /usr/local/mysql/bin/mysqld_safe –defaults-file=/etc/my.cnf & 或者: /etc/init.d/mysqld start (service mysqld start) # 测试MySQL是否启动 # 1)查看是否有进程mysql ps -ef | grep mysql # 2)查看端口是否运行 netstat -tnl | grep 3306 # 3)读取mysql版本信息 /usr/local/mysql/bin/mysqladmin version # 4) 登录mysql /usr/local/mysql/bin/mysql -u root#修改MySQL密码update user set password=PASSWORD("") where user='root';flush privileges; # 至此,MySQL安装完成
2)安装nginx
a、nginx安装需要pcre库的支持,首先是要安装这个库文件
yum -y install pcre*
b、安装nginx
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module make && make install
c、将nginx当做系统一个服务来运行
vim /etc/init.d/nginx#!/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="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx 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 killall -9 nginx } 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/init.d/nginx
d、将nginx加到系统服务
chkconfig --add nginx chkconfig nginx on
3)安装php
注意:这个php的安装时将php以一个进程来运行,在Apache中,是将php当做是Apache的一个模块来运行,所以在编译的时候要php支持php-fpm
一、/******************************* 安装GD库 ****************************/ 1)jpeg6 mkdir -p /usr/local/jpeg6 mkdir -p /usr/local/jpeg6/bin mkdir -p /usr/local/jpeg6/lib mkdir -p /usr/local/jpeg6/include mkdir -p /usr/local/jpeg6/man mkdir -p /usr/local/jpeg6/man1 mkdir -p /usr/local/jpeg6/man/man1 cd /usr/local/src tar -zxvf jpegsrc.v6b.tar.gz cd jpeg-6b ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static make # 编译完成 make install # 后续的工作,如复制程序到目标目录,清空缓存等。 2)libpng cd /usr/local/src tar -zvxf libpng-1.2.16.tar.gz cd libpng-1.2.16 ./configure //和zlib一样不要带参数,让它默认安装到相应目录 make && make install 3)freetype cd /usr/local/src tar -zvxf freetype-2.3.4.tar.gz cd freetype-2.3.4 mkdir -p /usr/local/freetype # 创建目录 -p:创建上级目录 mkdir a/b(如果没有a目录会报错) ./configure --prefix=/usr/local/freetype make && make install 4)GD库 cd /usr/local/src tar -zvxf gd-2.0.35.tar.gz mkdir -p /usr/local/gd cd gd-2.0.35 ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg6/ --with-png --with-zlib --with-freetype=/usr/local/freetype make && make install (出错的话,再重新配置一遍,执行上一行) 三、/************************ 编译安装 PHP 所需的支持库 *****************************/ cd /usr/local/src tar zxvf libiconv-1.13.tar.gz cd libiconv-1.13/ ./configure --prefix=/usr/local make && make install cd /usr/local/src #ldconfig是一个动态链接库管理命令,为了让动态链接库为系统所共享 tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8/ ./configure make && make install /sbin/ldconfig cd libltdl/ ./configure --enable-ltdl-install make && make install cd /usr/local/src tar zxvf mhash-0.9.9.tar.gz cd mhash-0.9.9/ ./configure make && make install # 创建程序库的软连接(直接复制运行就可以) ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4 ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8 ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/ cd /usr/local/src tar zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8/ /sbin/ldconfig ./configure make && make install 四、/***************************** 安装PHP5.3(需要前三步都做好之后) *************************************/ cd /usr/local/src tar zxvf php-5.3.27.tar.gz cd php-5.3.27 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg6 --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd=/usr/local/gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear make ZEND_EXTRA_LIBS='-liconv' make install //************************************ 配置php的配置文件 ******************************/ cp ./php.ini-production /usr/local/php/etc/php.ini cd /usr/local/php/etc cp ./php-fpm.conf.default ./php-fpm.conf五、/*********************************修改nginx***********************************/server { listen 80 default; server_name localhost; #charset koi8-r; access_log logs/default.access.log main; error_log logs/default.error.log; root /usr/local/nginx/html; index index.html index.htm index.php; location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1 last;break; } } location ~ .+\.php($|/) { set $script $uri; set $path_info "/"; if ($uri ~ "^(.+\.php)(/.+)") { set $script $1; set $path_info $2; } fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php?IF_REWRITE=1; include fastcgi_params; fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$script; fastcgi_param SCRIPT_NAME $script; }}六、将php制作成系统服务vim /etc/init.d/php-fpm#! /bin/sh### BEGIN INIT INFO# Provides: php-fpm# Required-Start: $remote_fs $network# Required-Stop: $remote_fs $network# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: starts php-fpm# Description: starts the PHP FastCGI Process Manager daemon### END INIT INFOprefix=/usr/local/phpexec_prefix=${prefix}php_fpm_BIN=${exec_prefix}/sbin/php-fpmphp_fpm_CONF=${prefix}/etc/php-fpm.confphp_fpm_PID=${prefix}/var/run/php-fpm.pidphp_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"wait_for_pid () { try=0 while test $try -lt 35 ; do case "$1" in 'created') if [ -f "$2" ] ; then try='' break fi ;; 'removed') if [ ! -f "$2" ] ; then try='' break fi ;; esac echo -n . try=`expr $try + 1` sleep 1 done}case "$1" in start) echo -n "Starting php-fpm " $php_fpm_BIN --daemonize $php_opts if [ "$?" != 0 ] ; then echo " failed" exit 1 fi wait_for_pid created $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit 1 else echo " done" fi ;; stop) echo -n "Gracefully shutting down php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -QUIT `cat $php_fpm_PID` wait_for_pid removed $php_fpm_PID if [ -n "$try" ] ; then echo " failed. Use force-quit" exit 1 else echo " done" fi ;; force-quit) echo -n "Terminating php-fpm " ;; restart) $0 stop $0 start ;; reload) echo -n "Reload service php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -USR2 `cat $php_fpm_PID` echo " done" ;; *) echo "Usage: $0 {start|stop|force-quit|restart|reload}" exit 1 ;;esac
#加权限 chmod +x /etc/init.d/php-fpm #加入到系统服务 chkconfig --add php-fpm chkconfig php-fpm on
上面就是lnmp环境的搭建,在这个搭建的过程中,可能会出现安装包的依赖性的问题,但这些解决都是非常简单的,只要看提示那个软件包和库文件没有安装,直接用yum安装即可
来源:http://www.cnblogs.com/shiwenhu/p/4374060.html