码迷,mamicode.com
首页 > 其他好文 > 详细

LNMP编译安装

时间:2019-01-15 14:14:05      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:freetype   toc   最新   inline   useradd   char   led   mysql用户   ima   

centos6.5+Nginx1.14+MySQL8.0+PHP7.0
一、Nginx编译安装(nginx-1.14.2.tar.gz)
1、下载Nginx源码
下载地址 http://nginx.org/en/download.html
有三个版本Mainline version(开发版)、Stable version(最新稳定版)和Legacy versions(老版稳定版)
3、安装前准备
安装pcre-devel包、Additional Development、Development Tools、openssl与openssl-devel等依赖工具
yum -y groupinstall "Development Tools" " Additional Development"
yum -y install pcre-devel openssl openssl-devel
创建用户与组
#groupadd -r nginx #useradd -r -g nginx nginx
创建目录
#mkdir -p /var/tmp/nginx/{proxy,client,fcgi}
4、解压与安装
#tar -zxvf nginx-1
#cd nginx-1.14.2
#./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre
#make && make install
5、为Nginx提供服务启动脚本
vim /etc/rc.d/init.d/nginx
#!/bin/sh
#nginx - this script starts and stops the nginx daemon
#chkconfig: - 85 15
#description: Nginx is an HTTP(S) server, HTTP(S) reverse \
#proxy and IMAP/POP3 proxy server
#processname: nginx
#config: /etc/nginx/nginx.conf
#config: /etc/sysconfig/nginx
#pidfile: /var/run/nginx.pid
#Source function library.
. /etc/rc.d/init.d/functions
#Source networking configuration.
. /etc/sysconfig/network
#Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
#make required directories
user=nginx -V 2>&1 | grep "configure arguments:" | sed ‘s/[^*]*--user=\([^ ]*\).*/\1/g‘ -
options=$nginx -V 2>&1 | grep ‘configure arguments:‘
for opt in $options; do
if [ echo $opt | grep ‘.*-temp-path‘ ]; then
value=echo $opt | cut -d "=" -f 2
if [ ! -d "$value" ]; then
echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1 ;;
stop)
rh_status_q || exit 0
$1;;
restart|configtest)
$1;;
reload)
rh_status_q || exit 7
$1;;
force-reload)
force_reload;;
status)
rh_status;;
condrestart|try-restart)
rh_status_q || exit 0;;
*)
echo $"Usage: $0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac

