您的位置:首页 > 运维架构 > Nginx

阿里云服务器搭建lnmp。Centos6.8 + nginx-1.10.3 + MySQL-5.6.16 + PHP-5.4.16

2017-08-02 11:45 746 查看
参考文献:http://www.jb51.NET/article/107429.htm

注意事项:1.英文引号的使用 和 –add(–list)前的–号(两个 - 线)

2.命令行代码要整行,不能断开

安装Nginx

1.准备工作

1.关闭SELINUX

修改配置文件,重启服务后永久生效。 # sed -i ‘s/SELINUX=.*/SELINUX=disabled/g’ /etc/selinux/config

命令行设置立即生效。 # setenforce 0

2.将源码包(tar.gz)都移至 /usr/local/src 目录下

3.在/usr/local/src下解压安装: # tar xvf (nginx.tar.gz–自己源码包)

4.安装工具:#yum groupinstall “Development tools”

# yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel

6.执行下列代码:

./configure \
--prefix=/usr/local/nginx \
--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.pid \
--lock-path=/var/run/nginx.lock \
--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 \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--wit
4000
h-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module


7.完成后执行编译:# make && make install

# mkdir -pv /var/tmp/nginx/client

8.# mkdir -pv /var/tmp/nginx/client

写入以下内容:之后,保存退出(按:wq!);

#!/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
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
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
killall -9 nginx
}
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


9.赋予脚本执行权限: # chmod +x /etc/init.d/nginx

10.添加至服务管理列表,设置开机自启:# chkconfig –add nginx

# chkconfig nginx on

11.启动服务:#service nginx start

12.查看是否成功: # cd /usr/sbin/ 进入后 # ./nginx

此时如果报错:[emerg]: getpwnam(“nginx”) failed ;

解决方法:# useradd -s /sbin/nologin -M nginx

13.然后浏览器上输入你的IP地址(阿里云公网),能出现 welcome to nginx! 既ok了。

阿里云服务器必须要开启80端口,管理-》安全组-》配置规则-》添加安全组规则 新增80端口访问

安装mysql

1.准备编译环境:# yum groupinstall “Server Platform Development” “Development tools” -y

# yum install cmake -y

2.准备mysql数据库存放目录: # mkdir /mnt/data

# groupadd -r mysql

# useradd -r -g mysql -s /sbin/nologin mysql

# id mysql

3.更改数据目录权限: # chown -R mysql:mysql /mnt/data

4.解压: # tar xvf (mysql编码包) -C /usr/local/src

进入解压后的包:# cd /usr/local/src/(解压后的mysql文件)

5.开始解压编译:(执行后可能会报错,报错解决方法位于文章最后)

—5.7需要1.59版本的库;你可以下载boost库然后编译boost库,或者下载带有boost库的mysql版本。则在代码后追加:-DDOWNLOAD_BOOST=1 \ 和 -DWITH_BOOST=/usr/local/mysql/boost/boost_1_59_0 \

# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mnt/data \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci


6.安装:# make && make install

7.修改安装目录的权限属组:# chown -R mysql:mysql /usr/local/mysql/

8.初始化数据库:# /usr/local/mysql/scripts/mysql_install_db –user=mysql –datadir=/mnt/data/

需要注意这里是mysql5.7以下的初始化命令,而5.7以上的都是用:

# /usr/local/mysql/bin/mysqld –initialize –user=mysql –basedir=/usr/local/mysql –datadir=/mnt/data/

9.复制配置文件:# cp support-files/my-default.cnf /etc/my.cnf

这里又有一点要注意:mysql5.7配置文件需要修改my.cnf关键配置, mysql5.7之前默认配置文件中是有配置项的,不用手动修改。以下为配置,根据实际情况修改:

</div>
<div>[mysqld]</div>
<div>basedir = /usr/local/mysql</div>
<div>datadir = /mnt/data</div>
<div>port = 3306</div>
<div>socket = /Ultrapower/test/mysql/tmp/mysql.sock</div>
<div></div>
<div>sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES</div>
<div>[client]</div>
<div>socket = /Ultrapower/test/mysql/tmp/mysql.sock</div>
<div>


