本地虚拟机LNMP环境安装
Posted 杜文健
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了本地虚拟机LNMP环境安装相关的知识,希望对你有一定的参考价值。
首先上传源码包到linux中(本人上传到根目录中),随意上传能找到即可
一、配置YUM源(如果已经配好就不许要重新配置)
挂载光驱要挂载到/mnt下 Mount /dev/cdrom /mnt
1.备份yum源目录
[[email protected] ~]# cp /etc/yum.repos.d /etc/yum.repos.d_bak
2.删除yum源目录中所有文件,并创建dvd.repo
[[email protected] ~]# cd /etc/yum.repos.d
[[email protected] yum.repos.d]# rm -rf ./*
[[email protected] yum.repos.d]# touch dvd.repo
3.在dvd.repo中写入以下几行
[[email protected] yum.repos.d]# vi dvd.repo
[dvd]
name=install dvd
baseurl=file:///mnt
enabled=1
gpgcheck=0
二、YUM安装系统所需要的依赖包
1.yum安装,将以下几行复制安装即可
yum -y install yum-fastestmirror ntp
yum -y install patch make flex bison tar
yum -y install libtool libtool-libs kernel-devel
yum -y install libjpeg libjpeg-devel libpng libpng-devel
yum -y install libtiff libtiff-devel gettext gettext-devel
yum -y install libxml2 libxml2-devel zlib-devel net-snmp
yum -y install file glib2 glib2-devel bzip2 diff* openldap-devel
yum -y install bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs
yum -y install e2fsprogs-devel krb5 krb5-devel libidn libidn-devel
yum -y install openssl openssl-devel vim-minimal unzip
三、上传源码包到LINUX
1.将准备好的源码包上传到linux中(我存放在根目录下)
四、安装Nginx
1.安装nginx组件
解压包之前记得切换到源码包所在目录 [[email protected] /]# cd /linux_nignx
yum -y install gcc gcc-c++ gcc-g77 flex bison tar libtool libtool-libs kernel-devel autoconf libjpeg libjpeg-devel libpng libpng-devel libtiff libtiff-devel gettext gettext-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel file glib2 glib2-devel bzip2diff* openldap-devel bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal unzip automake make
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
2.安装pcre (源码包安装)
(1)解压pcre包,进入解压好的目录
[[email protected] linux_nignx]# tar -zxvf pcre-8.39.tar.gz
[[email protected] linux_nignx]# cd pcre-8.39
(2)解析、编译、安装
[[email protected] pcre-8.39]# ./configure
[[email protected] pcre-8.39]# make && make install
3.安装nginx
(1)解压nginx包,进入目录
[[email protected] linux_nignx]# tar -zxvf nginx-1.8.0.tar.gz
[[email protected] linux_nignx]# cd nginx-1.8.0
(2)解析、编译、安装
[[email protected] linux_nignx]# ./configure
[[email protected] linux_nignx]# make && make install
(3)启动nginx
[[email protected] linux_nignx]# cd /usr/local/nginx/sbin
[[email protected] linux_nignx]# ./nginx
重启[[email protected] linux_nignx]# ./nginx –s
启动nginx:/usr/local/nginx/sbin/nginx
重启nginx: /usr/local/nginx/sbin/nginx -s reload
五、安装Mysql
1.yum安装依赖包
[[email protected] linux_nignx]# yum -y install gcc gcc-c++ gcc-g77 autoconf automake fiex* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake
[[email protected] linux_nignx]# yum -y install cmake
2.创建mysql用户
[[email protected] linux_nignx]# useradd mysql
3.解压mysql包,进入目录
[[email protected] linux_nignx]# tar -zxvf mysql-5.6.21.tar.gz
[[email protected] linux_nignx]# cd mysql-5.6.21
4.解析、编译、安装
[[email protected] mysql-5.6.21]# cmake .
[[email protected] mysql-5.6.21]# make && make install
下面这项可以延后处理,只是为了用于登陆mysql使用的
5、修改mysql账户信息----默认情况下是安装在/usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
cd /usr/local/mysql/scripts
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
cd /usr/local/mysql/support-files
cp mysql.server /etc/rc.d/init.d/mysql
cp my-default.cnf /etc/my.cnf
chkconfig --add mysql
chkconfig mysql on
service mysql start
修改密码:/usr/local/mysql/bin/mysqladmin -u root password ‘123456‘
登陆:/usr/local/mysql/bin/mysql -u root -p
修改远程访问权限:
1。 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"
Sql代码 复制代码
1. mysql -u root -pvmwaremysql>use mysql;
2. mysql>update user set host = ‘%‘ where user = ‘root‘;
3. mysql>select host, user from user;
2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
Sql代码 复制代码
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;
FLUSH PRIVILEGES;
六、安装PHP
1、安装libi库
[[email protected] linux_nignx]# tar -zxvf libiconv-1.14.tar.gz
[[email protected] linux_nignx]# cd libiconv-1.14
[[email protected] libiconv-1.14]#./configure –help
[[email protected] libiconv-1.14]# ./configure --prefix=/usr/local
[[email protected] libiconv-1.14]# make && make install
2、安装php
解压php5.6以后进入解压好的目录,执行以下命令
[[email protected] php-5.6.3]# echo "/usr/local/lib">>/etc/ld.so.conf
[[email protected] php-5.6.3]# /sbin/ldconfig
[[email protected] php-5.6.3]# ./configure --enable-fpm --enable-mbstring --with-mysql=/usr/local/mysql --with-iconv-dir=/usr/local --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mb --enable-bcmath --enable-mbstring --enable-sockets --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --with-iconv-t --with-zlib --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql --enable-dom --enable-xml --enable-fpm --with-iconv-dir=/usr/local
编译完毕后,我们再来make。在make时,我们注意要加上-liconv参数。如果不加上-liconv参数,系统在make编译会报错。报错信息如下:
Generating phar.php
//php-5.3.16/sapi/cli/php: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
make: *** [sapi/cli/php] Error 1
使用命令如下:
make ZEND_EXTRA_LIBS=‘-liconv‘
如果仍然报错,执行以下操作
[[email protected] php-5.6.3]# cp ext/phar/phar.php ext/phar/phar.phar
[[email protected] php-5.6.3]# make test
[[email protected] php-5.6.3]# make install
3、配置环境变量
[[email protected] php-5.6.3]# echo "PATH=$PATH:/usr/local/php/bin:/usr/local/php/sbin">> /etc/profile
4、刷新系统变量
[[email protected] php-5.6.3]# source !$
5、配置php信息
[[email protected] php-5.6.3]# cp php.ini-production /usr/local/php/etc/php.ini
[[email protected] php-5.6.3]# cd /usr/local/php
[[email protected] php]# cp etc/php-fpm.conf.default etc/php-fpm.conf
[[email protected] php-5.6.3]# useradd www
[[email protected] php]# vi etc/php-fpm.conf
将 user = nobody 改写为 user = www
group = nobody group = www
下面这段复制的命令看好自己的源码包路径
[[email protected] php]# cp /linux_nignx/php-5.6.3/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
6、修改php-fpm权限并运行
[[email protected] php]# chmod 755 /etc/init.d/php-fpm
[[email protected] php]# /usr/local/php/sbin/php-fpm -t
7、启动php-fpm
[[email protected] php]# service php-fpm start
8、添加php到系统服务
[[email protected] php]# chkconfig --add php-fpm && chkconfig php-fpm on
七、Nginx解析PHP
1、打开nginx配置文件
[[email protected] conf]# vi /usr/local/nginx/conf/nginx.conf
2、在server内部对应位置加入以下配置信息
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
3、重启nginx搞定
以上是关于本地虚拟机LNMP环境安装的主要内容,如果未能解决你的问题,请参考以下文章