Fedora23搭建PHP开发环境
添加163镜像源。
$ cd /etc/yum.repos.d
$ wget http://mirrors.163.com/.help/fedora-163.repo
$ wget http://mirrors.163.com/.help/fedora-updates-163.repo
配置dnf自动选择最快的镜像源
$ vim /etc/dnf.conf
# 在文件末尾添加一行
fastestmirror=true
# wq保存退出
生成缓存
$ dnf clean all
$ dnf makecache
检查更新 && 升级更新
$ dnf check-update
$ dnf upgrade
添加RPM-Fusion源
$ su -c 'dnf install http://download1.rpmfusion.org/free/fedora/rpmfusion-$ free-release-$(rpm -E %fedora).noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm'
$ su -c 'dnf update'
添加Remi源
wget http://rpms.remirepo.net/fedora/remi-release-23.rpm
su -c 'dnf install remi-release-23.rpm'
dnf repolist all
安装Nginx Mainline version
$ vi /etc/yum.repos.d/nginx.repo
# 添加如下内容
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/rhel/7/$basearch/
gpgcheck=0
enabled=1
# wq保存退出
# 安装
$ dnf install nginx
# 查看版本
$ nginx -v
#启动服务并设置开机启动
$ sudo systemctl start nginx
$ sudo systemctl enable nginx
关闭Fedora系统防火墙
$ systemctl stop firewalld.service
$ systemctl disable firewalld.service
此时通过浏览器打开虚拟机的IP地址应该可以看到nginx的测试页面了
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
安装MariaDB
$ sudo vi /etc/yum.repos.d/MariaDB.repo
# 复制如下内容到文件中,这里Fedora21的源始终连不上,所以使用Rhel7的源安装。
# MariaDB 10.1 RedHat repository list - created 2016-02-03 16:56 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/rhel7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
# 保存退出
# 安装
$ sudo dnf install MariaDB-server MariaDB-client
# 查看安装版本
$ mysql --version
# 启动服务并设置开机启动
$ sudo systemctl start mariadb
$ sudo systemctl enable mariadb
#配置安全设置
$ sudo mysql_secure_installation
安装php7
# 编辑remi-php70.repo文件启用该源。
$ vi /etc/yum.repos.d/remi-php70.repo
# 更改 enabled值为1 即 enabled=1
# 保存退出
# 安装
$ dnf install php php-fpm
# 查看版本和模块
$ php --version
$ php --modules
# 启动服务并设置开机启动
$ sudo systemctl start php-fpm
$ sudo systemctl enable php-fpm
配置Nginx转发到Php-fpm
$ sudo vi /etc/nginx/conf.d/default.conf
编辑内容如下
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.php index.html index.htm;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
测试一下配置文件是否正确,然后重启服务
$ sudo nginx -t
$ sudo systemctl restart nginx
新建php文件进行测试
$ vi /usr/share/nginx/html/index.php
添加一段php代码
<?php phpinfo(); ?>
现在打开浏览器输入Fedora虚拟机的IP地址,正确的话应当看见PHP信息的页面。
如果打开页面超时,尝试关闭Fedora的防火墙。Fedora23使用的防火墙叫做Firewalld
$ sudo systemctl stop firewalld
$ sudo systemctl disable firewalld
安装Composer
$ sudo dnf install composer