centos7安装nginx+php+mysql

修改系统配置

chmod +x /etc/rc.d/rc.local
echo "ulimit -n `cat /proc/sys/fs/nr_open`" >> /etc/rc.local
echo "ulimit -u 1048576" >> /etc/rc.local
echo "source /etc/profile" >> /etc/rc.local
echo "* soft nofile `cat /proc/sys/fs/nr_open`" >> /etc/security/limits.conf
echo "* hard nofile `cat /proc/sys/fs/nr_open`" >> /etc/security/limits.conf
echo "* soft nproc 1048576" >> /etc/security/limits.conf
echo "* hard nproc 1048576" >> /etc/security/limits.conf
sed -ri "s/^[^#]/#\0/" /etc/security/limits.d/*-nproc.conf

添加防火墙规则

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload

安装nginx

rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install -y nginx
systemctl enable nginx
systemctl start nginx

安装php

yum -y install php php-fpm php-mysqlnd php-mbstring php-gd
vi /etc/php.ini #修改date.timezone =Asia/Shanghai,并去掉前面的注释(分号)
systemctl start php-fpm
systemctl enable php-fpm

php-fpm工作进程是以apache用户启动的(查看/etc/php-fpm.d/www.conf文件可以看到,user和group的值都是apache),所以项目的文件以及文件夹的所属用户和用户组要修改为apache,否则php-fpm会没有权限读写项目文件,修改用户和用户组的命令:chown -R apache:apache fileordir,其中fileordir请修改为实际的文件或文件夹。

php错误日志路径:/var/log/php-fpm/www-error.log(在/etc/php-fpm.d/www.conf中的php_admin_value[error_log]参数定义的,/etc/php-fpm.d/www.conf的参数会覆盖/etc/php.ini的参数)

安装mysql

rpm -ivh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
yum install -y mysql-server
sed -i '/\[mysqld\]/a\lower_case_table_names=1' /etc/my.cnf
sed -i '/\[mysqld\]/a\max_connections=2000' /etc/my.cnf
sed -i '/\[mysqld\]/a\default-storage-engine=InnoDB' /etc/my.cnf
sed -i '/\[mysqld\]/a\character-set-server=utf8' /etc/my.cnf
systemctl start mysqld
systemctl enable mysqld

标签: centos7安装nginx+php+mysql

添加新评论