为启动脚本添加权限
#chmod +x /etc/rc.d/init.d/nginx
#chkconfig --add nginx
#chkconfig nginx on
#service nginx restart
启动中可能会遇到的问题
nginx: [emerg] getpwnam("nginx") failed #未建立nginx用户和用户组
查看端口是否监听
#netstat -tlunp |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0: LISTEN 6431/nginx
可以网页测试 浏览器输入IP地址 看到welcome to nginx 则表示成功
二、MySQL二进制安装(mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz)
1、先卸载之前版本的MySQL组件 #rpm -e
2、安装新版的MySQL组件
#rpm -ivh mysql-community-client-8.0.13-1.el6.x86_64.rpm
#rpm -ivh mysql-community-common-8.0.13-1.el6.x86_64.rpm
#rpm -ivh mysql-community-devel-8.0.13-1.el6.x86_64.rpm
#rpm -ivh mysql-community-libs-8.0.13-1.el6.x86_64.rpm
3、新建数据文件夹
#mkdir -p /mydata/data
4、新建mysql用户与组
#groupadd -r mysql
#useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
#chown mysql:mysql /mydata/data
5、安装MySQL8.0.13
#tar -Jxvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz -C /usr/local
#cd /usr/local
#ln -sv mysql-5.5.24-linux2.6-i686 mysql
#cd mysql
#chown -R mysql:mysql .
#/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/data --initialize-insecure
#chown -R root .
6、为MySQL提供主配置文件
#vi /etc/my.cnf
[mysqld]
server-id = 1
port = 3306
mysqlx_port = 33060
mysqlx_socket = /mydata/data/mysqlx.sock
datadir = /mydata/data
socket = /mydata/data/mysql.sock
pid-file = /mydata/data/mysqld.pid
log-error = /mydata/data/error.log
slow-query-log = 1
slow-query-log-file = /mydata/data/slow.log
long_query_time = 0.2
log-bin = /mydata/data/bin.log
relay-log = /mydata/data/relay.log
binlog_format =ROW
relay_log_recovery = 1
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect =‘SET NAMES utf8mb4‘
innodb_buffer_pool_size = 1G
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
log_timestamps = SYSTEM
lower_case_table_names = 0
default-authentication-plugin =mysql_native_password
sql_mode =NO_ENGINE_SUBSTITUTION
7、提供启动服务脚本
#cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
#vi /etc/rc.d/init.d/mysqld #更改一下几项
basedir=/usr/local/mysql
datadir=/mydata/data
mysqld_pid_file_path=/mydata/data/mysqld.pid
为启动脚本添加权限
#chmod +x /etc/rc.d/init.d/mysqld
#chkconfig --add mysqld
#chkconfig mysqld on
#service mysqld restart
8、添加MySQL的man手册
#vi /etc/man.conf
MANPATH /usr/local/mysql/man
9、输出mysql的头文件至系统头文件路径/usr/include
#ln -sv /usr/local/mysql/include /usr/include/mysql
10、输出mysql的库文件给系统库
#echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf
#ldconfig
11、修改PATH环境变量,让系统可以直接使用mysql的相关命令
12、常见报错
1251--Client does not support authentication protocol requested by server
#卸载之前的MySQL版本
ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2) #无套接字文件
ln -s /mydata/data/mysql.sock /var/lib/mysql/mysql.sock
三、PHP安装(php-7.0.33.tar.bz2)
1、安装前准备--解决软件依赖关系
安装mcrypt、mcrypt-devel、mhash、mhash-devel、libevent、libevent-devel与yum -y groupinstall "X Software Development"
2、解压并安装PHP
#tar -jxvf php-7.0.33.tar.bz2
#cd php-7.0.33
./configure --prefix=/usr/local/php --with-pdo-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --enable-mysqlnd --with-mysqli --with-pdo_mysql --enable-bcmath
#make
#make test
#make install
3、为PHP提供配置文件
#cp /usr/local/php.ini-production /etc/php.ini
4、为php-fpm提供配置文件
#cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
5、为PHP-FPM提供服务脚本文件
#cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
为启动脚本添加权限
#chmod +x /etc/rc.d/init.d/php-fpm
#chkconfig --add php-fpm
#chkconfig php-fpm on
#service php-fpm restart

常用报错
1、configure: error: mcrypt.h not found. Please reinstall libmcrypt.
#安装libmcrypt
2、/usr/local/src/php-5.6.38/ext/mysqli/php_mysqli_structs.h:63:23: 致命错误:my_global.h:没有那个文件或目录
./configure 加上 --enable-mysqlnd --with-mysqli
3、usr/local/src/php-5.6.38/ext/pdo_mysql/php_pdo_mysql_int.h:138:2: 错误:未知的类型名‘my_bool’ my_bool in_null;
./configure 加上 --with-pdomysql
4、configure: error: xml2-config not found. Please check your libxml2 installation
安装libxml2-devel
5、configure: error: Please reinstall the BZip2 distribution
安装bzip2-devel
6、configure: error: jpeglib.h not found
安装libjpeg-turbo-devel
7、configure: error: png.h not found
安装libpng-devel
8、configure: error: freetype-config not found
安装freetype-devel
9、
WARNING: Nothing matches the include pattern ‘/usr/local/php/etc/php-fpm.d/.conf‘ from /usr/local/php/etc/php-fpm.conf at line 125
#cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf 复制*
10、ERROR: failed to open configuration file ‘/usr/local/php/etc/php-fpm.conf‘: No such file or directory
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
四、整合nginx与php
1、编辑/etc/nginx/nginx.conf,启用如下选项:

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;
}
location / {
root html;
index index.php index.html index.htm;
}
2、编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
而后重新载入nginx的配置文件: # service nginx reload
3、在/usr/html新建index.php的测试页面,测试php是否能正常工作:
#cat > /usr/html/index.php << EOF
<?php
phpinfo();
?> 接着就可以通过浏览器访问此测试页面了。

LNMP编译安装

标签:freetype   toc   最新   inline   useradd   char   led   mysql用户   ima   

原文地址:http://blog.51cto.com/2937761/2342818

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!