lnmp源码安装

lnmp源码安装

1.nginx安装

用xshell连接虚拟机,搭建yum库。
用yum安装wget,可以用wget命令从网上下载nginx软件包。
用yum下载lrzsz,可以将桌面上的软件包传送到虚拟机中。
将nginx软件包保存到/usr/local/src/中,将服务保存到/data/server/中。
[[email protected] ~]# yum -y install lrzsz
[[email protected] ~]# mkdir -p /data/server/
[[email protected] ~]# cd /usr/local/src/
[[email protected] src]# tar zxf nginx-1.11.5.tar.gz -C /data/server/
nginx安装需要的环境用yum安装。
[[email protected] src]# yum -y install gcc
[[email protected] src]# yum -y install pcre-devel
[[email protected] src]# yum -y install zlib-devel
切换路径。
[[email protected] src]# cd /data/server/nginx-1.11.5/
配置。
[[email protected] nginx-1.11.5]# ./configure --prefix=/data/server/nginx
编译安装。
[[email protected] nginx-1.11.5]# make && make install
切换路径,开启nginx服务并关闭防火墙。
[[email protected] nginx-1.11.5]# cd /data/server/nginx/sbin/
[[email protected] sbin]# ls
nginx
[[email protected] sbin]# ./nginx
[[email protected] sbin]# netstat -anput | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4919/nginx: master
[[email protected] sbin]# systemctl stop firewalld
打开浏览器,输入IP,查看。
lnmp源码安装

2.mysql安装

先将mysql软件包传送或下载到虚拟机中。
[[email protected] sbin]# cd /usr/local/src/
[[email protected] src]# rz
[[email protected]calhost src]# ls
mysql-5.6.19.tar.gz nginx-1.11.5.tar.gz
先将配置mysql所需要的环境等用yum安装。
[[email protected] src]# yum -y install gcc gcc-c++ lrzsz pcre-devel zlib-devel cmake
[[email protected] src]# yum -y install ncurses-devel
解包。
[[email protected] src]# tar zxf mysql-5.6.19.tar.gz -C /data/server/
[[email protected] mysql-5.6.19]# cd /data/server/mysql-5.6.19/
配置。
[[email protected] mysql-5.6.19]# cmake -DCMAKE_INSTALL_PREFIX=/data/server/mysql -DSYSCONFDIR=/etc/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all
编译并安装。
[[email protected] mysql-5.6.19]# make && make install(此过程所需时间较长)
创建用户。
[[email protected] mysql-5.6.19]# groupadd mysql
[[email protected] mysql-5.6.19]# useradd -s /sbin/nologin -M -g mysql mysql
删除配置文件,切换路径。
[[email protected] mysql-5.6.19]# rm -rf /etc/my.cnf
[[email protected] mysql-5.6.19]# cd /data/server/mysql
初始化数据库。
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/data/server/mysql --datadir=/data/server/mysql/var
链接并添加系统服务。
[[email protected] mysql]# ln -s my.cnf /etc/my.cnf
[[email protected] mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
cp: overwrite ‘/etc/rc.d/init.d/mysqld’? y
修改权限。
[[email protected] mysql]# chmod 755 /etc/rc.d/init.d/mysqld
修改配置文件。
[[email protected] mysql]# vi /etc/rc.d/init.d/mysqld
lnmp源码安装
启动服务。
[[email protected] mysql]# service mysqld start
Unit mysqld.service could not be found.
Starting MySQL… SUCCESS!
开机自启动。
[[email protected] mysql]# chkconfig mysqld on
修改配置文件。
[[email protected] mysql]# vi /etc/profile
lnmp源码安装
加载文件。
[[email protected] mysql]# source /etc/profile
[[email protected] mysql]# mkdir /var/lib/mysql
链接文件。
[[email protected] mysql]# ln -s /data/server/mysql/lib/mysql /usr/lib/mysql
[[email protected] mysql]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
[[email protected] mysql]# ln -s /data/server/mysql/include/mysql /usr/include/mysql
初始化mysql。
[[email protected] mysql]# mysql_secure_installation
lnmp源码安装
lnmp源码安装
切换到bin下。
[[email protected] mysql]# cd bin
lnmp源码安装

3.php安装

先将php安装包下载到虚拟机中。
安装php包所需要的环境等。
[[email protected] php-7.2.0]# yum -y install libxml2-devel
[[email protected] php-7.2.0]# yum -y install openssl-devel
[[email protected] php-7.2.0]# yum -y install bzip2-devel
[[email protected] php-7.2.0]# yum -y install libcurl-devel
[[email protected] php-7.2.0]# yum -y install readline-devel
此外,还有一个需要用编译安装的环境libmcrypt-2.5.8.tar.gz。
[[email protected] src]# tar zxf libmcrypt-2.5.8.tar.gz -C /data/server/
[[email protected] src]# cd /data/server/libmcrypt-2.5.8/
[[email protected] libmcrypt-2.5.8]# ./configure
[[email protected] libmcrypt-2.5.8]# make && make install
解包。
[[email protected] src]# tar zxf php-7.2.0.tar.gz -C /data/server/
切换路径。
[[email protected] src]# cd /data/server/php-7.2.0
配置。
[[email protected] php-7.2.0]# ./configure --prefix=/data/server/php --with-config-file-path=/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache=no --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline --without-sqlite3 --without-pdo-sqlite --with-pear
编译并安装。
[[email protected] php-7.2.0]# make && make install
复制配置文件到/data/server下
[[email protected] php-7.2.0]# cp php.ini-development /data/server/php/etc/php.ini
[[email protected] php-7.2.0]# cp /data/server/php/etc/php-fpm.conf.default /data/server/php/etc/php-fpm.conf
[[email protected] php-7.2.0]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
修改权限。
[[email protected] php-7.2.0]# chmod +x /etc/init.d/php-fpm
新建用户和组。
[[email protected] php-7.2.0]# groupadd www
[[email protected] php-7.2.0]# useradd -s /sbin/nologin -M -g www www
切换路径,查看,并复制改名。
[[email protected] php-7.2.0]# cd /data/server/php/etc/php-fpm.d/
[[email protected] php-fpm.d]# ls
www.conf.default
[[email protected] php-fpm.d]# cp www.conf.default www.conf
启动服务成功。
[[email protected] php-fpm.d]# /etc/init.d/php-fpm start
Starting php-fpm done
修改配置文件。
[[email protected] php-fpm.d]# vi /data/server/nginx/conf/nginx.conf
进入后,在末行模式下set nu显示行号。
lnmp源码安装
lnmp源码安装
lnmp源码安装
保存退出
编辑一个lnmp环境测试页面.
[[email protected] php-fpm.d]# vi /data/server/nginx/html/1.php
lnmp源码安装
切换路径。
[[email protected] sbin]# cd /data/server/nginx/sbin/
[[email protected] sbin]# ./nginx
[[email protected] sbin]# netstat -anput | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 44579/nginx: master
网页输入ip/1.php验证。
lnmp源码安装