Centos 7.4 LAMP搭建
查看centos 版本
$ cat /etc/redhat-release
安装nginx
$ yum install nginx
设置nginx开机起动
$ systemctl start nginx
测试访问http://域名或IP/
浏览器可看到nginx 相关信息
查看nginx安装位置
$ sudo find / -name nginx
安装php
$ 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 list php*查看是否有自己需要安装的版本,如果没有就需要添加第三方yum源
选择自己需要的php版本号 安装
$ yum install php72w-common
安装mysql
$ wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
$ rpm -ivh mysql-community-release-el7-5.noarch.rpm
$ yum install mysql-community-server
安装成功后重启mysql服务
$ service mysqld restart
设置MySQL密码
$ mysql -u root -p
$ set password for 'root'@'localhost' = password('yourpassword');
$ exit
安装php-fpm
搜索yum 源
$ sudo yum search php72
安装
$ yum install php72w-fpm
配置php处理器
$ vim /etc/php.ini
查找cgi.fix_pathinfo 将 ;cgi.fix_pathinfo=1
改为cgi.fix_pathinfo=0
配置www.conf
$ vim /etc/php-fpm.d/www.conf
将
user = nobody group = nobody
改为
user = nginx group = nginx
启动php-fom
$ systemctl start php-fpm
设置php-fpm 开机自启动
$ 设置php-fpm开机自启动
配置nginx
修改service 部分如下
index index.php index.html index.htm;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /data/www;
# Load configuration files for the default server block.
location ~ .php$ {
try_files $uri =404;
root /data/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
include /etc/nginx/conf.d/*.conf;
重启nginx
$ systemctl restart nginx