常用命令
#檢查更新 yum check-update #執行更新 yum update #安裝軟件,如nano yum install nano #查看CentOS版本號 cat /etc/redhat-release #查看CentOS位數 getconf LONG_BIT #安裝編譯組件 yum install gcc gcc-c++ make openssl-devel 或者 sudo yum groupinstall 'Development Tools'
首先還是用LNMP練手
參考http://www.krizna.com/centos/install-lemp-on-centos-6/
nginx
去nginx官網下載源碼自己編譯安裝也是極好的,可以參考http://www.runoob.com/linux/nginx-install-setup.html
#用rpm添加nginx官方repository rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm #檢查更新 yum check-update #安裝nginx yum install nginx #啓動nginx service nginx start #添加到開機自動啓動 chkconfig nginx on
nginx默認目錄:
Default document root directory: /usr/share/nginx/html
Default configuration file: /etc/nginx/nginx.conf
Default Virtual host config directory: /etc/nginx/conf.d/
Default Virtual host config file: /etc/nginx/conf.d/default.conf
mysql
yum install mysql mysql-server service mysqld start chkconfig mysqld on #初始化mysql /usr/bin/mysql_secure_installation
額,默認好像是5.1的,如果想安裝新版本可以從mysql官方源安裝。
rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm #默認5.7,如果要5.6,執行下面兩條命令 yum-config-manager --disable mysql57-community yum-config-manager --enable mysql56-community #查看現在庫里的mysql版本 yum repolist enabled | grep mysql #安裝mysql yum install mysql-community-server service mysqld start mysql_secure_installation chkconfig mysqld on
新建用戶及數據庫可參考mysql tricks。
安裝默認php5.3
#這裏默認是5.3.3,更高版本請跳過這一節往下看 yum install php-fpm php-mysql #把php-fpm配置文件中到用戶從apache改爲nginx nano /etc/php-fpm.d/www.conf #修改如下兩行 user = nginx group = nginx service php-fpm start chkconfig php-fpm on
添加一個Virtual Host測試下,新建文件/etc/nginx/conf.d/phptest.conf,寫入下面內容,並且重啓nginx使之生效 sudo service nginx reload:
server { listen 8080; # listen port server_name localhost; # Server name location / { root /usr/share/nginx/html; # Document root index index.php index.html index.htm; } location ~ \.php$ { root /usr/share/nginx/html; # Document root fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
新建/usr/share/nginx/html/info.php測試下安裝是否成功:
<?php phpinfo(); ?>
升級或安裝php5.5
#rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm nano /etc/yum.repos.d/remi.repo #修改其中[remi]和[remi-php55]兩部分中的enabled值爲1。 service httpd stop service mysqld stop #如果已經安裝了php要升級則執行 yum update -y #如果是首次安裝則執行下面兩行 sudo yum install mysql-server sudo yum install php php-mysql service httpd start service mysqld start #更新下mysql mysql_upgrade -u root -p #php到配置文件夾/etc/php-fpm.d下會有php.conf.rpmnew,將其命名爲php.conf #如果使用nginx,要修改user和group值爲nginx
phpmyadmin
yum install phpmyadmin
新建一個文件/etc/nginx/conf.d/phpMyAdmin.conf,內容爲
server { listen 8080; location ~ \.php$ { root /usr/share/phpMyAdmin; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location / { root /usr/share/phpMyAdmin; index index.php; } }
還有兩點需要注意:
#修改php session到權限爲777 chmod 777 /var/lib/php/session #mbstring missing #去掉/etc/php.ini中mbstring前的; #403https://mos.meituan.com/library/17/how-to-install-phpmyadmin-on-centos6/
配置網卡相關:
#nano etc/sysconfig/network-scripts/ifcfg-eth0 ONBOOT=yes NM_CONTROLLED=no #如果要配置靜態ip BOOTPROTO=static #並增加 IPADDR=192.168.1.42 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=114.114.114.114 DNS2=4.4.4.4 #重啓網絡服務 /etc/init.d/network restart #修改hostname #nano /etc/sysconfig/network HOSTNAME=www.fortytwo.com #並在host中增加條目 #nano /etc/hosts 192.168.1.42 www.fortytwo.com
本文更新於 2016/12/27。