1. 下載php
#MySQL下載地址html
http://dev.mysql.com/downloads/mysql/mysql
#Nginx下載地址nginx
http://nginx.org/en/download.htmlc++
#PHP下載地址sql
http://php.net/downloads.php後端
使用WinSCP把下載好的壓縮包上傳到/usr/local/src目錄api
mysql-5.7.16.tar.gz nginx-1.10.2.tar.gz php-7.0.12.tar.gzsession
2. 安裝curl
2.1 MySQL安裝
#安裝所需依賴
yum install gcc gcc-c++ cmakencurses ncurses-devel bison
#下載boost http://www.boost.org/users/download/
tar zxf boost_1_59_0.tar.gz
cp boost_1_59_0 /usr/local/boost
#建立運行用戶
groupadd mysql
useradd -r -g mysql -s /bin/falsemysql
#編譯安裝
cmake .-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_unicode_ci
make
make install
#更改權限
chown -R mysql /usr/local/mysql
chgrp -R mysql /usr/local/mysql
#初始化
cd /usr/local/mysql/bin
./mysqld --initialize--user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#拷貝配置文件
mv /etc/my.cnf/etc/my.cnf.bak
cd /usr/local/mysql/support-files
cp my-default.cnf /etc/my.cnf
#啓動和關閉
cd /usr/local/mysql/bin
./mysqld_safe --user=mysql
cd /usr/local/mysql/support-files
./mysql.server stop
#設置開機啓動
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755/etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
service mysqld start
service mysqld stop
service mysqld restart
#修改環境變量
vi/etc/profile
PATH=/usr/local/mysql/bin:$PATH
export PATH
source/etc/profile
#修改root密碼
cd /usr/local/mysql/bin
./mysql -uroot-p
mysql>alter user 'root'@'localhost' identified by '123456';
mysql>exit;
2.2 Nginx安裝
安裝pcre openssl zlib
#安裝依賴
yum install perl(openssl須要)
#安裝pcre
cd /usr/local/src
mkdir /usr/local/pcre
tar zxvf pcre-8.39.tar.gz
cd pcre-8.39
./configure --prefix=/usr/local/pcre
make
make install
#安裝openssl
cd /usr/local/src
mkdir /usr/local/openssl
tar xvf openssl-1.1.0.tar.gz
cd openssl-1.1.0
./config --prefix=/usr/local/openssl
make
make install
#安裝zlib
cd /usr/local/src
mkdir /usr/local/zlib
tar zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure --prefix=/usr/local/zlib
make
make install
#安裝Nginx
#建立運行用戶
groupadd www
useradd -g www www -s /bin/false
#編譯安裝
cd /usr/local/src
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure --prefix=/usr/local/nginx --user=www--group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.1.0 --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.39
make
make install
#測試配置文件是否正確
/usr/local/nginx/sbin/nginx -t
#啓動
/usr/local/nginx/sbin/nginx
2.3 PHP安裝
#安裝依賴
yum install libxml2 libxml2-devel curl-devel openjpeg openjpeg-devel openjpeg-libs libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel mcrypt php-mcrypt libmcrypt libmcrypt-devel bzip2 bzip2-devel
#建立運行用戶
groupadd -r php
useradd -r -g php -s /bin/flase php
#編譯安裝
./configure --prefix=/usr/local/php --with-mcrypt=/usr/include --with-mhash --with-openssl --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --without-gdbm --disable-fileinfo --with-bz2 --enable-maintainer-zts --with-libdir=lib64
make
make install
#拷貝配置文件
cp php.ini-development /usr/local/php/etc/php.ini
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
cp /usr/local/src/php-7.0.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#啓動
/etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
#配置Nginx代理PHP實現訪問
經過上面的操做,nginx和php-fpm服務都被咱們跑起來了,可是php-fpm走的是127.0.0.1:9000,外網是沒法訪問的,並且咱們也不可能直接經過php-fpm給外網提供服務,咱們用nginx去代理9000端口執行php。
實際上這個過程只須要對nginx進行配置便可,fpm已經在後臺運行了,咱們須要在nginx的配置文件中增長代理的規則,便可讓用戶在訪問80端口,請求php的時候,交由後端的fpm去執行,並返回結果。
vi /usr/local/nginx/conf/nginx.conf
把前面的#註釋符號去掉,把script改成$document_root最終以下:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;
include fastcgi_params;
}
這樣就OK了,從新載入nginx配置便可