centos 版本6.6
**1. 關閉防火牆**
service iptables stop
**2. 安裝nginx**
方法1:rpm -ivh http://nginx.org/packages/centos/6/x86_64/RPMS/nginx-1.8.0-1.el6.ngx.x86_64.rpm
方法2:yum install nginx #默認不行
推薦:
#cd /etc/yum.repos.d/
#vim nginx.repophp
# nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
這樣就可使用
#yum install nginx 安裝更新了
chkconfig nginx on #開機啓動
訪問測試
你能夠用下列方法檢查配置文件是否有語法錯誤
/etc/init.d/nginx configtest
**3. 安裝php**
yum install php php-fpm
php -m #查看已經安裝的擴展
yum install php-mysql php-mbstring php-gd php-xml php-mcrypt #根據須要按照擴展庫
chkconfig php-fpm on
安裝mcrypt錯誤:No package php-mcrypt available.
方法1:
yum install epel-release //擴展包更新包
yum update //更新yum源,這句能夠不用
yum install php-mcrypt
方法2:
動態加載編譯
下載對應版本的php源碼包http://cn.php.net/releases/,wget可能須要安裝,yum install wget ,解壓進入
cd /ext/mcrypt
phpize phpize是用來擴展php擴展模塊的,經過phpize能夠創建php的外掛模塊
whereis php-config
./configure --with-php-config=/usr/bin/php-config
網上都是上面這種寫法
直接 ./configure 這樣也是能夠的,若是提示錯誤須要提供php-config的路徑,那確定就得上面那樣寫了
若是遇到如下錯誤,請先安裝gcc,yum install gcc
configure: error: no acceptable C compiler found in $PATH
繼續,
configure: error: mcrypt.h not found. Please reinstall libmcrypt
須要先安裝libmcrypt
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
解壓進去
./configure
若是遇到下面錯誤
centos configure: error: C++ compiler cannot create executables
安裝gcc-c++
yum install gcc-c++
繼續
./configure
make && make install
安裝成功後,繼續安裝mcrypt,回到其目錄下
./configure --with-php-config=/usr/bin/php-config
最後顯示
Installing shared extensions: /usr/lib64/php/modules/
安裝成功,而後須要給php添加該擴展
cd /etc/php.d
建立一個mrcypt.ini文件就行,裏面寫extension=mcrypt.so
echo 'extension=mcrypt.so' > mcrypt.ini
重啓php-fpm,查看phpinfo
**4. 配置nginx支持php**
vi /etc/nginx/conf.d/default.conf
location ~ \.php$ {
root html;#注意這裏須要改爲根目錄 /var/www 否則找不到php文件,若是在外面已寫,這裏不用寫
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}#取消FastCGI server部分location的註釋,並要注意fastcgi_param行的參數,改成$document_root$fastcgi_script_name,或者使用絕對路徑
service nginx restart #重啓nginx
創建php文件,測試
**5. 安裝mysql**
yum install mysql mysql-server
chkconfig mysqld on
mysql_secure_installation #安全配置嚮導
運行mysql_secure_installation會執行幾個設置:
a)爲root用戶設置密碼
b)刪除匿名帳號
c)取消root用戶遠程登陸
d)刪除test庫和對test庫的訪問權限
e)刷新受權表使修改生效
經過這幾項的設置可以提升mysql庫的安全。建議生產環境中mysql安裝這完成後必定要運行一次mysql_secure_installation。html
other method
#cd /etc/yum.repos.d/
#vim mysql-community.repomysql
[mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/ enabled=1 gpgcheck=0
#yum install mysql-community-server
#service mysqld start //啓動的時候它會提示,有兩種方法去休息root密碼,推薦第二種
#/usr/bin/mysql_secure_installation
一路y
(完)linux
mysql 5.7 版本不太同樣nginx
After you installed MySQL-community-server 5.7 from fresh on linux, you will need to find the temporary password from /var/log/mysqld.log to login as root.c++
grep 'temporary password' /var/log/mysqld.log
mysql_secure_installation
to change new password