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-server 3 4 ##查找MySQL的残留文件 5 find / -name mysql 6 7 ##如果存在残留文件,将其删除 8 rm -rf *mysql*
二、删除系统中已存在的MySQL安装包
1 ##查找是否有mysql安装包 2 rpm -qa | grep -i mysql 3 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 install 11 12 yum install -y ncurses-devel* 13 yum install -y bison 14 15 ##创建 mysql 用户, 创建数据库目录和权限 16 groupadd mysql 17 useradd -g mysql mysql 18 mkdir -p /data/mysql 19 chown -R root:mysql /data/mysql 20 21 ##下载 mysql 源码并且编译 22 wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.20.tar.gz 23 tar xzfv mysql-5.6.20.tar.gz 24 cd mysql-5.6.20 25 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc/ 26 27 gmake 28 gmake install 29 30 ##配置 mysql 31 cd /usr/local/mysql 32 cp ./support-files/my-default.cnf /etc/my.cnf 33 34 vim /etc/my.cnf 35 #在 [mysqld] 段增加 36 datadir = /data/mysql 37 wait-timeout = 30 38 max_connections = 512 39 max_connect_errors = 10000000 40 default-storage-engine = MyISAM 41 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=mysql 49 50 cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld 51 52 chmod 755 /etc/rc.d/init.d/mysqld 53 54 chkconfig --add mysqld 55 56 ##设置启动脚本变量,编辑 /etc/rc.d/init.d/mysqld 57 vim /etc/rc.d/init.d/mysqld 58 basedir=/usr/local/mysql 59 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 bin 66 #启动服务 67 service mysqld start 68 69 ##设置数据库管理员root密码 70 mysqladmin -u root password '123456' 71 service mysqld restart 72 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 ./configure 10 make 11 make install 12 13 cd ../ 14 wget http://cn2.php.net/distributions/php-5.6.0.tar.gz 15 tar zxvf php-5.6.0.tar.gz 16 cd php-5.6.0 17 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-pear 19 20 make 21 make test 22 make install 23 24 25 cd /usr/local/php-5.6.0/etc/ 26 cp php-fpm.conf.default php-fpm.conf 27 28 /usr/local/php-5.6.0/sbin/php-fpm ##启动 29 30 ##修改FPM 配置文件php-fpm.conf 31 vi php-fpm.conf 32 pm.max_children = 50 33 pm.start_servers = 20 34 pm.min_spare_servers = 5 35 pm.max_spare_servers = 35 36 pm.max_requests = 500 37 ##去掉分号 38 39 ln -s /usr/local/php-5.6.0/sbin/php-fpm /bin/php-fpm 40 cp /usr/local/src/php-5.6.0/php.ini-production /usr/local/php-5.6.0/lib/php.ini 41 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.gz 11 12 cd nginx-1.7.5 13 ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --without-http_rewrite_module --with-http_ssl_module --with-pcre 14 15 make && make install 16 17 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 18 ##启动nginx,nginx启动成功 19 20 /usr/local/nginx/sbin/nginx -s reload 21 ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx 22 23 ##修改nginx配置文件,根据需要修改对应文件 24 25 vi /usr/local/nginx/conf/nginx.conf 26 user nobody;#去掉前面,及找到如下部分取消其前的注释,并修改$document_root 27 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 reload 38 39 cd /usr/local/nginx/html 40 vi info.php 41 <?php 42 phpinfo(); 43 ?> 44 45 46 nginx -s reload 47 48 49 打开浏览器访问一下,成功应该能看到PHP页面信息
o(=•ェ•=)m纸上得来终觉浅,绝知此事要躬行o(=•ェ•=)m