安装php7
centos7默认安装php5,安装是比较方便,但因为太老,我们尝试安装php7。默认的centos7 yum库是不带 php7的源。
1.安装epel-release
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
2.安装PHP7的rpm源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
3.安装PHP7
yum -y install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64
如果需要安装php-fpm在后台运行,还需要安装如下的包
yum -y install php70w-fpm php70w-opcache
正常情况下安装成功。如果出现错误,可以留言在评论区。
4、启动php-fpm
systemctl start php-fpm
5、开机启动设置
systemctl enable php-fpm
systemctl daemon-reload
查看端口9000是不是已经启动,netstat -an |grep 9000,如果启动就算成功。
[root@lamp ~]# netstat -an |grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
成功!
6、配置nginx和php
首先创建一个文件,实际上nginx的默认根目录是在/usr/share/nginx/html
配置nginx,yum安装后的nginx默认的配置文件在/etc/nginx/nginx.conf,该文件中指明了当前conf.d中文件为模块的配置文件。安装之后有一个文件default.conf. 直接修/etc/nginx/conf.d/default.conf
[root@lamp conf.d]# vi default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
#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$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
我们把有关php配置的#去掉,#在配置文件中表示注释。
server {
listen 80;
server_name localhost;
#charset koi8-r;
access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
#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$ {
#修改1
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#修改2
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
注意:默认是访问到nginx的/usr/share/nginx/html的index页,如果是做网站,可以把我们自己的网站目录映射到/usr/share/nginx/html,
mount --bind test1 test2
把 test1 挂载到 test2,
如果test2目录有内容将被遮住(dir2目录的内容一样存在。就好像窗帘把窗户遮住一样。窗户始终存在,只是被遮住而已,等umount了,原来dir2目录的内容就显示出来了)
要取消挂载使用 umount 即可
如果在开机的时候自动挂载,可以在/etc/fstab里面增加以下内容
test1 test2 none bind 0 0