LNMP单点服务器搭建
LNMP单点服务器搭建
一、部署服务器环境
Linux:centos6.5
nginx:1.14.0
mysql:5.6.33
php:5.6.36
1.网络配置2.FQDN/etc/hosts/etc/sysconfig/network3.防火墙iptables和selinux4.yum源epel和163源5.安装vim6.网络校时7.lrzsz上传下载工具
二、Mysql
1.安装
①创建mysql用户,mysql启动使用这个用户shell > groupadd mysqlshell > useradd -s /sbin/nologin -g mysql -M mysqlshell > tail -1 /etc/passwd②安装cmakeyum -y install cmake③解压并进行编译tar zxvf mysql-5.6.33.tar.gzcd mysql-5.6.33编译设置cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_DATADIR=/usr/local/mysql/data \-DSYSCONFDIR=/etc \-DENABLED_LOCAL_INFILE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DEXTRA_CHARSETS=all \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_SSL=bundled出错,解决依赖shell > yum -y install ncurses-develshell > rm -f CMakeCache.txt重新cmake以上的参数编译并安装shell > make && make install
2.配置
①授权shell > chown -R mysql:mysql /usr/local/mysql②复制配置文件shell > cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf③初始化数据库shell > /usr/local/mysql/scripts/mysql_install_db –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data –user=mysql④添加启动服务shell > cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldshell > chmod +x /etc/init.d/mysqld (因为mysql服务已经有执行权限,可以不执行此条命令)shell > service mysqld startshell > chkconfig –add mysqld(添加服务管理)shell > chkconfig mysqld on(增加之后默认已经自启,此条可以不执行)⑤添加环境变量(mysql命令可直接使用)shell > echo ‘PATH=/usr/local/mysql/bin:$PATH’ >> /etc/profileshell > echo ‘export PATH’ >> /etc/profileshell > source /etc/profile⑥处理匿名登录和无密码问题mysql > select Host,User,Password from mysql.user;删除匿名用户mysql > delete from mysql.user where User=’’;修改用户密码mysql > update mysql.user set Password = password(‘123456’);刷新权限mysql > flush privileges;
三、Nginx
1.安装
①解决依赖shell > yum -y install pcre-devel zlib-devel openssl-devel②解压进入目录shell > tar zxf nginx-1.14.0.tar.gzshell > cd nginx-1.14.0③配置编译参数shell > ./configure –prefix=/usr/local/nginx-1.14.0 –with-http_ssl_module④编译并安装到目录shell > make && make install
2.配置
①添加启动服务https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/nginx的启动脚本文件,可以通过以上链接获得,放在 /etc/init.d/ 下shell > chmod +x /etc/init.d/nginxshell > chkconfig –add nginx②隐藏版本号
server_tokens off;
四、PHP
1.安装
①解压进入目录shell > tar zxf php-5.6.36.tar.gzshell > cd php-5.6.36②编译参数配置shell > ./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –enable-fpm –with-fpm-user=www –with-fpm-group=www –with-mysql=mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-iconv-dir –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir –enable-xml –disable-rpath –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –enable-mbregex –enable-mbstring –with-mcrypt –enable-ftp –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-xmlrpc –enable-zip –enable-soap –without-pear –with-gettext –disable-fileinfo –enable-maintainer-zts③解决遇到的依赖软件问题shell > yum -y install libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel④编译并安装到目录shell > make && make install
2.配置
①复制配置文件shell > cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confshell > cp /root/soft/php-5.6.36/php.ini-production /usr/local/php/etc/php.ini②添加php-fpm运行用户shell > groupadd wwwshell > useradd -s /sbin/nologin -g www -M www③添加启动服务shell > cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmshell > chmod +x /etc/init.d/php-fpmshell > chkconfig –add php-fpmshell > chkconfig php-fpm on④添加环境变量shell > echo ‘PATH=/usr/local/php/bin:$PATH’ >> /etc/profileshell > echo ‘export PATH’ >> /etc/profileshell > source /etc/profile⑤网站应用配置(nginx和php进行关联,告诉nginx,php在哪里)root html提升到最上边location ~ \.php$ {# root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;#php文件查找路径fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}$document_root加载的就是root的目录
版权声明:本文为xuzheng820原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。