说明:闲来无事,用虚拟机安装了CentOS7版本的linux,搞了下PHP环境的安装(分装,其实有很多一键shell集成安装包的,总感觉学习就要一步一步来,才有成就),之前只是弄一些简单的服务器上的操作,纯属小学生,仅供自己温习,有想借鉴的瞅瞅也行,有误导的地方,见谅~!
一. 准备工作
①预先安装虚拟机vm11,用的就是百度推荐当前的那个。
vm11序列号:1F04Z-6D111-7Z029-AV0Q4-3AEH8,具体安装说明不必多说
②下载centos7的安装包,
下载地址:
http://www.centoscn.com/plus/download.php?open=2&id=5070&uhash=30d461226e4a5148bf1cb899
放在虚拟机下安装,详细也不多说,很简单
③启动虚拟机,简单配置一下系统相关
*关闭内置防火墙(弃用自带的防火墙、启用iptables防火墙)
[root@localhost ~]# systemctl stop firewalld.service #停止firewall
[root@localhost ~]# systemctl disable firewalld.service #禁止firewall开机启动
*安装iptables防火墙
[root@localhost ~]# yum install iptables-services 安装
*修改iptables配置
[root@localhost ~]# vim /etc/sysconfig/iptables 编辑防火墙配置文件
在 -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT下面添加 这两项:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
保存退出:wq
*启动并设置开机启动
[root@localhost ~]# systemctl restart iptables.service 重启新防火墙使配置生效
[root@localhost ~]# systemctl enable iptables.service 设置防火墙开机启动
④更新系统:
[root@localhost ~]# vim /etc/yum.repos.d/CentOS-Base.repo
*修改内容:
将所有
"baseurl=http://mirror.**centos**.org/centos/$releasever/os/$basearch/"
修改为
"baseurl=http://mirrors.**shlug**.org/centos/$releasever/os/$basearch/"
保存退出:wq
⑤更新软件库
[root@localhost ~]# yum -y upgrade
*安装所需库
[root@localhost ~]# yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel
⑥软件目录:
/usr/local/src #软件源代码包存放位置
/usr/local/software #软件安装位置
⑦下载所需安装包
nginx:
[root@localhost ~]# wget http://nginx.org/download/nginx-1.7.4.tar.gz
mysql:
[root@localhost ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
二、安装编译工具及库文件
*安装编译基础库
[root@localhost ~]# yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel
*安装nginx
先看系统有无nginx
[root@localhost ~]# find -name nginx
有可先卸载
[root@localhost ~]# yum remove nginx
进入nginx下载目录
[root@localhost ~]# tar -xvf nginx-1.7.4.tar.gz
[root@localhost ~]# cd nginx-1.7.4.tar.gz
[root@localhost ~]# ./configure --prefix=/usr/local/nginx
cmake && make install
安装成功,查看一下nginx安装目录
[root@localhost ~]# whereis nginx
不成功,主要是某些依赖库没有安装好
*安装mysql
mysql在centos7.0版本中被mariadb替代了
[root@localhost ~]# yum install mysql-server mysql
不想用可以安装下面版本
[root@localhost ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
[root@localhost ~]# yum install mysql-community-server
[root@localhost ~]# service mysqld restart
初次安装mysql是root账户没有密码
[root@localhost ~]# mysql -uroot
mysql> use mysql;
mysql> set password for ‘root’@‘localhost’ = password('123');
或
mysql> update user set `password`=password('123') where user='root';
mysql> flush privileges;
mysql> exit
*安装PHP
[root@localhost ~]# yum install php php-mysql php-fpm
把php-fpm加入开机启动
[root@localhost ~]# systemctl start php-fpm
[root@localhost ~]# systemctl enable php-fpm.service
三、修改相关配置
**nginx**:
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
①去掉下面注释;
②把/script$fastcgi_script_name;
↓
$document_root$fastcgi_script_name
(这个很重要,不然你的虚拟目录会找不到,出现 page not found)
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /mnt/www/weixin;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
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;
}
③虚拟目录可以改至你想制定的目录了
location / {
root /mnt/www/weixin;
index index.php index.html index.htm;
}
**PHP**
[root@localhost ~]# vim /etc/php.ini
修改你要改的配置了,和windows中的一样。。
其他可以看老外的强文
https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7
PS: 这玩意儿,配一下就知道怎么回事儿了,不然 遇到问题挺蛋疼。。