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

CentOS6.8 安装 nginx + mysql+ php

2017-05-18 16:27 399 查看
参考转载: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.执行一下语句:

7.安装继续:

8.添加sysv启动脚本 # vim /etc/init.d/nginx

写入下边内容:

: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

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

安装mysql

1. 准备编译环境:

2.准备mysql数据库存放目录

3.更改数据目录权限。

#
chown -R mysql:mysql /mnt/data

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

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.设置开机启动:





注册为开机启动服务:





查看是否设置成功:

#
chkconfig –list mysql


10.设置PATH环境变量:



这里执行可能会报错:-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/。。。"



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命令,具体更新密码步骤如下:

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

方法2:用mysqladmin

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

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

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

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

1.安装依赖包:#
yum
install

libmcrypt
libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel
bzip2

bzip2
-devel


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


2.解压# tar xvf php源码包 -C /usr/local/src
3.# cd /usr/local/src/解压后的文件
4.执行 #

这边的出现了个小方框: 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配置文件。

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

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

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

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

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的测试页面,内容如下

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

?

?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: