centos安裝lnmp
配置防火牆,開啓80,3306端口,加到22端口下邊纔有用
#vim /etc/sysconfig/iptables
*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
依賴庫和開發工具
#yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
yum安裝ngnix
新安裝的Centos裏邊沒有nginx包的話,要先處理下源:
#rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
# yum check-update #更新yum軟件包
#yum info nginx(查看centos裏的nginx的信息)
#yum -y install nginx (安裝nginx)
#chckconfig nginx on (設爲開機自啓動動)
#service nginx restart(重啓,或者/etc/init.d/nginx restart )
可以: rm -rf /usr/share/nginx/html/* #刪除ngin默認測試頁,後續用index.php來作爲默認的頁面
安裝Mysql
#yum install mysql mysql-server mysql-devel
#/etc/init.d/mysqld start 啓動mysql
# chkconfig mysqld on (設爲開機自啓動)
#mysql -u root (設置密碼,初始密碼爲空)
爲roor賬號修改密碼
方法1:
mysql>USE mysql;
mysql>UPDATE user SET Password=PASSWORD('要設置的密碼') WHERE user='root';
mysql> flush privileges;
Mysql> \q
方法2:
#mysql_secure_installation
輸入原密碼,輸入新密碼,重複新密碼,一路輸入Y,回車,最後出現Thanks for using MySQL!
則密碼修改成功
允許遠程登錄,完成後就能用mysql-front(navcat mysql)遠程管理mysql了
mysql -u root -p
Enter Password: <your new password>
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1224' WITH GRANT OPTION;
配置文件: /usr/share/mysql/my-medium.cnf
可以 cp /usr/share/mysql/my-medium.cnf /etc/my.cnf #拷貝配置文件(注意:如果/etc目錄下面默認有一個my.cnf,直接覆蓋即可)
安裝Php
#yum install php
#yum install php-fpm
安裝PHP組件,使PHP支持 MySQL、PHP支持FastCGI模式
# yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel php-fpm
#/etc/rc.d/init.d/php-fpm start #啓動php-fpm
#chkconfig php-fpm on #設置開機啓動
配置php-fpm
cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak #備份原有配置文件
vim/etc/nginx/nginx.conf
user nginx nginx; #修改nginx運行賬號爲:nginx組的nginx用戶
cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.confbak #備份原有配置文件
vim /etc/php-fpm.d/www.conf
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
#/etc/rc.d/init.d/php-fpm restart (service php-fpm restart)
#chkconfig php-fpm on 設置開機自啓動
nginx 支持php (藍色爲修改的地方)
#cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak #備份原有配置文件
#vim /etc/nginx/conf.d/default.conf
location / {
root /usr/share/nginx/html;(歡迎頁面的文件處)
假如修改爲 root /www
index index.html index.htm index.php;
}
去掉下邊的註釋,並修改fastcgi_param SCRIPT_FILENAME
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html;$fastcgi_script_name;
include fastcgi_params; //fastcgi程序.
}
//注:默認的爲 /usr/share/nginx/html,改成對應目錄即可,以改爲/www爲例說明
location 定義文件類型, \.php$ 代表所有以 php 作爲文件後綴的文件類型.
root 定義 php 文件存放的路徑, 當前以 "/www 作爲默認存放位置.
fastcgi_index 定義 php 文件類型中的默認索引頁
fastcgi_param SCRIPT_FILENAME 定義了頁面請求參數, 如客戶端需要訪問 /t1.php 則會自動讀取 /www/t1.php文件, 如客戶端訪問 / 則自動讀取 /www/index.php 文件
include 定義fastcgi 配置信息將會被保存到 /usr/share/nginx/html 文件中
nginx最常用的方法是利用 tcp/ip 協議連接 phpfastcgi 接口, 因此要連接php必須先啓動fastcgi程序.
修改nginx配置參數後,使用nginx -t檢查配置.
提示successfull後就可以使用 nginx -s reload來重新加載配置
重啓niginx可能會提示:
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
意思是重複綁定了server name,但這個警告不會影響到服務器運行。而且,這個重複綁定的意思是現在運行的nginx服務和將要加載的新配置中的重複,所以,這個警告其實是不必的。
nginx可以在同一ip端口綁定多個域名。
我的解決辦法是殺掉nginx進程重新啓動,或者先去掉default_server設定,重新加載nginx配置後,再加上,再重新配置。
重啓nginx,php-fpm。
測試一下:
在/usr/share/nginx/html下新建index.php
<?php echo phpinfo();
?>
瀏覽器輸出 http://ip,即可看到phpinfo信息
題外話:
chown nginx.nginx /usr/share/nginx/html/ -R #設置目錄所有者
chmod 700 /usr/share/nginx/html/ -R #設置目錄權限
nginx默認站點目錄是:/usr/share/nginx/html/
權限設置:chown nginx.nginx /usr/share/nginx/html/ -R
MySQL數據庫目錄是:/var/lib/mysql
Mysql配置文件: /usr/share/mysql/my-medium.cnf
權限設置:chown mysql.mysql -R /var/lib/mysql
查看版本 nginx -v php -v
nginx本機hosts映射
和win下面一樣,文件路徑在/etc/hosts
Linux查找
查找文件 find -name haha.php
查找文件中的關鍵字:
grep [keyword] [路徑] -R
還可以指定在哪一行
grep [keyword] [路徑] -Rn
另外,如果查看ftp開啓了什麼權限的話,可以執行下面的命令:
getsebool -a | grep ftp