CentOS6.8 安装 nginx + mysql+ php

来源:互联网 发布:苹果蜂窝移动网络位置 编辑:程序博客网 时间:2024/06/02 03:49

参考转载:http://www.jb51.net/article/107429.htm,原版里边有些许报错,进行了更正。

准备工作:官网下载tar.gz源码包(nginx-1.10.3  +  mysql-5.6.16 + php-5.4.16  )

安装nginx

1.关闭 selinux : #  sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config ---或是进入文件改也ok

2.生效: # setenforce 0

3.将nginx源码包移动: # cd  /usr/local/src

4.在/usr/local/src下解压安装: # tar xvf  (nginx.tar.gz)

安装工具: #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

5.解压后进入解压后的文件:#  cd . /usr/local/src/nginx解压后文件

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 \

--with-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.添加sysv启动脚本  # vim /etc/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"] ; exit0

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 ] || exit5

 [ -f $NGINX_CONF_FILE ] || exit6

 echo-n $"Starting $prog: "

 daemon $nginx -c $NGINX_CONF_FILE

 retval=$?

 echo

 [ $retval -eq0 ] && touch$lockfile

 return$retval

}

stop() {

 echo-n $"Stopping $prog: "

 killproc $prog -QUIT

 retval=$?

 echo

 [ $retval -eq0 ] && rm-f $lockfile

 return$retval

killall -9 nginx

}

restart() {

 configtest || return$?

 stop

 sleep1

 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/null2>&1

}

case"$1"in

 start)

 rh_status_q && exit0

 $1

 ;;

 stop)

 rh_status_q || exit0

 $1

 ;;

 restart|configtest)

 $1

 ;;

 reload)

 rh_status_q || exit7

 $1

 ;;

 force-reload)

 force_reload

 ;;

 status)

 rh_status

 ;;

 condrestart|try-restart)

 rh_status_q || exit0

  ;;

 *)

 echo$"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

 exit2

esac

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

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

10.启动服务:#service nginx start

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

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

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

# id nginx

然后浏览器上输入你的IP地址,能出现 welcome to nginx! 既ok了。


安装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文件)


# 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

5.安装:# make && make install ----很长时间

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

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

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

9.设置开机启动:

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

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

注册为开机启动服务:

# chkconfig mysqld on

# chkconfig --add mysqld

查看是否设置成功:

# chkconfig –list mysql

10.设置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

1)注意""双引号的格式和位置,正确为 eport PATH="/usr/。。。"

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

11.启动服务:# service mysqld start

12.测试:找到mysql的安装目录,一般可以直接键入命令mysql -uroot -p,回车后提示你输密码,如果刚安装好MYSQL,超级用户root是没有密码的,故直接回车即可进入到MYSQL中了,MYSQL的提示符是:mysql>

#cd /usr/local/mysql

# mysql -uroot -p

Enter password:  ---直接回车,ok了;出现 mysql>


***扩展:连接到远程主机上的MySQL

假设远程主机的IP为:10.0.0.1,用户名为root,密码为123。则键入以下命令:

mysql -h10.0.0.1 -uroot -p123

(注:u与root可以不用加空格,其它也一样)

退出MySQL命令:

exit (回车)


修改密码:

方法1:用SET PASSWORD命令,具体更新密码步骤如下:

?
1
2
3
4
5
c:>mysql -u root
 
mysql>setpassword for 'root'@'localhost'=password('newpasswd');
 
mysql>setpassword for 'root'@'%'=password('newpasswd'); //本条可选

通过以上设置,root的密码将变为newpasswd这样就完成了根用户root密码的设置工作。

方法2:用mysqladmin

?
1
mysqladmin -u root password"newpass"

如果root已经设置过密码,采用如下方法

?
1
mysqladmin -u root passwordoldpass "newpass"

方法3: 用UPDATE直接编辑user表

?
1
2
3
4
5
6
7
mysql -u root
 
  mysql> use mysql;
 
  mysql>UPDATEuser SET Password = PASSWORD('newpass')WHEREuser = 'root';
 
  mysql> FLUSH PRIVILEGES;

在丢失root密码的时候,可以这样

?
1
2
3
4
5
6
7
mysqld_safe--skip-grant-tables&
 
  mysql -u root mysql
 
  mysql>UPDATEuser SET password=PASSWORD("new password")WHEREuser='root';
 
  mysql> FLUSH PRIVILEGES;


php安装---最蛮长的等待

1.安装依赖包:#yuminstalllibmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2bzip2-devel

(后边还有很多没安装其的,到时提示什么,就yum下载安装什么)

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

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

4.执行 #

./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、、、、Thank you for using PHP  才算安装正确;

会一直报错:最后边有php出错的解决代码,根据报错解决;其中有某些软件包会找不到的,

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

5.成功运行出现Think you 之后; # make && make install

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

# cp /usr/local/src/自己的php软件包/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(自己的php软件包)/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格式的主页,类似如下:

         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 /usr/local/nginx/html/$fastcgi_script_name;

            include        fastcgi_params;

        } 

12.测试是否成功,在/usr/local/nginx/html/新建index.php的测试页面,内容如下

<?php

phpinfo();

?>

13.重启nginx :# service nginx reload

14.进入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

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





注意引号 '' 和 -- (两个减号)的使用和位置

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
?
?

原创粉丝点击