10.设置开机启动:# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

# chmod +x /etc/init.d/mysql

11.注册为开机启动服务:# chkconfig mysqld on

# chkconfig –add mysqld

12.查看是否设置成功: chkconfig –list mysql

13..设置PATH环境变量:# echo “export PATH=$PATH:/usr/local/mysql/bin” > /etc/profile.d/mysql.sh

这里执行可能会报错:-bash: export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/

解决:进入/etc/profile.d/mysql.sh 注意”“双引号的格式和位置,正确为 eport PATH=”/usr/。。。”

# source /etc/profile.d/mysql.sh


14.启动服务:# service mysqld start

15.测试:如果刚安装好MYSQL,超级用户root是没有密码的,故直接回车即可

如果刚安装好MYSQL,超级用户root是没有密码的,故直接回车即可

#cd /usr/local/mysql

# mysql -uroot -p 一直回车,ok了;出现 mysql> 就ok了

16.登录mysql并修改密码:alter user ‘root’@’localhost’ identified by ‘newpassword’;

php安装

1.安装依赖包: yum install libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel

2 解压# tar xvf php源码包 -C /usr/local/src

3.解压 # tar xvf php源码包 -C /usr/local/src

# cd /usr/local/src/解压后的文件

4.执行:报错了提示缺少了什么就yum补上,文章末尾有参考方法。

# ./configure --prefix=/usr/local/php \
--with-config-file-scan-dir=/etc/php.d \
--with-config-file-path=/etc \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-fpm \
--enable-opcache \
--disable-fileinfo \
--with-jpeg-dir \
--with-iconv-dir=/usr/local \
--with-freetype-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-exif \
--with-curl \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-inline-optimization \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-ftp \
--with-gettext \
--enable-zip \
--enable-soap \
--with-bz2


执行以上的配置,如果出现下面这样的license,才是正确的,才可以开始编译,如果出问题,就解决,一般是少了什么库。

可以 # yum search 提示的软件名 ;例如安装GD库的时候,有个文件就得安装类似的 libjpeg 就要安装相

似软件包 libjpeg_xx_.x86_64

5.执行编译:# make && make install

6.添加php和php-fpm配置文件。

# cp /usr/local/src/php-7.0.16/php.ini-production /etc/php.ini
# cd /usr/local/php/etc/
# cp php-fpm.conf.default php-fpm.conf
# sed -i ‘s@;pid = run/php-fpm.pid@pid = /usr/local/php/var/run/php-fpm.pid@' php-fpm.conf


7.添加php-fpm启动脚本。

# cp /usr/local/src/php-7.0.16/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm


8.添加php-fpm至服务列表并设置开机自启。

# chkconfig –add php-fpm
# chkconfig –list php-fpm
# chkconfig php-fpm on


9.启动服务。# service php-fpm start

10.添加nginx对fastcgi的支持,首先备份默认的配置文件。

# cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak

# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf


11.编辑/etc/nginx/nginx.conf,在所支持的主页面格式中添加php格式的主页,类似如下

</div>
<div>location / {</div>
<div>root /usr/local/nginx/html;</div>
<div>index index.php index.html index.htm;</div>
<div>}</div>
<div>


12.取消以下内容前面的注释:注意fastcgi_param SCRIPT_FILENAME后面的内容

</div>
<div>location ~ \.php$ {</div>
<div>root /usr/local/nginx/html;</div>
<div>fastcgi_pass 127.0.0.1:9000;</div>
<div>fastcgi_index index.php;</div>
<div>fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name;</div>
<div>include fastcgi_params;</div>
<div>}</div>
<div>


13.测试是否成功,在/usr/local/nginx/html/新建index.php的测试页面

<?php

phpinfo();

?>


14.重启nginx : # service nginx reload

15.进入nginx安装目录sbin下,输入命令./nginx :# cd /usr/sbin 而后 # ./nginx (有错的话运行这里之后就会报错,然后查询解决)

nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

nginx: [emerg] still could not bind()—-问题描述:地址已被使用。可能nginx服务卡死了,导致端口占用,出现此错误。

