天天看點

CentOS6.8 安裝 nginx + mysql+ php

參考轉載: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"

] ;

exit

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

$1

;;

stop)

rh_status_q ||

exit

$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

;;

*)

echo

$

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

exit

2

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>

set

password

for

'root'

@

'localhost'

=

password

(

'newpasswd'

);

mysql>

set

password

for

'root'

@

'%'

=

password

(

'newpasswd'

); //本條可選

通過以上設定,root的密碼将變為newpasswd這樣就完成了根使用者root密碼的設定工作。

方法2:用mysqladmin

?

1

mysqladmin -u root

password

"newpass"

如果root已經設定過密碼,采用如下方法

?

1

mysqladmin -u root

password

oldpass

"newpass"

方法3: 用UPDATE直接編輯user表

?

1 2 3 4 5 6 7

mysql -u root

  mysql> use mysql;

  mysql>

UPDATE

user

SET

Password

=

PASSWORD

(

'newpass'

)

WHERE

user

=

'root'

;

  mysql> FLUSH

PRIVILEGES

;

在丢失root密碼的時候,可以這樣

?

1 2 3 4 5 6 7

mysqld_safe

--skip-grant-tables&

  mysql -u root mysql

  mysql>

UPDATE

user

SET

password

=

PASSWORD

(

"new password"

)

WHERE

user

=

'root'

;

  mysql> FLUSH

PRIVILEGES

;

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.執行 #

./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 '[email protected];pid = run/[email protected] = /usr/local/php/var/run/[email protected]' 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

?
?

繼續閱讀