- A+
所属分类:技术分享
这里以centos7作为服务器范例,其他版本大差不差!
数据库 mariadb(mysql)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | yum -y install mariadb mariadb-server systemctl start mariadb.service systemctl enable mariadb.service # 初始化数据库 mysql_secure_installation # 新用户 GRANT ALL PRIVILEGES ON db.* TO 'user'@'localhost' IDENTIFIED BY 'passwd'; FLUSH PRIVILEGES; # 改密码 SET PASSWORD FOR 'user'@'localhost' = PASSWORD('pass'); # 安全配置 vim /etc/my.cnf # add # [mysqld] # bind-address = 127.0.0.1 |
nginx
nginx如果需要某些高级特性,比如lua支持等,可以自己下载源码编译,这里直接用官方源yum安装!
1 2 3 4 5 6 7 8 9 10 11 12 13 | rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm yum -y install nginx systemctl restart nginx.service systemctl enable nginx.service # firewall(optional) firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --reload # curl localhost |
III. php7的安装与配置
php7有两个源可以选择,一个是webtatic提供的,也就是php70w,那个w指得就是webtatic,另一个可以使用remi源。
webtatic方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm yum -y install php70w php70w-opcache php70w-fpm php70w-mysql php70w-pdo php70w-pgsql php70w-xml php70w-mbstring php70w-mcrypt php70w-gd # or goto http://www.tecmint.com/install-and-compile-php-7-on-centos-7-and-debian-8/ # goto http://my.oschina.net/dingdayu/blog/513359?fromerr=Ob30V98l vim /etc/php.ini # 防止漏洞 # add # cgi.fix_pathinfo=0 sed -i 's/user = apache/user = nginx/' /etc/php-fpm.d/www.conf sed -i 's/group = apache/group = nginx/' /etc/php-fpm.d/www.conf systemctl enable php-fpm systemctl start php-fpm |
remi方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm yum --enablerepo=remi update remi-release yum --enablerepo=remi-php70 # 搜索PHP yum search php70 # 各取所需吧 yum install php70 php70-php-devel php70-php-fpm php70-php-mbstring php70-php-mcrypt php70-php-mysqlnd php70-php-gd php70-php-opcache php70-php-pdo php70-php-json php70-php-xml php70-php-pecl-xdebug php70-php-pecl-zip systemctl start php70-php-fpm.service systemctl enable php70-php-fpm.service sed -i 's/user = apache/user = nginx/' /etc/opt/remi/php70/php-fpm.d/www.conf sed -i 's/group = apache/group = nginx/' /etc/opt/remi/php70/php-fpm.d/www.conf # PHP的执行文件不再是php,而是被命名为php70,所以需要做一个软连接 # ➜ /home ll /usr/bin/|grep php # lrwxrwxrwx 1 root root 14 Dec 8 23:58 php -> /usr/bin/php70 # lrwxrwxrwx 1 root root 32 Dec 8 23:49 php70 -> /opt/remi/php70/root/usr/bin/php # lrwxrwxrwx 1 root root 36 Dec 8 23:49 php70-cgi -> /opt/remi/php70/root/usr/bin/php-cgi # lrwxrwxrwx 1 root root 33 Dec 8 23:57 php70-pear -> /opt/remi/php70/root/usr/bin/pear # lrwxrwxrwx 1 root root 38 Dec 8 23:49 php70-phar -> /opt/remi/php70/root/usr/bin/phar.phar # 其他以此类推 ln -s /usr/bin/php70 /usr/bin/php # PHP的配置文件位于 ls /etc/opt/remi/php70/|grep -E '\.conf|\.ini' # pear.conf # php-fpm.conf # php.ini # 还有php-fpm.d/php.d目录下的单独配置 # 需要注意的是session的文件路径需要写入权限,在php-fpm.d/www.conf下定义,默认在 /var/opt/remi/php70/lib/php/session/ 下,opcache、wsdlcache同理。 php -v # PHP 7.0.0 (cli) (built: Dec 1 2015 16:06:41) ( NTS ) # Copyright (c) 1997-2015 The PHP Group # Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies # with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend # # # Technologies # with Xdebug v2.4.0RC2, Copyright (c) 2002-2015, by Derick Rethans |
nginx 与 php-fpm
1 2 3 4 5 6 7 8 | mkdir -p /var/log/nginx/web # 以后将所有的虚拟主机配置放到这里 mkdir /etc/nginx/sites-available # 将所有运行中的站点放在这里 mkdir /etc/nginx/sites-enabled vim /etc/nginx/nginx.conf |
注意下面的配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | include /etc/nginx/sites-enabled/*.conf; location ~ .*\.(php|php5){ fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_split_path_info ^(.+?.php)(/.*)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; #fastcgi_cache phpgao; #fastcgi_cache_valid 200 302 1h; #fastcgi_cache_valid 301 1d; #fastcgi_cache_valid any 1m; #fastcgi_cache_min_uses 1; #fastcgi_cache_methods GET HEAD; #fastcgi_cache_use_stale error timeout invalid_header http_500; #fastcgi_cache_key $request_method://$host$request_uri; } |
最后重启服务
1 2 3 4 5 6 | # 检查配置 nginx -t # 重启 systemctl reload nginx.service # 或者 nginx -s reload |
OK,配置完成,然后享受php7带来的快感吧,不过前提就是你的PHP程序代码需要支持php7的语法!
2016年1月7日 下午10:27 沙发
0.0
2016年9月12日 上午9:58 板凳
能不能问一下,我老是找不到镜像源是什么原因
2016年9月12日 下午5:49 1层
@dumen 什么叫找不到镜像?搭建什么的时候出现的?
2016年9月13日 上午9:17 2层
@david 之前看别的教程,安装完lnmp之后升级php7的时候,一般出现 yum remove php* php-common 之后 ,然后执行了# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm成功, 但是安装 yum install php70w的时候经常是在查找完所有镜像后 提示没有更多镜像。每次出错就从新装一个虚拟机,装次数多了,有点记不清。
来自外部的引用: 1