數據包:php
nginx-1.12.0.tar.gzhtml
mysql-5.6.36.tar.gzmysql
php-5.6.11.tar.bz2linux
zend-loader-php5.6-linux-x86_64_update1.tar.gznginx
---------------------安裝Nginx-----------------------------c++
1、安裝壓縮包sql
tar zxvf nginx-1.12.0.tar.gz -C /opt數據庫
2、安裝編譯環境vim
yum install gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel -y緩存
3、建立管理用戶
useradd -M -s /sbin/nologin nginx
注:/bin/false是最嚴格的禁止login選項,一切服務都不能用,
/sbin/nologin只是不容許系統login,能夠使用其餘ftp等服務
4、編譯安裝
cd /opt/nginx-1.12.0/
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-file-aio \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_flv_module \
--with-http_ssl_module
make && make install
5、編寫啓動腳本、創建命令軟鏈接
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx
vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 99 20
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
chmod +x /etc/init.d/nginx
chkconfig --add nginx
systemctl start nginx
netstat -ntap | grep 80
---------------------------安裝mysql---------------------
1、安裝壓縮包
tar xzvf mysql-5.6.36.tar.gz -C /opt
2、安裝編譯環境
yum install -y ncurses-devel autoconf cmake bison libaio-devel
3、建立管理用戶
useradd -s /sbin/nologin mysql
mkdir -p /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
4、編譯安裝
cd /opt/mysql-5.6.36/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/home/mysql/ \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306
make && make install
------若是報錯,清空緩存文件-若是正常可忽略-------
find -name CMakeCache.txt
rm -f ./CMakeCache.txt
---------------------------------
5、設置環境變量和啓動服務
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add /etc/init.d/mysqld
chkconfig mysqld --level 235 on
6、初始化數據庫
/usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--ldata=/var/lib/mysql \
--basedir=/usr/local/mysql \
--datadir=/home/mysql
ln -s /var/lib/mysql/mysql.sock /home/mysql/mysql.sock /*直接創建軟鏈接*/
vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/home/mysql
service mysqld start
netstat -tnl 3306
mysql>show databases;
-------------------安裝php-----------------------
1、安裝壓縮包
tar xjvf php-5.6.11.tar.bz2 -C /opt
2、安裝編譯環境
yum -y install \
gd \
libpng \
libpng-devel \
pcre \
libjpeg-devel \
freetype-devel \
gettext-devel \
libXpm-devel \
libxml2-devel \
fontconfig-devel \
httpd-devel \
bzip2-devel
4、編譯安裝
cd php-5.6.11
./configure \
--prefix=/usr/local/php5 \
--with-gd \
--with-zlib \
--with-apxs2=/usr/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-config-file-path=/usr/local/php5 \
--enable-mbstring \
--enable-sqlite-utf8 \
--with-libxml-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-ttf \
--with-iconv \
--with-openssl \
--with-gettext \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--enable-static \
--enable-zend-multibyte \
--enable-inline-optimization \
--enable-sockets \
--enable-soap \
--enable-ftp \
--enable-fpm \
--disable-ipv6
make && make install
cp php.ini-development /usr/local/php5/php.ini //複製模版做爲php主配置文件
-----------提升php解析效率-----------
cd /abc
tar zxvf zend-loader-php5.6-linux-x86_64_update1.tar.gz -C /opt
cd zend-loader-php5.6-linux-x86_64/
cp ZendGuardLoader.so /usr/local/php5/lib/php/
vi /usr/local/php5/php.ini
zend_loader.enable=1 //開啓模塊
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
---------------------配置nginx支持php--------------------------
cd /usr/local/php5/etc/
cp php-fpm.conf.default php-fpm.conf ////複製模版做爲php-fpm主配置文件
ln -s /usr/local/php5/bin/* /usr/local/bin/
ln -s /usr/local/php5/sbin/* /usr/local/sbin/
vim php-fpm.conf
pid = run/php-fpm.pid //肯定pid文件路徑
user = nginx //表示由nginx用戶調用
group = nginx
pm.max_children = 50 //fpm模塊最大的進程數
pm.start_servers = 20 //啓動時開啓的進程數
pm.min_spare_servers = 5 //最小空閒進程數
pm.max_spare_servers = 20 //最大空閒進程數
php-fpm //killall php-fpm 關閉程序
---------------------------修改nginx啓動腳本---------------------
vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: 2345 99 20
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
PROG_FPM="/usr/local/sbin/php-fpm"
PIDF_FPM="/usr/local/php5/var/run/php-fpm.pid"
case "$1" in
start)
$PROG
$PROG_FPM
;;
stop)
kill -s QUIT $(cat $PIDF)
kill -s QUIT $(cat $PIDF_FPM)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
kill -s HUP $(cat $PIDF_FPM)
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
--------------------------------------------------------------------------
修改nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
location ~.php$ {
root html;
fastcgi_pass 127.0.0.1:9000; //php文件轉發給php-fpm 模塊
fastcgi_index index.php; //默認文件爲index.php
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; //包含fastcgi的配置文件
}
nginx -t
vi /usr/local/nginx/html//index.php
<?php
phpinfo();
?>
service nginx stop
service nginx start
systemctl stop firewalld.service
setenforce 0
在網頁測試「http://192.168.218.131/index.php」
--------下面測試數據庫工做是否正常-----
mysql -u root -p
CREATE DATABASE sky;
GRANT all ON sky.* TO 'skyuser'@'%' IDENTIFIED BY 'admin123';
flush privileges;
<?php
$link=mysql_connect('192.168.80.193','skyuser','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
mysql_close();
?>