CentOS 6.3安裝配置nginx+php+mysql
準(zhǔn)備篇
1.配置防火墻,開(kāi)啟80端口、3306端口
1 vim /etc/sysconfig/iptables
2 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #允許80端口通過(guò)防火墻
3 -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #允許3306端口通過(guò)防火墻
service iptables restart #重啟防火墻,使配置生效
2.關(guān)閉SELINUX(這個(gè)和服務(wù)器安全相關(guān),先關(guān)閉。相關(guān)介紹:https://wiki.centos.org/zh/HowTos/SELinux)
vim /etc/selinux/config #SELINUX=enforcing #注釋掉 #SELINUXTYPE=targeted #注釋掉 SELINUX=disabled #增加 :wq #保存退出 shutdown -r now #重啟系統(tǒng)
3.安裝第三方源
1)安裝EPEL倉(cāng)庫(kù)
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倉(cāng)庫(kù)
CentOS 6
rpm -Uvh https://centos6.iuscommunity.org/ius-release.rpm
CentOS 7
rpm -Uvh https://centos7.iuscommunity.org/ius-release.rpm
錯(cuò)誤處理:
1.安裝IUS倉(cāng)庫(kù)出錯(cuò):curl: (35) SSL connect error。這個(gè)問(wèn)題在RHEL 6.1 -> RHEL 6.4應(yīng)該都會(huì)出現(xiàn),原因是curl使用了REST API。解決:
yum update nss
2.結(jié)果問(wèn)題1沒(méi)解決,出另一個(gè)問(wèn)題:Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again。解決:
vim /etc/yum.repos.d/CentOS-Base.repo
把有mirrorlist的都注釋掉,有baseurl的都去掉注釋,然后再進(jìn)行步驟1,再安裝IUS倉(cāng)庫(kù)。修改如下:
[epel] name=Extra Packages for Enterprise Linux 6 - $basearch baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch failovermethod=priority enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 [epel-debuginfo] name=Extra Packages for Enterprise Linux 6 - $basearch - Debug baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 gpgcheck=1 [epel-source] name=Extra Packages for Enterprise Linux 6 - $basearch - Source baseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 gpgcheck=1
查看倉(cāng)庫(kù)列表,看看是否安裝成功了:
yum repolist
ius | 2.3 kB 00:00 ius/primary_db | 183 kB 00:00 repo id repo name status base CentOS-6 - Base 5,062 epel Extra Packages for Enterprise Linux 6 - i386 9,992 extras CentOS-6 - Extras 39 ius IUS Community Packages for Enterprise Linux 6 - i386 329 updates CentOS-6 - Updates 382 repolist: 15,804
安裝倉(cāng)庫(kù)成功。接下來(lái)安裝nginx,mysql,php。
安裝篇
查看即將要安裝的軟件的版本:
yum list nginx mysql php
結(jié)果:
[root@localhost ~]# yum list nginx mysql php Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile * base: mirrors.163.com * extras: mirrors.163.com * ius: hkg.mirror.rackspace.com * updates: mirrors.163.com Available 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的版本都有些舊,他們都來(lái)源于mirrors.163.com這個(gè)源。而epel和ius源的軟件版本一般比較新。
使用以下命令列出所有mysql和php的版本:
yum list mysql* php*
這會(huì)列出一大堆像這樣的結(jié)果,接下來(lái)只要選擇需要安裝的軟件版本就好:
軟件名字 軟件版本 #軟件所在倉(cāng)庫(kù)
php56u.i686 5.6.26-1.ius.centos6 ius mysql55.i686 5.5.52-1.ius.centos6 ius 安裝nginx yum remove httpd* php* #刪除系統(tǒng)自帶的軟件包 yum install nginx #安裝nginx 根據(jù)提示輸入y進(jìn)行安裝 chkconfig nginx on #設(shè)置nginx開(kāi)機(jī)啟動(dòng) service nginx start #啟動(dòng)nginx 安裝MySQL yum remove mysql* #刪除系統(tǒng)已經(jīng)安裝的mysql yum list mysql* #列出mysql所有版本,找到要安裝的版本的名字 yum install mysql57u* #我安裝的是mysql5.7.15。輸入Y即可自動(dòng)安裝,直到安裝完成 service mysqld start #啟動(dòng)MySQL chkconfig mysqld on #設(shè)為開(kāi)機(jī)啟動(dòng)
安裝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及擴(kuò)展 chkconfig php-fpm on #設(shè)置php-fpm開(kāi)機(jī)啟動(dòng) service php-fpm start #啟動(dòng)php-fpm
配置篇
nginx的配置文件是/etc/nginx下的nginx.conf。在nginx.conf文件的最后一行可以看到: include /etc/nginx/conf.d/*.conf; 它把 /etc/nginx/conf.d目錄下后綴為.conf的文件都包含進(jìn)來(lái)了,所以只要在/etc/nginx/conf.d/這個(gè)目錄下配置一個(gè).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/這個(gè)目錄下新建一個(gè)index.php
cd /usr/share/nginx/html #進(jìn)入html目錄 vim index.php #新建index.php,加上phpinfo();
瀏覽器訪問(wèn):centos的ip地址/index.php。完成!
- CentOS 6.4安裝配置LNMP服務(wù)器(Nginx+PHP+MySQL)
- CentOS 6.3安裝配置Nginx方法
- CentOS 7.2安裝Nginx 1.10.2的詳細(xì)教程
- CentOS下編譯、安裝與配置nginx
- 在阿里云Centos下如何安裝Nginx
- CentOS 4.0安裝配置Nginx的方法
- CentOS 6.6服務(wù)器編譯安裝lnmp(Nginx1.6.2+MySQL5.6.21+PHP5.6.3)
- centos7系統(tǒng)下nginx安裝并配置開(kāi)機(jī)自啟動(dòng)操作
- CentOS 6.5編譯安裝Nginx 1.10.2+MySQL 5.5.52+PHP5.5.38
- 詳解Linux(Centos)之安裝Nginx及注意事項(xiàng)
相關(guān)文章
You don’t have permission to access /index.php on.
運(yùn)行php時(shí)提示You don't have permission to access /index.php on.錯(cuò)誤的解決方法,需要的朋友可以參考下2013-02-02
Linux上安裝搭建Nginx服務(wù)器的詳細(xì)步驟
本篇文章主要介紹了Linux上搭建Nginx服務(wù)器的詳細(xì)步驟,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-02-02
阿里云LNMP 云服務(wù)器重啟后網(wǎng)站打不開(kāi)解決方法
購(gòu)入了阿里云云服務(wù)器之后,感覺(jué)十分滿意,特別是阿里云的“快照”功能,對(duì)于折騰帝來(lái)說(shuō)簡(jiǎn)直就是神器。云服務(wù)器隨便弄,弄壞了大不了一個(gè)“回滾快照”,秒秒鐘的事而已2013-06-06
Ubuntu20的tzselect設(shè)置時(shí)間失效的問(wèn)題,樹(shù)莓派服務(wù)器(推薦)
這篇文章主要介紹了Ubuntu20的tzselect設(shè)置時(shí)間失效的問(wèn)題,樹(shù)莓派服務(wù)器,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05

