技术员联盟提供win764位系统下载,win10,win7,xp,装机纯净版,64位旗舰版,绿色软件,免费软件下载基地!

当前位置:主页 > 教程 > 服务器类 >

linux服务器下LNMP安装与配置方法

来源:技术员联盟┆发布时间:2019-01-13 12:00┆点击:

现在很多朋友都选择了linux服务器下配置LNMP(linux+nginx+mysql+php),这里分享下LNMP安装与配置方法,需要的朋友可以参考下

 

Nginx与apache、lighttp性能综合对比,如下图:

linux服务器下LNMP安装与配置方法

注意:关闭rpm默认安装的apache和mysql

1.准备php函数的rpm包

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

2.准备lnmp其他的源代码包

wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget

3.安装php-5.2.14源代码包所需要的函数支持包

复制代码 代码如下:


tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=http://www.3lian.com/usr/local
make
make install
cd ../

(libiconv库为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换)

复制代码 代码如下:


tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../

(libmcrypt是加密算法扩展库。支持DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+等算法。)

复制代码 代码如下:


tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
(加密算法支持)
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/bin/libmcrypt-config /usr/bin/libmcrypt-config
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
./configure
make
make install
cd ../

4. 编译安装MySQL 5.5.3-m3

复制代码 代码如下:


groupadd mysql
useradd -g mysql mysql

tar zxvf mysql-5.5.3-m3.tar.gz
cd mysql-5.5.3-m3
./configure --prefix=http://www.3lian.com/usr/local/mysql --without-debug --enable-thread-safe-client --with-pthread --enable-assembler --enable-profiling --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-extra-charsets=all --with-plugins=all --with-mysqld-user=mysql --without-embedded-server --with-server-suffix=-community --with-unix-socket-path=http://www.3lian.com/tmp/mysql.sock
Make
#编译
Make install
#安装
Cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
#准备mysql配置文件
Vi /etc/my.cnf
[client]
default-character-set=utf8
#修改客户端和连接字符集
[mysqld]
character-set-server=utf8
#修改服务器和数据库字符集
collation-server = utf8_general_ci
#修改服务器校验字符集                   登陆mysql后可以s查看字符集

Setfacl -m u:mysql:rwx -R /usr/local/mysql
Setfacl -m d:u:mysql:rwx -R /usr/local/mysql
#设置权限
/usr/local/mysql/bin/mysql_install_db --user=mysql
#安装mysql和test数据库
/usr/local/mysql/bin/mysqld_safe --user=mysql &
#启动mysql服务
/usr/local/mysql/bin/mysqladmin -uroot password  123
#修改mysql登录密码为123
/usr/local/mysql/bin/mysql -uroot -p123
#用mysql登录

5. 编译安装PHP(FastCGI模式。使用fastCGI管理php,加快php解析速度)

复制代码 代码如下:


tar zxvf php-5.2.14.tar.gz
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
#-p  1    是数字
#解压并打补丁,让php支持fpm来方便管理php-cgi进程(使用php-fpm管理fastCGI)
# gzip   -c  保留源文件   -d  解压
cd php-5.2.14/
./configure --prefix=http://www.3lian.com/usr/local/php --with-config-file-path=http://www.3lian.com/usr/local/php/etc --with-mysql=http://www.3lian.com/usr/local/mysql --with-mysqli=http://www.3lian.com/usr/local/mysql/bin/mysql_config --with-iconv-dir=http://www.3lian.com/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=http://www.3lian.com/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
make ZEND_EXTRA_LIBS='-liconv'
#编译过程设定变量(编译过程需要)
make install
cp /lnmp/php-5.2.14/php.ini-dist  /usr/local/php/etc/php.ini
cd ../

6.准备编译安装PHP5扩展模块

复制代码 代码如下: