首页 > 代码库 > CentOS7下搭建LNMP记录
CentOS7下搭建LNMP记录
OS:使用虚拟机最小化安装的CentOS 7系统;配置好防火墙,SELINUX,YUM源,IP地址等。
0、因为采用了最小化安装系统,所缺少的包比较多,必要工具先安装一下
1 yum install gcc gcc-c++ wget vim lrzsz
数据库安装
一、删除系统中已存在的MySQL
1 ##删除MySQL的lib库,服务文件2 yum remove mysql mysql-server mysql-libs mysql-server3 4 ##查找MySQL的残留文件5 find / -name mysql6 7 ##如果存在残留文件,将其删除8 rm -rf *mysql*
二、删除系统中已存在的MySQL安装包
1 ##查找是否有mysql安装包2 rpm -qa | grep -i mysql3 4 ##如果有,则删除安装包5 yum -y remove mysql-libs*
三、安装新mysql5.6.19(可根据自己需求选择)
1 ##添加依赖应用 2 yum install -y gcc gcc-c++ autoconf automake zlib* libxml* libtool-ltdl-devel 3 4 ##安装 cmake 及相关软件 ncurses 和 bison 5 wget http://www.cmake.org/files/v3.0/cmake-3.0.2.tar.gz #可自选方式 6 tar zxvf cmake-3.0.2.tar.gz 7 cd cmake-3.0.2 8 ./bootstrap 9 make 10 make install11 12 yum install -y ncurses-devel* 13 yum install -y bison14 15 ##创建 mysql 用户, 创建数据库目录和权限16 groupadd mysql17 useradd -g mysql mysql18 mkdir -p /data/mysql19 chown -R root:mysql /data/mysql20 21 ##下载 mysql 源码并且编译22 wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.20.tar.gz23 tar xzfv mysql-5.6.20.tar.gz24 cd mysql-5.6.2025 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc/26 27 gmake28 gmake install29 30 ##配置 mysql31 cd /usr/local/mysql32 cp ./support-files/my-default.cnf /etc/my.cnf33 34 vim /etc/my.cnf35 #在 [mysqld] 段增加36 datadir = /data/mysql37 wait-timeout = 3038 max_connections = 51239 max_connect_errors = 1000000040 default-storage-engine = MyISAM41 42 #在 [mysqld] 段修改43 max_allowed_packet = 16M 44 45 #保存退出编辑46 47 ##初始化数据库48 ./scripts/mysql_install_db --datadir=/data/mysql --basedir=/usr/local/mysql --defaults-file=/etc/my.cnf --user=mysql49 50 cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld51 52 chmod 755 /etc/rc.d/init.d/mysqld53 54 chkconfig --add mysqld55 56 ##设置启动脚本变量,编辑 /etc/rc.d/init.d/mysqld57 vim /etc/rc.d/init.d/mysqld58 basedir=/usr/local/mysql59 datadir=/data/mysql 60 61 ##设置变量环境62 echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile (永久生效)63 export PATH=$PATH:/usr/local/mysql/bin (当前生效)64 65 cd bin66 #启动服务67 service mysqld start68 69 ##设置数据库管理员root密码70 mysqladmin -u root password ‘123456‘71 service mysqld restart72 73 ##进入Mysql 74 75 mysql -u root -p
安装php5.6.0
1 ##添加依赖应用 2 yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel curl-devel 3 4 ##安装加密扩展库 5 cd /usr/local/src/ 6 wget libmcrypt-2.5.8.tar.gz 7 tar zxvf libmcrypt-2.5.8.tar.gz 8 cd libmcrypt-2.5.8 9 ./configure10 make11 make install12 13 cd ../14 wget http://cn2.php.net/distributions/php-5.6.0.tar.gz15 tar zxvf php-5.6.0.tar.gz16 cd php-5.6.017 18 ./configure --prefix=/usr/local/php-5.6.0 --with-mysql=/usr/local/mysql --with-mysql-sock --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-fpm --with-ncurses --enable-soap --with-libxml-dir --with-XMLrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --disable-mbregex --disable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-pdo-mysql --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear19 20 make21 make test22 make install23 24 25 cd /usr/local/php-5.6.0/etc/26 cp php-fpm.conf.default php-fpm.conf27 28 /usr/local/php-5.6.0/sbin/php-fpm ##启动29 30 ##修改FPM 配置文件php-fpm.conf31 vi php-fpm.conf32 pm.max_children = 5033 pm.start_servers = 2034 pm.min_spare_servers = 535 pm.max_spare_servers = 3536 pm.max_requests = 50037 ##去掉分号38 39 ln -s /usr/local/php-5.6.0/sbin/php-fpm /bin/php-fpm40 cp /usr/local/src/php-5.6.0/php.ini-production /usr/local/php-5.6.0/lib/php.ini41 42 43 ##php-fpm安装完成
安装nginx1.7.5
1 cd /usr/local/src/ 2 wget http://nginx.org/download/nginx-1.7.5.tar.gz 3 4 useradd www 5 ##添加www nginx运行账户 6 7 usermod -s /sbin/nologin -g www www 8 ##将www加入www组并禁止www登录shell 9 10 tar zxvf nginx-1.7.5.tar.gz11 12 cd nginx-1.7.513 ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --without-http_rewrite_module --with-http_ssl_module --with-pcre14 15 make && make install16 17 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf18 ##启动nginx,nginx启动成功19 20 /usr/local/nginx/sbin/nginx -s reload21 ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx22 23 ##修改nginx配置文件,根据需要修改对应文件24 25 vi /usr/local/nginx/conf/nginx.conf26 user nobody;#去掉前面,及找到如下部分取消其前的注释,并修改$document_root27 28 location ~ \.php$ {29 root html;30 fastcgi_pass 127.0.0.1:9000;31 fastcgi_index index.php;32 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;33 include fastcgi_params;34 }35 36 37 nginx -s reload38 39 cd /usr/local/nginx/html40 vi info.php41 <?php42 phpinfo();43 ?>44 45 46 nginx -s reload47 48 49 打开浏览器访问一下,成功应该能看到PHP页面信息
CentOS7下搭建LNMP记录
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。