LNMP单点服务器搭建

一、部署服务器环境

Linux:centos6.5

nginx:1.14.0

mysql:5.6.33

php:5.6.36 

1.网络配置
2.FQDN
/etc/hosts
/etc/sysconfig/network
3.防火墙
iptables和selinux
4.yum源
epel和163源
5.安装vim
6.网络校时
7.lrzsz上传下载工具
二、Mysql
1.安装
①创建mysql用户,mysql启动使用这个用户
shell > groupadd mysql
shell > useradd -s /sbin/nologin -g mysql -M mysql
shell > tail -1 /etc/passwd
②安装cmake
yum -y install cmake
③解压并进行编译
tar zxvf mysql-5.6.33.tar.gz
cd 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-devel
shell > 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/mysqld
shell > chmod +x /etc/init.d/mysqld (因为mysql服务已经有执行权限,可以不执行此条命令)
shell > service mysqld start
shell > chkconfig --add mysqld(添加服务管理)
shell > chkconfig mysqld on(增加之后默认已经自启,此条可以不执行)
⑤添加环境变量(mysql命令可直接使用)
shell > echo 'PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
shell > echo 'export PATH' >> /etc/profile
shell > 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.gz
shell > 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/nginx
shell > chkconfig --add nginx

 ②隐藏版本号

server_tokens off;

 

四、PHP

1.安装

①解压进入目录
shell > tar zxf php-5.6.36.tar.gz
shell > 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.conf
shell > cp /root/soft/php-5.6.36/php.ini-production /usr/local/php/etc/php.ini
②添加php-fpm运行用户
shell > groupadd www
shell > useradd -s /sbin/nologin -g www -M www
③添加启动服务
shell > cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
shell > chmod +x /etc/init.d/php-fpm
shell > chkconfig --add php-fpm
shell > chkconfig php-fpm on
④添加环境变量
shell > echo 'PATH=/usr/local/php/bin:$PATH' >> /etc/profile
shell > echo 'export PATH' >> /etc/profile
shell > 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的目录
 
 
 

猜你喜欢

转载自www.cnblogs.com/xuzheng820/p/9076671.html