首页 > 代码库 > 搭建LNMP
搭建LNMP
下载软件包
百度云地址下载地址:http://pan.baidu.com/s/1eSfWNoY
一共有17个包
[root@localhost lnmp]# ls /usr/local/src/lnmp
libgd-2.1.0.tar.gz mysql-5.6.19.tar.gz php-5.5.14.tar.gz cmake-2.8.11.2.tar.gz
libmcrypt-2.5.8.tar.gz 1lib-5.1.2.tar.gz Discuz_X3.2_SC_GBK.zip libpng-1.6.12.tar.gz
nginx-1.6.0.tar.gz tiff-4.0.3.tar.gz libvpx-v1.3.0.tar.bz2 yasm-1.2.0.tar.gz
openssl-1.0.1h.tar.gz freetype-2.5.3.tar.gz zlib-1.2.8.tar.gz jpegsrc.v9a.tar.gz pcre-8.35.tar.gz
安装编译工具及库文件
yum install -y apr* autoconf automake bison bzip2 bzip2* compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gd
libXrender gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libjpeg-turbo
libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp
libXau-devel libxml2 libxml2-devel libXpm* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl
php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel
安装配置mysql服务
1. 安装cmake编译工具
cd /usr/local/src/lnmptar xzvf cmake-2.8.11.2.tar.gzcd cmake-2.8.11.2/./configuremakemake install
2.创建用于执行mysql服务程序的帐号:
useradd mysql -s /sbin/nologin
3.创建数据库程序和文件的目录,并设置目录的所属与所组:
mkdir -p /usr/local/mysql/varchown -Rf mysql:mysql /usr/local/mysql
4.安装Mysql服务程序
cd /usr/local/src/lnmptar xzvf mysql-5.6.19.tar.gzcd mysql-5.6.19/cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/var -DSYSCONFDIR=/etcmakemake install
5.删除系统默认的配置文件:
rm -rf /etc/my.cnf
6.生成系统数据库
cd /usr/local/mysql./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var
7.创建配置文件的软连接文件my.cnf
ln -s my.cnf /etc/my.cnf
8.将mysqld服务程序添加到开机启动项:
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqldchmod 755 /etc/rc.d/init.d/mysqldchkconfig mysqld on
9.编辑启动项的配置文件:
vim /etc/init.d/mysqld
basedir=/usr/local/mysqldatadir=/usr/local/mysql/var
10.启动mysqld服务程序:
service mysqld start
11.把mysql服务程序命令目录添加到环境变量中
echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
source /etc/profile
12.将mysqld服务程序的库文件链接到默认的位置:
mkdir /var/lib/mysqlln -s /usr/local/mysql/lib/mysql /usr/lib/mysqlln -s /usr/local/mysql/include/mysql /usr/include/mysqlln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
13.初始化mysqld服务程序:
[root@lnmp mysql]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order to log into MySQL to secure it, we‘ll need the currentpassword for the root user. If you‘ve just installed MySQL, andyou haven‘t set the root password yet, the password will be blank,so you should just press enter here.Enter current password for root (enter for none): OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MySQLroot user without the proper authorisation.Set root password? [Y/n] y New password: 输入要为root用户设置的数据库密码。Re-enter new password: 重复再输入一次密码。Password updated successfully!Reloading privilege tables.. ... Success!By default, a MySQL installation has an anonymous user, allowing anyoneto log into MySQL without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y(删除匿名帐号) ... Success!Normally, root should only be allowed to connect from ‘localhost‘. Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] y(禁止root用户从远程登陆) ... Success!By default, MySQL comes with a database named ‘test‘ that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] y(删除test数据库并取消对其的访问权限) - Dropping test database... ... Success! - Removing privileges on test database... ... Success!Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] y(刷新授权表,让初始化后的设定立即生效) ... Success!All done! If you‘ve completed all of the above steps, your MySQLinstallation should now be secure.Thanks for using MySQL!Cleaning up...
安装nginx服务
1.安装PCRE(Perl兼容的正则表达式库)
cd /usr/local/src/lnmp/mkdir /usr/local/pcretar xzvf pcre-8.35.tar.gzcd pcre-8.35./configure --prefix=/usr/local/pcremakemake install
2.安装openssl服务程序
cd /usr/local/src/lnmp/mkdir /usr/local/openssltar xzvf openssl-1.0.1h.tar.gzcd openssl-1.0.1h./config --prefix=/usr/local/opensslmakemake install
3.把openssl服务程序命令目录添加到环境变量中
vim /etc/profile//将配置文件最下面的参数追加参数为:export PATH=$PATH:/usr/local/mysql/bin:/usr/local/openssl/bin[root@localhost pcre-8.35]# source /etc/profile
4.安装zlib数据压缩函数库
cd /usr/local/src/lnmp/tar xf zlib-1.2.8.tar.gzcd zlib-1.2.8./configure --prefix=/usr/local/zlibmakemake install
5.创建用于执行nginx服务的用户www:
useradd www -s /sbin/nologin
6.安装nginx服务程序(openssl,zlib,pcre要写成源码解压路径!!!):
cd /usr/local/src/lnmp/tar xf nginx-1.6.0.tar.gzcd nginx-1.6.0./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/lnmp/openssl-1.0.1h --with-zlib=/usr/local/src/lnmp/zlib-1.2.8 --with-pcre=/usr/local/src/lnmp/pcre-8.35makemake install
7.创建nginx程序脚本
vim /etc/rc.d/init.d/nginx
#!/bin/bash# 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: /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 0nginx="/usr/local/nginx/sbin/nginx"prog=$(basename $nginx)NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxmake_dirs() {# make required directoriesuser=`$nginx -V 2>&1 | grep "configure arguments:" | sed ‘s/[^*]*--user=\([^ ]*\).*/\1/g‘ -` if [ -z "`grep $user /etc/passwd`" ]; then useradd -M -s /bin/nologin $user fioptions=`$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 fidone}start() {[ -x $nginx ] || exit 5[ -f $NGINX_CONF_FILE ] || exit 6make_dirsecho -n $"Starting $prog: "daemon $nginx -c $NGINX_CONF_FILEretval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval}stop() {echo -n $"Stopping $prog: "killproc $prog -QUITretval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval}restart() {#configtest || return $?stopsleep 1start}reload() {#configtest || return $?echo -n $"Reloading $prog: "killproc $nginx -HUPRETVAL=$?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" instart) 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 2esac
8.给脚本执行权限,并使它开机启动
chmod 755 /etc/rc.d/init.d/nginx
chkconfig nginx on
9.启动nginx服务,并访问
service nginx start
安装配置php服务
1.安装yasm汇编器
cd /usr/local/src/lnmptar zxvf yasm-1.2.0.tar.gzcd yasm-1.2.0./configuremakemake install
2.安装libmcrypt加密算法扩展库
cd /usr/local/src/lnmptar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8./configuremakemake install
3.安装libvpx视频编码器
cd /usr/local/src/lnmptar xjvf libvpx-v1.3.0.tar.bz2cd libvpx-v1.3.0./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9makemake install
4.安装Tiff标签图像文件格式
cd /usr/local/src/lnmptar zxvf tiff-4.0.3.tar.gzcd tiff-4.0.3./configure --prefix=/usr/local/tiff --enable-sharedmakemake install
5.安装libpng图片(png格式)函数库
cd /usr/local/src/lnmptar zxvf libpng-1.6.12.tar.gzcd libpng-1.6.12./configure --prefix=/usr/local/libpng --enable-sharedmakemake install
6.安装freetype字体引擎
cd /usr/local/src/lnmptar zxvf freetype-2.5.3.tar.gzcd freetype-2.5.3
./configure --prefix=/usr/local/freetype --enable-shared
make
make install
7.安装libgd图像处理程序
cd /usr/local/src/lnmptar zxvf libgd-2.1.0.tar.gzcd libgd-2.1.0./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpxmakemake install
8.安装t1lib图片生成函数库
cd /usr/local/src/lnmptar zxvf t1lib-5.1.2.tar.gzcd t1lib-5.1.2./configure --prefix=/usr/local/t1lib --enable-sharedmakemake install
9.将函数库文件放至合适的位置:
cd /usr/local/src/lnmpln -s /usr/lib64/libltdl.so /usr/lib/libltdl.socp -frp /usr/lib64/libXpm.so* /usr/lib/
10.安装php服务程序
cd /usr/local/src/lnmptar -zvxf php-5.5.14.tar.gzcd php-5.5.14export LD_LIBRARY_PATH=/usr/local/libgd/lib./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-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctypemakemake install
搭建LNMP