安装Nginx
1:更新服务器系统
yum update
2:安装Nginx源
yum localinstallhttp://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
3:执行安装Nginx
yum install nginx
4:测试安装成功
[访问你的ip地址],例如:http://47.96.19.7/
PS:如果无法访问,请确保服务端已打开http 80端口
Mysql安装
1:安装Mysql源
yum localinstallhttp://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
2:安装mysql
yum install mysql-community-server
3:启动mysql
service mysqld start
4:查看mysql状态,出现PID,证明启动成功
service mysqld status
5:获取mysql默认生成密码
grep 'temporary password' /var/log/mysqld.log
6:修改默认密码
mysql -uroot -p
Enter password:输入上页的密码,进入mysql
mysql> use mysql;
mysql> update user set password=password('123') where user='root' and host='localhost';
mysql> flush privileges;
mysql> quit;
7:确认密码修改完成,即重新登陆mysql测试
PHP安装
注:本篇主要说明php7的安装、配置以及相关扩展
1.下载php7源码包
cd /usr/local & wget -O php7.tar.gzhttp://cn2.php.net/get/php-7.1.11.tar.gz/from/this/mirror
2.解压源码包
tar -xvf php7.tar.gz
3.进入目录
cd php7
4.安装php依赖包
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
5.编译配置
注意:安装依赖包如果安装不成功,编译也会出错
./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache
6:编译与安装
make && make install
7:添加 PHP 命令到环境变量
vim /etc/profile
在末尾加入
PATH=$PATH:/usr/local/php/bin
export PATH
要使改动立即生效执行
source /etc/profile
查看环境变量
echo $PATH
查看php版本
php -v
8:配置php-fpm
cp php.ini-production /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 sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
9:启动php-fpm
/etc/init.d/php-fpm start
配置Nginx支持php
1:创建nginx对应php项目配置文件conf
vim /etc/nginx/conf.d/test.com.conf
2:写入配置文件conf
server{
listen 80;
server_name test.com;
root /home/www/test.com; # 该项要修改为你准备存放相关网页的路径
location / {
index index.php index.html index.htm;
#如果请求既不是一个文件,也不是一个目录,则执行一下重写规则
if (!-e $request_filename)
{
#地址作为将参数rewrite到index.php上。
rewrite ^/(.)$ /index.php/$1;
#若是子目录则使用下面这句,将subdir改成目录名称即可。
#rewrite ^/subdir/(.
)$ /subdir/index.php/$1;
}
}
#proxy the php scripts to php-fpm
location ~ .php {
include fastcgi_params;
##pathinfo支持start
#定义变量 $path_info ,用于存放pathinfo信息
set $path_info "";
#定义变量 $real_script_name,用于存放真实地址
set $real_script_name $fastcgi_script_name;
#如果地址与引号内的正则表达式匹配
if ($fastcgi_script_name ~ "^(.+?.php)(/.+)$") {
#将文件地址赋值给变量 $real_script_name
set $real_script_name $1;
#将文件地址后的参数赋值给变量 $path_info
set $path_info $2;
}
#配置fastcgi的一些参数
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
###pathinfo支持end
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}
location ^~ /data/runtime {
return 404;
}
location ^~ /application {
return 404;
}
location ^~ /simplewind {
return 404;
}
}
3:重启nginx
service nginx reload
4:测试php是否成功
创建测试index.php
vim /home/www/test.com/index.php
输入:
phpinfo();
查看访问测试php
作者:Cyneric
链接:https://www.jianshu.com/p/b2fc2e7d5027
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。