lsof -i :80 查看被什么占用 ,然后 kill -9 xxxx(占用的数字),然后再重启,再./nginx

16.浏览器 输入ip地址 或 http://ip地址/index.php 若能成功出现信息,ok。

代码报错以及解决方案:

yum groupinstall “Server Platform Development” “Development tools” -y 无法执行时,
执行清空  yum clean all  再运行


报错:
-- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:82 (MESSAGE):
Curses library not found.  Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu , package name is libncurses5-dev ,
on RedHat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:126 (FIND_CURSES)
cmake/readline.cmake:216 (MYSQL_USE_BUNDLED_LIBEDIT)
CMakeLists.txt:256 (MYSQL_CHECK_READLINE)
-- Configuring incomplete, errors occurred!
是由于没有安装ncurses-develcmake会产生CMakeCache.txt文件,每次cmake之前需要删除它....
解决方案:先安装
ncurses-devel 包
yum install ncurses-devel
再删除刚才编译生成的 CMakeCache.txt
文件 rm MakeCache.txt
再次执行一次cmake ...


configure:
error: libpng.(a|so) not found.
configure一般的搜索编译路径为/usr/lib/下,因为PHP默认就在/usr/lib/下找相关库文件,而x64机器上是在:/usr/lib64.这时你就可以直接把需要的库文件从/usr/lib64中拷贝到/usr/lib/中去就可以了.
那么记得要在configure前执行如下的命令:
cp -frp /usr/lib64/libjpeg.* /usr/lib/


This article is post on https://coderwall.com/p/ggmpfa configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
复制代码 代码如下:
yum -y install libxslt-devel

configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.
复制代码 代码如下:
yum -y install net-snmp-devel

configure: error: Please reinstall readline - I cannot find readline.h
复制代码 代码如下:
yum -y install readline-devel

configure: error: Cannot find pspell
复制代码 代码如下:
yum -y install aspell-devel

checking for unixODBC support... configure: error: ODBC header file '/usr/include/sqlext.h' not found!
复制代码 代码如下:
yum -y install unixODBC-devel

configure: error: Unable to detect ICU prefix or /usr/bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works.
复制代码 代码如下:
yum -y install libicu-devel

configure: error: utf8mime2text() has new signature, but U8TCANONICAL is missing. This should not happen. Check config.log for additional information.
复制代码 代码如下:
yum -y install libc-client-devel

configure: error: freetype.h not found.
复制代码 代码如下:
yum -y install freetype-devel

configure: error: xpm.h not found.
复制代码 代码如下:
yum -y install libXpm-devel

configure: error: png.h not found.
复制代码 代码如下:
yum -y install libpng-devel

configure: error: vpx_codec.h not found.
复制代码 代码如下:
yum -y install libvpx-devel

configure: error: Cannot find enchant
复制代码 代码如下:
yum -y install enchant-devel

configure: error: Please reinstall the libcurl distribution - easy.h should be in /include/curl/
复制代码 代码如下:
yum -y install libcurl-devel

LAOGAO added 20140907:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
复制代码 代码如下:
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz tar zxf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install

added 20141003:
Cannot find imap
复制代码 代码如下:
ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so

configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing.
复制代码 代码如下:
yum -y install libc-client-devel

Cannot find ldap.h
复制代码 代码如下:
yum -y install openldap
yum -y install openldap-devel

configure: error: Cannot find ldap libraries in /usr/lib
复制代码 代码如下:
cp -frp /usr/lib64/libldap* /usr/lib/

configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
复制代码 代码如下:
yum -y install postgresql-devel

configure: error: Please reinstall the lib curl distribution
复制代码 代码如下:
yum -y install curl-devel

configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.
复制代码 代码如下:
yum -y install net-snmp-devel

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
复制代码 代码如下:
yum -y install libxslt-devel

checking for BZip2 support… yes checking for BZip2 in default path… not found configure: error: Please reinstall the BZip2 distribution
Fix:
复制代码 代码如下:
yum -y install bzip2-devel

checking for cURL support… yes checking if we should use cURL for url streams… no checking for cURL in default path… not found configure: error: Please reinstall the libcurl distribution – easy.h should be in/include/curl/
Fix:
复制代码 代码如下:
yum -y install curl-devel

