本文档将指导您在CentOS 6.5上部署LNMP(Linux、Nginx、MySQL、PHP)环境。
系统环境
系统平台:CentOS release 6.5
安装前准备
在安装LNMP之前,您需要安装一些编译器和依赖包。
必备编译器和工具
bash
#安装gcc、gcc-c++编译器:
yum -y install gcc gcc-c++
#检查编译器是否正确安装:
gcc -v
#必备依赖包,安装所需的依赖包:
yum -y install make cmake gcc gcc-c++ zlib-devel libtool libtool-ltdl libtool-ltdl-devel bison ncurses-devel openldap-devel ntp vim-enhanced gcc-g77 flex autoconf bzip2-devel openssl-devel libxml2-devel libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel curl-devel pam-devel e2fsprogs-devel krb5-devel libidn-devel
检查并卸载旧版本
bash
#检查并卸载Apache
rpm -qa | grep httpd rpm -e httpd --nodeps rm -rf /etc/httpd/
#检查并卸载MySQL
rpm -qa | grep mysql rpm -e mysql --nodeps
#检查并卸载PHP
rpm -qa | grep php rpm -e php --nodeps
关闭SELinux并清空防火墙规则
bash
#检查SELinux状态
/usr/sbin/sestatus -v getenforce
#临时关闭SELinux
setenforce 0
#永久关闭SELinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
安装LNMP
bash
#安装Nginx
#安装依赖包
yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel
#编译安装Nginx
tar -zxvf nginx-1.18.0.tar.gz cd nginx-1.18.0 ./configure --prefix=/usr/local/nginx make && make install
#启动Nginx
/usr/local/nginx/sbin/nginx
安装MySQL
bash
#使用YUM安装MySQL
yum -y install mysql-server mysql mysql-devel service mysqld start
安装PHP
bash
#安装依赖包
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel pcre-devel openssl openssl-devel curl curl-devel libxslt libxslt-devel
#编译安装PHP
tar zxf php-5.3.10.tar.gz cd php-5.3.10 mkdir -p /usr/local/php ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-mysql=/usr/local/mysql --enable-mbstring --with-curl --with-openssl make && make install cp php.ini-development /usr/local/php/etc/php.ini
配置Nginx和PHP
bash
#编辑Nginx配置文件/usr/local/nginx/conf/nginx.conf:
server { listen 80; server_name localhost; location / { root html; index index.php index.html index.htm; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; } }
启动PHP-FPM
bash
#安装并配置PHP-FPM:
yum -y install php-fpm service php-fpm start
测试LNMP环境
bash
#创建测试PHP页面:
echo "<?php phpinfo(); ?>" > /usr/local/nginx/html/index.php
#在浏览器中输入服务器IP地址,您应该能够看到PHP信息页面。
设置MySQL密码
bash
mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('你的密码'); FLUSH PRIVILEGES;
#通过上述步骤,您已经成功在CentOS 6.5上部署了LNMP环境。如果有任何问题,请检查日志文件并根据错误消息进行调试。