注:我搭建是Centos6版本以上的,Centos7以上有大的改變php
rm -rf /etc/sysconfig/iptablesvim /etc/sysconfig/iptables複製代碼
添加一下內容:html
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended
.*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT
-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
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT複製代碼
:wq保存退出,重啓防火牆使配置生效mysql
/etc/init.d/iptables restart centos 7.0以上執行 systemctl restart firewalld.service複製代碼
關閉SELINUXlinux
rm -rf /etc/selinux/configvim /etc/selinux/config複製代碼
而後添加一行內容:nginx
SELINUX=disabled複製代碼
:wq 保存退出web
進行重啓系統sql
shutdown -r now複製代碼
注意:配置好防火牆必須重啓系統
yum install wget複製代碼
wget http://www.atomicorp.com/installers/atomic複製代碼
sh ./atomic複製代碼
yum check-update複製代碼
yum remove httpd* php*複製代碼
yum install -y nginx複製代碼
chkconfig nginx on Centos 7.0 以上執行 systemctl enable nginx.service複製代碼
service nginx startCentos 7.0 以上 systemctl start nginx.service複製代碼
Starting nginx:nginx:[emerg] socket() [::]:80 failed (97:Address family not supported by protocol) [FAILED]複製代碼
處理方法數據庫
vim /etc/nginx/conf.d/default.conf複製代碼
將vim
listen 80 default_server;
listen [::]:80 default_server;複製代碼
改成:centos
listen 80;#listen [::]:80 default_server;複製代碼
yum list installed | grep php複製代碼
yum remove php.x86_64 php-cli.x86_64 php-common.x86_64複製代碼
Centos 5.X
rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm
CentOs 6.x
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
CentOs 7.X
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm複製代碼
rpm -qa | grep webstaticrpm -e [上面搜索到的包便可]複製代碼
yum -y install php56w.x86_64
yum -y --enablerepo=webtatic install php56w-devel
yum -y install php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64
yum -y install php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-opcache.x86_64複製代碼
yum -y install php56w-fpm複製代碼
chkconfig php-fpm onCentos7.0以上 systemctl enable php-fpm.service複製代碼
/etc/init.d/php-fpm startCentos 7.0 以上 systemctl start php-fpm.service複製代碼
yum install -y mysql mysql-server複製代碼
/etc/init.d/mysqld start複製代碼
chkconfig mysqld on複製代碼
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf複製代碼
mysql_secure_installation複製代碼
Thanks for using MySQL!複製代碼
MySql密碼設置完成,從新啓動 MySQL:
#重啓
/etc/init.d/mysqld restart複製代碼
/etc/init.d/mysqld stop複製代碼
/etc/init.d/mysqld start複製代碼
我存放的nginx路徑地址
[root@iZ2zeftluibm3hesz36v3tZ conf.d]# pwd
/etc/nginx/conf.d
複製代碼
[root@iZ2zeftluibm3hesz36v3tZ conf.d]# ll
total 20
-rw-r--r-- 1 root root 1501 Feb 9 10:54 admin.shop.conf
-rw-r--r-- 1 root root 434 Dec 25 20:39 default.conf.bak
-rw-r--r-- 1 root root 1419 Feb 8 17:19 web.shop.conf
複製代碼
由於nginx.conf裏面
include /etc/nginx/conf.d/*.conf;
複製代碼
在/etc/nginx/conf.d下面新建一個.conf的文件 把這個東西複製進去
{
listen 80;
server_name 解析域名;
index index.php index.html index.htm default.html default.htm default.php;
client_header_buffer_size 16k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
client_body_buffer_size 128k;
location / {
root 項目路徑;
index index.php;
proxy_connect_timeout 3000;
proxy_send_timeout 3000;
proxy_read_timeout 3000;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
if (!-e $request_filename) {
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ \.php$ {
root 項目路徑;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
複製代碼
:wq 保存退出
vim /etc/php-fpm.d/www.conf複製代碼
user = nginx複製代碼
group = nginx複製代碼
cd /var/www
vim index.php
複製代碼
<?php
phpinfo();
?>
:wq!
複製代碼
#設置權限
chown nginx.nginx /var/www -R複製代碼
#重啓nginx
service nginx restart複製代碼
#重啓php-fpm
service php-fpm restart複製代碼
這時你的mysql數據庫不能遠程鏈接的,此時你應該受權一下
USE mysql; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION; FLUSH PRIVILEGES;複製代碼
到這裏就大體寫完了,網上搭建服務器環境的不少,我也是綜合各個前人經驗,加入一些本身的理解,但願對有須要的朋友能有一點小小的幫助。這裏推薦我上一篇Git版本庫的搭建哦。
哈哈,知識在於分享,願你們一塊成長。