centos 版本6.6
**1. 关闭防火墙**
service iptables stop
**2. 安装nginx**
方法1:rpm -ivh http://nginx.org/packages/centos/6/x86_64/RPMS/nginx-1.8.0-1.el6.ngx.x86_64.rpm
方法2:yum install nginx #默认不行
推荐:
#cd /etc/yum.repos.d/
#vim nginx.repophp
# nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
这样就可使用
#yum install nginx 安装更新了
chkconfig nginx on #开机启动
访问测试
你能够用下列方法检查配置文件是否有语法错误
/etc/init.d/nginx configtest
**3. 安装php**
yum install php php-fpm
php -m #查看已经安装的扩展
yum install php-mysql php-mbstring php-gd php-xml php-mcrypt #根据须要按照扩展库
chkconfig php-fpm on
安装mcrypt错误:No package php-mcrypt available.
方法1:
yum install epel-release //扩展包更新包
yum update //更新yum源,这句能够不用
yum install php-mcrypt
方法2:
动态加载编译
下载对应版本的php源码包http://cn.php.net/releases/,wget可能须要安装,yum install wget ,解压进入
cd /ext/mcrypt
phpize phpize是用来扩展php扩展模块的,经过phpize能够创建php的外挂模块
whereis php-config
./configure --with-php-config=/usr/bin/php-config
网上都是上面这种写法
直接 ./configure 这样也是能够的,若是提示错误须要提供php-config的路径,那确定就得上面那样写了
若是遇到如下错误,请先安装gcc,yum install gcc
configure: error: no acceptable C compiler found in $PATH
继续,
configure: error: mcrypt.h not found. Please reinstall libmcrypt
须要先安装libmcrypt
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
解压进去
./configure
若是遇到下面错误
centos configure: error: C++ compiler cannot create executables
安装gcc-c++
yum install gcc-c++
继续
./configure
make && make install
安装成功后,继续安装mcrypt,回到其目录下
./configure --with-php-config=/usr/bin/php-config
最后显示
Installing shared extensions: /usr/lib64/php/modules/
安装成功,而后须要给php添加该扩展
cd /etc/php.d
建立一个mrcypt.ini文件就行,里面写extension=mcrypt.so
echo 'extension=mcrypt.so' > mcrypt.ini
重启php-fpm,查看phpinfo
**4. 配置nginx支持php**
vi /etc/nginx/conf.d/default.conf
location ~ \.php$ {
root html;#注意这里须要改为根目录 /var/www 否则找不到php文件,若是在外面已写,这里不用写
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}#取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改成$document_root$fastcgi_script_name,或者使用绝对路径
service nginx restart #重启nginx
创建php文件,测试
**5. 安装mysql**
yum install mysql mysql-server
chkconfig mysqld on
mysql_secure_installation #安全配置向导
运行mysql_secure_installation会执行几个设置:
a)为root用户设置密码
b)删除匿名帐号
c)取消root用户远程登陆
d)删除test库和对test库的访问权限
e)刷新受权表使修改生效
经过这几项的设置可以提升mysql库的安全。建议生产环境中mysql安装这完成后必定要运行一次mysql_secure_installation。html
other method
#cd /etc/yum.repos.d/
#vim mysql-community.repomysql
[mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/ enabled=1 gpgcheck=0
#yum install mysql-community-server
#service mysqld start //启动的时候它会提示,有两种方法去休息root密码,推荐第二种
#/usr/bin/mysql_secure_installation
一路y
(完)linux
mysql 5.7 版本不太同样nginx
After you installed MySQL-community-server 5.7 from fresh on linux, you will need to find the temporary password from /var/log/mysqld.log to login as root.c++
grep 'temporary password' /var/log/mysqld.log
mysql_secure_installation
to change new password