版权声明:本文为博主原创文章,拒绝相同的垃圾博文。 https://blog.csdn.net/tsummerb/article/details/80212117
一、编译安装php7.1
①下载php的稳定版本:http://php.net/ 并解压,我下载是的php7.1.16,下载之后将压缩文件放到合适的位置,此处放在了/usr/lib目录下
命令:tar -zxvf php-7.1.16.tar
②编译configure
命令:cd php-7.1.16
./configure --enable-fpm --enable-inline-optimization --disable-debug
③执行sudo make 和 sudo make install 安装
④查看php、php-fpm是否安装成功
查看php的可执行路径:which php
查看php的版本号:php-v
查看php-fpm的可执行路径:which php-fpm
查看php-fpm的配置文件路径:whereis php-fpm
⑤配置php-fpm
命令:cd /usr/local/etc/ cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d cp www.conf.default www.conf
修改www.config中的user和group为所属的用户和用户组
启动php-fpm:which php-fpm查看php-fpm的可执行路径,然后执行即可启动php-fpm
二、安装nginx
命令:sudo apt-get install nginx
查看nginx的相关位置:whereis nginx
Nginx的默认网站目录是 /usr/share/nginx/html/,默认Nginx网站配置文件为 /etc/nginx/sites-available/default 。
具体的nginx配置如下:cd /etc/nginx/sites-available/ cp default test.conf
具体的test.conf的配置如下:
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
root /var/www/sites;
index index.php index.htm index.html;
server_name 127.0.0.1;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
需要注意:nginx和php-fpm的通信有两种,一种是通过ip和端口号通信,另一种是通过sock通信,两者的区别
前者可以跨服务器,而UNIX Domain Socket不经过网络,只能用于Nginx跟PHP-FPM都在同一服务器的场景,用哪种取决于PHP-FPM配置。
配置完成之后,启动nginx,用which nginx查看nginx的可执行路径,执行路径即可启动。
三、安装mysql
sudo apt-get install mysql-server
安装过程中会让你为 MySQL root用户设置密码,安装完毕,执行
mysql -u root -p,之后输入密码,即可操作mysql。
至此php、php-fpm、nginx以及mysql都安装完毕,创建网站项目之后,执行curl 127.0.0.1即可查看运行结果。