阿里云CentOS安装php环境(lnmp):
1、安装nginx;
yum install nginx
2、安装mysql
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum install mysql-community-server
安装完mysql之后,系统已经生成了默认密码,可以通过以下命令查看:
cat /var/log/mysqld.log | grep 'password'
接下来我们重置下mysql账号的密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
3、安装php-7.1
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 search php71w
//安装php以及扩展
yum install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath
//开启服务
service php-fpm start
4、修改nginx配置文件:
建议在/etc/nginx/conf.d下面新建一个文件 "域名".conf,内容如下:
server {
charset utf-8;
client_max_body_size 128M;
listen 80; ## listen for ipv4
server_name 域名;
root 项目路径;
index index.php;
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php/$1 last;
}
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
try_files $uri =404;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/?.*)$;
fastcgi_param SCRIPT_FILENAME
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
}
error_page 404 /404.html;
location ~ /\.(ht|svn|git) {
deny all;
}
}
这时候可以在项目根目录新建index.php,使用phpinfo()打印PHP的相关信息,访问域名如果可以看到phpinfo那个熟悉的页面就说明配置已成功;
阿里云服务器默认并未开启80端口,所以需要手动在安全规则中添加80端口。