checking for curl_multi_strerror in -lcurl… yes checking for QDBM support… no checking for GDBM support… no checking for NDBM support… no configure: error: DBA: Could not find necessary header file(s).
Fix:
复制代码 代码如下:
yum -y install db4-devel

checking for fabsf… yes checking for floorf… yes configure: error: jpeglib.h not found.
Fix:
复制代码 代码如下:
yum -y install libjpeg-devel

checking for fabsf… yes checking for floorf… yes checking for jpeg_read_header in -ljpeg… yes configure: error: png.h not found.
Fix:
复制代码 代码如下:
yum -y install libpng-devel

checking for png_write_image in -lpng… yes If configure fails try –with-xpm-dir=
configure: error: freetype.h not found.
Fix:
复制代码 代码如下:
Reconfigure your PHP with the following option. --with-xpm-dir=/usr

checking for png_write_image in -lpng… yes configure: error: libXpm.(a|so) not found.
Fix:
复制代码 代码如下:
yum -y install libXpm-devel

checking for bind_textdomain_codeset in -lc… yes checking for GNU MP support… yes configure: error: Unable to locate gmp.h
Fix:
复制代码 代码如下:
yum -y install gmp-devel

checking for utf8_mime2text signature… new checking for U8T_DECOMPOSE… configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.
Fix:
复制代码 代码如下:
yum -y install libc-client-devel

checking for LDAP support… yes, shared checking for LDAP Cyrus SASL support… yes configure: error: Cannot find ldap.h
Fix:
复制代码 代码如下:
yum -y install openldap-devel

checking for mysql_set_character_set in -lmysqlclient… yes checking for mysql_stmt_next_result in -lmysqlclient… no checking for Oracle Database OCI8 support… no checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h' not found!
Fix:
复制代码 代码如下:
yum -y install unixODBC-devel

checking for PostgreSQL support for PDO… yes, shared checking for pg_config… not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
Fix:
复制代码 代码如下:
yum -y install postgresql-devel

checking for sqlite 3 support for PDO… yes, shared checking for PDO includes… (cached) /usr/local/src/php-5.3.7/ext checking for sqlite3 files in default path… not found configure: error: Please reinstall the sqlite3 distribution
Fix:
复制代码 代码如下:
yum -y install sqlite-devel

checking for utsname.domainname… yes checking for PSPELL support… yes configure: error: Cannot find pspell
Fix:
复制代码 代码如下:
yum -y install aspell-devel

checking whether to enable UCD SNMP hack… yes checking for default_store.h… no
checking for kstat_read in -lkstat… no checking for snmp_parse_oid in -lsnmp… no checking for init_snmp in -lsnmp… no configure: error: SNMP sanity check failed. Please check config.log for more information.
Fix:
复制代码 代码如下:
yum -y install net-snmp-devel

checking whether to enable XMLWriter support… yes, shared checking for xml2-config path… (cached) /usr/bin/xml2-config checking whether libxml build works… (cached) yes checking for XSL support… yes, shared configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
Fix:
复制代码 代码如下:
yum -y install libxslt-devel

configure: error: xml2-config not found. Please check your libxml2 installation.
Fix:
复制代码 代码如下:
yum -y install libxml2-devel

checking for PCRE headers location… configure: error: Could not find pcre.h in /usr
Fix:
复制代码 代码如下:
yum -y install pcre-devel

configure: error: Cannot find MySQL header files under yes. Note that the MySQL client library is not bundled anymore!
Fix:
复制代码 代码如下:
yum -y install mysql-devel

checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h' not found!
Fix:
复制代码 代码如下:
yum -y install unixODBC-devel

checking for pg_config… not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
Fix:
复制代码 代码如下:
yum -y install postgresql-devel

configure: error: Cannot find pspell
Fix:
复制代码 代码如下:
yum -y install pspell-devel

configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.
Fix:
复制代码 代码如下:
yum -y install net-snmp-devel

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
Fix:
复制代码 代码如下:
yum -y install libxslt-devel
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