版本:
CentOS 7.3 + Apache 2.4 + PHP7.1 + MySQL 5.6
也附加了Nginx的启动和设置。
均使用YUM安装。
1. 安装Apache 2.4
#更新源:
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 httpd
#CentOS7启动服务:
systemctl start httpd.service
#CentOS7设置开机启动服务:
systemctl enable httpd.service
2. CentOS7安装MySQL 5.6
#更新源:
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
#安装MySQL5.6:
yum -y install mysql-community-server
#安装成功后,将其加入开机启动:
systemctl enable mysqld
#启动mysql服务进程:
systemctl start mysqld
#配置MySQL:
mysql_secure_installation
具体设置项:新安装MySQL之后设置
3. 安装PHP 7.1
安装与设置
#安装最新版:
yum -y install mod_php71w php71w-bcmath php71w-cli php71w-common php71w-devel php71w-fpm php71w-gd php71w-mbstring php71w-mcrypt php71w-mysql php71w-snmp php71w-xml php71w-process php71w-ldap net-snmp net-snmp-devel net-snmp-utils rrdtool
#查看版本:
php -v
#基础配置(保证一些基本使用):
vi /etc/php.ini
修改时区:把;date.timezone改为date.timezone =PRC;
memory_limit = 2048M
upload_max_filesize = 64M
测试
vim /var/www/html/index.php
<?php
phpinfo();
保存退出,浏览器访问:
测试成功示例图OK!
附加:安装git、npm、composer(如果有需要)
# yum install -y git
# yum install -y npm
# cd ~
# curl -sS https://getcomposer.org/installer | php --
# mv composer.phar /usr/local/bin/composer
# chmod -R 777 /usr/local/bin/composer
附加:配置PHP7-FPM与nginx(如果有需要)
vi /etc/php-fpm.d/www.conf
在第 8 行和第 10行,user 和 group 赋值为 nginx:
user = nginx
group = nginx
在第 22 行,确保 php-fpm 运行在指定端口:
listen = 127.0.0.1:9000
取消第 366-370 行的注释,启用 php-fpm 的系统环境变量:
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
保存文件并退出。
在 /var/lib/ 目录下创建一个新的文件夹 session,并将其拥有者变更为 nginx 用户:
mkdir -p /var/lib/php/session
chown nginx:nginx -R /var/lib/php/session/
启动 php-fpm 和 Nginx,并将它们设置开机启动
systemctl start php-fpm.service
systemctl start nginx.service
systemctl enable php-fpm
systemctl enable nginx
网友评论