1、关闭firewallad
关闭防火墙
systemctl stop firewalld.service
禁止firewall开机启动
systemctl disable firewalld.service
2、安装iptables防火墙
yum install iptables-services #安装
vi/etc/sysconfig/iptables #编辑防火墙配置文件
systemctl restart iptables.service #最后重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config 关闭selinux
1.nginx需要安装的包
下载pcre (支持nginx伪静态)
下载openssl(nginx扩展)
下载zlib(nginx扩展)
2.php需要安装的包
下载libmcrypt(php扩展)
下载yasm(php扩展)
t1lib(php扩展)
下载gd库安装包
libvpx(gd库需要)
tiff(gd库需要)
libpng(gd库需要)
freetype(gd库需要)
jpegsrc(gd库需要)
以上软件包使用WinSCP工具上传到/usr/local/src目录
WinSCP下载地址:http://winscp.net/download/winscp554.zip
/soft/ 存放源码安装包
源码包编译安装位置:/usr/local/软件名字
用yum安装编译工具和相关库
yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cmake cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel
一、安装Nginx
1、安装pcre 支持nginx伪静态
mkdir /usr/local/pcretar zxvf pcre-8.34.tar.gz
cd pcre-8.34./configure --prefix=/usr/local/pcremake && make installcd ../ && rm -rf pcre-8.34
2、安装openssl
mkdir /usr/local/openssltar zxvf openssl-1.0.2k.tar.gz
cd openssl-1.0.2k
./config --prefix=/usr/local/opensslmake
make installcd ../ && rm -rf openssl-1.0.2k
3、安装zlib
mkdir /usr/local/zlibtar zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8./configure --prefix=/usr/local/zlibmake && make installcd ../ && rm -rf zlib-1.2.8
4、安装Nginx
groupadd www
useradd-g www www -s /bin/false # /bin/false不允许登陆tar -xzf nginx-1.10.3.tar.gz
cd nginx-1.10.3./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/soft/openssl-1.0.2k --with-zlib=/soft/zlib-1.2.7 --with-pcre=/soft/pcre-8.34
make && make installcd ../ && rm -rf nginx-1.10.3
二、mysql
三、php
1、安装libmcrypt
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8./configuremake && make installcd ../ && rm -rf libmcrypt-2.5.8
2、安装yasm
tar -zxvf yasm-1.2.0.tar.gz
cd yasm-1.2.0./configuremake && make installcd ../ && rm -rf yasm-1.2.0
3、安装libvpx
tar -xjvf libvpx-v1.3.0.tar-4.bz2
cd libvpx-v1.3.0./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9 && make && make installcd ../ && rm -rf libvpx-v1.3.0
4、安装tiff
tar -zxvf tiff-4.0.3.tar.gz
cd tiff-4.0.3./configure --prefix=/usr/local/tiff --enable-sharedmake && make installcd ../ && rm -rf libvpx-1.6.1
5、安装libpng
tar -zxvf libpng-1.6.12.tar.gz
cd libpng-1.6.7./configure --prefix=/usr/local/libpng --enable-sharedmake && make install#编译安装
cd ../ && rm -rf libpng-1.6.7
6、安装freetype
tar -zxvf freetype-2.5.3.tar.gz
cd freetype-2.5.3./configure --prefix=/usr/local/freetype --enable-sharedmake && make install#编译安装
cd ../ && rm -rf freetype-2.5.3
7、安装jpeg
tar -zxvf jpegsrc.v9b.tar.gz
cd jpeg-9a
./configure --prefix=/usr/local/jpeg --enable-sharedmake && make installcd ../ && rm -rf jpeg-9a
8、安装libgd
tar -zxvf libgd-2.1.0.tar.gz
cd libgd-2.1.0./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpege--with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiffmake && make installcd ../ && rm -rf libgd-2.1.0
9、安装php
tar -zvxf php-5.5.38.tar.gz
cd php-5.5.38./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/data/mysql/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-zlib-dir=/usr/local/zlib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctypemake && make install
cp php.ini-production /usr/local/php/etc/php.ini #复制php配置文件到安装目录rm -rf /etc/php.ini #删除系统自带配置文件ln -s /usr/local/php/etc/php.ini /etc/php.ini #添加软链接到 /etc目录cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf #添加软连接到 /etc目录
vi /usr/local/php/etc/php-fpm.conf #编辑
user = www #设置php-fpm运行账号为www
group = www #设置php-fpm运行组为www
pid = run/php-fpm.pid #取消前面的分号
:wq! #保存退出
设置 php-fpm开机启动
cp /soft/php-5.5.38/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷贝php-fpm到启动目录chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限
chkconfig php-fpm on #设置开机启动
vi /usr/local/php/etc/php.ini #编辑配置文件
为了保障网站的安全性,禁用掉不安全的功能:
找到:disable_functions =
修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
找到:;date.timezone =
修改为:date.timezone = PRC #设置时区
找到:expose_php = On
修改为:expose_php = Off #禁止显示php版本的信息
找到:short_open_tag = Off
修改为:short_open_tag = ON #支持php短标签
找到opcache.enable=0
修改为opcache.enable=1 #php支持opcode缓存
opcache.enable_cli=0找到:
修改为:opcache.enable_cli=0
在最后一行添加:zend_extension=opcache.so #开启opcode缓存功能
:wq! #保存退出
配置nginx支持php
vi /usr/local/nginx/conf/nginx.conf
修改/usr/local/nginx/conf/nginx.conf 配置文件,需做如下修改
user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/php/etc/php-fpm.conf中的user,group配置相同,否则php运行出错
index index.html index.htm index.php;#添加index.php
#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#location~\.php$ {
root html;
fastcgi_pass127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}#取消FastCGI server部分location的注释,注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
:wq! #保存退出
/etc/init.d/nginx restart #重启nginx
service php-fpm start #启动php-fpm
测试篇
cd /usr/local/nginx/html/ #进入nginx默认网站根目录
rm -rf /usr/local/nginx/html/* #删除默认测试页
vi index.php #新建index.php文件
phpinfo();
?>
:wq! #保存退出
chown www.www /usr/local/nginx/html/ -R #设置目录所有者
chmod 755 /usr/local/nginx/html/ -R #设置目录权限
在浏览器中打开服务器IP地址,会看到下面的界面
发现nginx遇到 find not file 解决办法
在修改nginx配置文件
把$document_root改为/usr/local/nginx/html
测试mysql数据库连接
mysqladmin -uroot password pwd123
vim test.php
$link=mysql_connect('localhost','root','pwd123'); //单引号
if($link)
echo "恭喜你,数据库连接成功!";
mysql_close();
?>
如果显示出的文字为乱码,建议修改nginx.conf文件
vim /usr/local/nginx/conf/nginx.conf
去掉注视,改为 charset utf-8; 支持中文解析
在浏览器中打开服务器IP地址加 test.php,会看到下面的界面