centos LNMP环境搭配

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.repo

# 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。

other method
#cd /etc/yum.repos.d/
#vim mysql-community.repo

[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
(完)

mysql 5.7 版本不太一样

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.

  1. grep 'temporary password' /var/log/mysqld.log
  2. Run mysql_secure_installation to change new password

 

 

转载于:https://my.oschina.net/liufeng815/blog/471227

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值