CentOS 6.3安裝配置nginx+php+mysql_Linux

來源:互聯網
上載者:User

準備篇

1.配置防火牆,開啟80連接埠、3306連接埠

1 vim /etc/sysconfig/iptables
2 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT   #允許80連接埠通過防火牆
3 -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #允許3306連接埠通過防火牆

service iptables restart    #重啟防火牆,使配置生效

2.關閉SELINUX(這個和伺服器安全相關,先關閉。相關介紹:https://wiki.centos.org/zh/HowTos/SELinux)

vim /etc/selinux/config#SELINUX=enforcing   #注釋掉#SELINUXTYPE=targeted  #注釋掉SELINUX=disabled    #增加:wq           #儲存退出  shutdown -r now     #重啟系統

3.安裝第三方源

1)安裝EPEL倉庫

yum install -y epel-release

如果以上命令不起作用:

CentOS/RHEL 7

rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

CentOS/RHEL 6

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

2)安裝IUS倉庫

CentOS 6

rpm -Uvh https://centos6.iuscommunity.org/ius-release.rpm

CentOS 7

rpm -Uvh https://centos7.iuscommunity.org/ius-release.rpm

錯誤處理:

1.安裝IUS倉庫出錯:curl: (35) SSL connect error。這個問題在RHEL 6.1 -> RHEL 6.4應該都會出現,原因是curl使用了REST API。解決:

yum update nss

2.結果問題1沒解決,出另一個問題:Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again。解決:

vim /etc/yum.repos.d/CentOS-Base.repo

把有mirrorlist的都注釋掉,有baseurl的都去掉注釋,然後再進行步驟1,再安裝IUS倉庫。修改如下:

[epel]name=Extra Packages for Enterprise Linux 6 - $basearchbaseurl=http://download.fedoraproject.org/pub/epel/6/$basearch#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearchfailovermethod=priorityenabled=1gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6[epel-debuginfo]name=Extra Packages for Enterprise Linux 6 - $basearch - Debugbaseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearchfailovermethod=priorityenabled=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6gpgcheck=1[epel-source]name=Extra Packages for Enterprise Linux 6 - $basearch - Sourcebaseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearchfailovermethod=priorityenabled=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6gpgcheck=1

 查看倉庫列表,看看是否安裝成功了:

yum repolist

ius                                                                             | 2.3 kB   00:00   ius/primary_db                                                                       | 183 kB   00:00   repo id                             repo name                                                  statusbase                              CentOS-6 - Base                                               5,062epel                              Extra Packages for Enterprise Linux 6 - i386                                 9,992extras                             CentOS-6 - Extras                                                39ius                               IUS Community Packages for Enterprise Linux 6 - i386                              329updates                             CentOS-6 - Updates                                               382repolist: 15,804

安裝倉庫成功。接下來安裝nginx,mysql,php。

安裝篇

查看即將要安裝的軟體的版本:

yum list nginx mysql php

結果:

[root@localhost ~]# yum list nginx mysql phpLoaded plugins: fastestmirror, securityLoading mirror speeds from cached hostfile* base: mirrors.163.com* extras: mirrors.163.com* ius: hkg.mirror.rackspace.com* updates: mirrors.163.comAvailable Packages    mysql.i686 5.1.73-7.el6 base nginx.i686 1.10.1-1.el6 epel php.i686 5.3.3-48.el6_8 updates

mysql和php的版本都有些舊,他們都來源於mirrors.163.com這個源。而epel和ius源的軟體版本一般比較新。

使用以下命令列出所有mysql和php的版本:

yum list mysql* php*

這會列出一大堆像這樣的結果,接下來只要選擇需要安裝的軟體版本就好:

軟體名字                軟體版本                            #軟體所在倉庫
php56u.i686 5.6.26-1.ius.centos6 ius mysql55.i686 5.5.52-1.ius.centos6 ius 安裝nginxyum remove httpd* php* #刪除系統內建的軟體包yum install nginx    #安裝nginx 根據提示輸入y進行安裝chkconfig nginx on    #設定nginx開機啟動service nginx start #啟動nginx安裝MySQLyum remove mysql*    #刪除系統已經安裝的mysqlyum list mysql*   #列出mysql所有版本,找到要安裝的版本的名字yum install mysql57u* #我安裝的是mysql5.7.15。輸入Y即可自動安裝,直到安裝完成service mysqld start #啟動MySQLchkconfig mysqld on   #設為開機啟動

安裝PHP

yum install php56u-fpm php56u-mbstring php56u-bcmath php56u-mcrypt php56u-xmlrpc php56u-pdo php56u-xml php56u-xmlrpc php56u-mysqlnd php56u-gd php56u-opcache    #安裝php5.6及擴充chkconfig php-fpm on  #設定php-fpm開機啟動service php-fpm start  #啟動php-fpm

配置篇

 nginx的設定檔是/etc/nginx下的nginx.conf。在nginx.conf檔案的最後一行可以看到: include /etc/nginx/conf.d/*.conf; 它把 /etc/nginx/conf.d目錄下尾碼為.conf的檔案都包含進來了,所以只要在/etc/nginx/conf.d/這個目錄下配置一個.conf檔案就行了。以下是我的配置:

## The default server#server {  listen    80;  server_name n.com;  root     /usr/share/nginx/html;  index index.php index.html;  # Load configuration files for the default server block.  location / {  try_files $uri $uri/ /index.php?$args;  }  location ~ .*\.(php)?$ {    expires -1s;    try_files $uri =404;    fastcgi_split_path_info ^(.+\.php)(/.+)$;    include fastcgi_params;    fastcgi_param PATH_INFO $fastcgi_path_info;    fastcgi_index index.php;    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;    fastcgi_pass 127.0.0.1:9000;  }  error_page 404 /404.html;    location = /40x.html {  }  error_page 500 502 503 504 /50x.html;    location = /50x.html {  }}

  重啟nginx:

service nginx restart

在/usr/share/nginx/html/這個目錄下建立一個index.php

cd /usr/share/nginx/html  #進入html目錄vim index.php        #建立index.php,加上phpinfo();

瀏覽器訪問:centos的ip地址/index.php。完成!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.