centos6.5 安裝PHP7+nignx+msyql

安裝PHP

安裝PHP相關依賴

yum install enchant enchant-devel gmp-devel libc-client libc-client-devel pam-devel firebird-devel libicu-devel openldap openldap-devel libmcrypt-devel unixODBC-devel freetds freetds-devel
yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzsz
yum install -y libtool libtool-ltdl-devel 
yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-devel
yum install -y python-devel  patch  sudo 
yum install -y openssl* openssl openssl-devel ncurses-devel
yum install -y bzip* bzip2 unzip zlib-devel
yum install -y libevent*
yum install -y libxml* libxml2-devel
yum install -y libcurl* curl-devel 
yum install -y readline-devel

make && make install && make clean

源碼安裝

wget http://cn2.php.net/distributions/php-7.0.12.tar.gz
tar xzf php-7.0.12.tar.gz 
cd cd php-7.0.12


./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-inline-optimization --enable-session --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-curlwrappers --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-readline

make

make install && make clean

 ln -s /usr/local/php/bin/php /usr/local/bin/php
 ln -s /usr/local/php/sbin/php-fpm /usr/local/bin/php-fpm
 
 php -v
PHP 7.0.12 (cli) (built: Oct 24 2016 22:29:41) ( NTS )

PHP 5.6及以上已經內置了php-fpm,不須要再使用外掛的方式安裝php-fpm。只須要編譯時加上「--enable-fpm」參數便可。php

以上爲只標註了部份php擴展,如需打開所有擴展,能夠使用"--enable-all",如若須要查看具體參數說明,可經過以下命令查看:html

> ./configure --help

錯誤處理

ext/date/php_date.lo' is not a valid libtool object

./configure 後,直接make可能會出現libtool: link: 'ext/date/php_date.lo' is not a valid libtool object 的錯誤。 make clean 一下而後再make,便可。緣由未知,多是某些腳本執行順序的問題?作個標記~python

配置PHP

A,配置php.ini文件

cp /root/php-7.0.12/php.ini-production /usr/local/php/etc/php.ini

vim /usr/local/php/etc/php.ini

> display_errors=Off

> default_time_zone=Asia/Chongqing

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf


#### B,啓動php-fpm

> # /usr/local/php/sbin/php-fpm -D

安裝 nginx

安裝依賴

yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-develmysql

源碼安裝

wget http://nginx.org/download/nginx-1.11.5.tar.gz
tar xzf nginx-1.11.5.tar.gz
cd nginx-1.11.5

./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx  \
--conf-path=/usr/local/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/cache/nginx/client_temp  \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp  \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp  \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp  \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp  \
--user=nginx  \
--group=nginx   \
--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-file-aio  \
--with-ipv6  \
--with-pcre  

make

make install && make clean

nginx -v
    nginx version: nginx/1.11.5

vim /usr/local/nginx/nginx.conf


#/usr/sbin/groupadd -f nginx
#/usr/sbin/useradd -g nginx nginx

錯誤處理

nginx安裝 nginx: [emerg] getpwnam(「www」) failed 錯誤 參考

linux 64系統中安裝nginx1.3時若是出現錯誤:nginx: [emerg] getpwnam(「www」) failedlinux

  • 解決方法1: 在nginx.conf中 把user nobody的註釋去掉既可
  • 解決方法2: 錯誤的緣由是沒有建立nginx這個用戶,應該在服務器系統中添加nginx用戶組和用戶nginx,以下命令:
#/usr/sbin/groupadd -f nginx
#/usr/sbin/useradd -g nginx nginx

安裝 Mysql

安裝依賴

yum -y install make gcc-c++ cmake bison-devel ncurses-devel perl


wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
tar xzf boost_1_59_0.tar.gz
cd boost_1_59_0
./bootstrap.sh

./b2 install --prefix=/usr/local/boost


# 建立用戶,組

groupadd mysql
mkdir /home/mysql  #自定義位置
mkdir /home/mysql/data  #自定義位置
useradd -g mysql -d /home/mysql mysql

下載安裝

安裝5.7*版本沒有搞好nginx

wget https://github.com/mysql/mysql-server/archive/mysql-5.6.34.tar.gz
tar xzf mysql-5.7.15.tar.gz 
cd mysql-server-mysql-5.7.15

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost

make && make install

初始化數據庫

進入安裝補錄下的bin目錄下,執行c++

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/data

注:默認密碼爲空git

調整配置文件和環境變量參數

將默認生成的my.cnf備份github

> mv /etc/my.cnf /etc/my.cnf.bak
> cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

# 以下是我修改配置文件/etc/my.cnf, 用於設置編碼爲utf8以防亂碼

[mysqld]

character_set_server=utf8

init_connect='SET NAMES utf8'

[client]

default-character-set=utf8

# 複製啓動腳本到init.d下
> cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

# 增長執行權限
> chmod 755 /etc/init.d/mysqld

# 建立mysql命令文件
> ln -s /usr/local/mysql/bin/mysql /usr/sbin/mysql 
注:沒有這個文件就沒有mysql命令,不能在任意位置使用mysql 訪問數據庫

啓動mysql

service mysqld startsql

訪問數據庫

mysql -uroot -p

修改默認密碼

use mysql; update user set password=PASSWORD("123456") where user='root';

建立超級用戶

GRANT ALL PRIVILEGES ON . TO 'admin'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;

GRANT ALL PRIVILEGES ON pengshi_develop.* TO 'admin'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON pengshi_develop.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '123456' WITH GRANT OPTION;

配置開機啓動

vim /etc/rc.d/rc.local

# 添加以下參數
/usr/sbin/nginx

/usr/local/bin/php-fpm -D

service mysqld start

# 而後
chmod +x /etc/rc.d/rc.local
相關文章
相關標籤/搜索