[腾讯云]简单在腾讯云 CenTOS7.0 安装Nginx,Mysql(MariaDB),Memcache,解析PHP!
1、安裝LNMP之前要安裝EPEL,以便安裝源以外的軟件,如Nginx,phpMyAdmin等。
yum install epel-release
2、安裝Nginx
a) yum install nginx
b) systemctl start nginx #啟動nginx systemctl stop nginx
c) systemctl enable nginx #設置開機啟動
/usr/share/nginx/html. 解析頁面目錄
/etc/nginx/nginx.conf nginx配置文件
###現在已經可以解析.html文件啦!還想解析PHP文件需要安裝PHP,然后修改nginx 配置文件
3、?進入nginx 配置目錄,復制nginx配置文件nginx.conf ,以留備份,防止改錯!
修改配置文件如下!
server {
?listen?????? 80;????? ?
??? server_name? server_domain_name_or_IP;
??? location / {
?????????? root?? /usr/share/nginx/html;
?????????? index? index.php index.html index.htm;????? ?
?? ? }???????? ?
??? error_page? 404????????????? /404.html;???????? ?
??? # redirect server error pages to the static page /50x.html????? ?
??? error_page?? 500 502 503 504? /50x.html;????? ?
??? location = /50x.html {????????? ?
?? ??? ? root?? /usr/share/nginx/html;????? ?
??? }???? ?
??? # 更改上方面location /? 直接把下方替換上方的就可以,或者直接加載server里也行!
??? location ~ \.php$ {????????? ?
?? ??? ? root?????????? /usr/share/nginx/html;????????? ?
?? ??? try_files $uri =404;????????? ?
?? ??? ? fastcgi_pass?? 127.0.0.1:9000;????????? ?
?? ??? fastcgi_index? index.php;????????? ?
?? ??? ? fastcgi_param? SCRIPT_FILENAME? $document_root$fastcgi_script_name;????????? ?
?? ??? ? include??????? fastcgi_params;????? ?
?? }
}
? 改完配置文件記得重啟nginx!
1、安裝PHP
yum install -y php php-devel php-fpm php-mysql php-common php-devel 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
老規矩:直接復制!
2、開啟php-fpm
a) systemctl start php-fpm #開啟php-fpm
b) systemctl enable php-fpm #開機自動啟動
?
這樣Nginx基本實現可以解析PHP!
?
?
下面安裝MYSQL
1、安裝MYSQL(MariaDB)
安裝LNMP方式,CentOS7下MYSQL已經被Mariadb替代,這個無所謂,完全兼容的!
(MariaDB 是一個采用Aria存儲引擎的MySQL分支版本,是由原來 MySQL 的作者Michael Widenius創辦的公司所開發的免費開源的數據庫服務器)
? ( LAMP架構盛極一時,這離不開MySQL的免費與易用,但是在Oracle收購了Sun之后,很多公司開始擔憂MySQL的開源前景,而最近Oracle進一步閉源的舉措更是讓人難以安 心,眾多互聯網公司紛紛開始尋求MySQL的替代方案。)
a) yum install mariadb-server mariadb
b) systemctl start mariadb #啟動mariadb
c) systemctl enable mariadb #設置開機啟動
2、設置MariaDB密碼
mysql_secure_installation
#會要求輸入原密碼,直接點擊回車就行,剩下的就是輸入新密碼以及確認密碼
#其他配置(了解一下就好)
Remove anonymous users? [Y/n] <– 是否刪除匿名用戶,回車
Disallow root login remotely? [Y/n] <–是否禁止root遠程登錄,回車,
Remove test database and access to it? [Y/n] <– 是否刪除test數據庫,回車
Reload privilege tables now? [Y/n] <– 是否重新加載權限表,回車
3、測試是否成功
mysql -u用戶名 -p密碼
進入就OK啦!
show databases;
?
?
linux 安裝memcache
?
1、查找Memcached
yum search memcached
2、安裝memcache和PHP相關擴展
yum -y install –enablerepo=rpmforge memcached php-pecl-memcache
3、驗證安裝?
memcached -h #應該會輸出一些幫助信息
4、設置開機啟動
chkconfig memcached on
5、啟動memcached
service memcached start
或者找到目錄的啟動/bin/systemctl start memcached.service
6、測試服務端是否安裝成功
php -m|grep memcache
#查看端口號
lsof -i tcp:11211 #如果提示lsof not found,使用yum install lsof即可
?
7、接下來加載php memcache擴展
找到php配置文件,一般使用yum默認安裝在etc/目錄下,如果沒找到可以建立一個文件輸出phpinfo搜索Configuration File可以查看到php.ini文件位置,
?
開啟memcache擴展
extension=/usr/lib64/php/modules/memcache.so,
重啟php服務
service php-fpm restart
8、檢測php擴展是否安裝ok
在輸出phpinfo頁面搜索memache,可查看到memcache擴展
9、新建mem.php,輸入如下代碼:
#去頁面加載文件夾建一個新文件
<?php
$mem = new Memcache;
$mem->connect("127.0.0.1", 11211);
$mem->set('key', 'This is a test, Hello World!--Pc.Lee', 0, 0);
$val = $mem->get('key');
echo $val;
?>
10、在地址欄運行文件
This is a test, Hello World!--Pc.Lee #頁面顯示這個輸出內容就OK啦!
?
轉載于:https://www.cnblogs.com/lipcblog/p/6476258.html
總結
以上是生活随笔為你收集整理的[腾讯云]简单在腾讯云 CenTOS7.0 安装Nginx,Mysql(MariaDB),Memcache,解析PHP!的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 导入jar包和创建jar文件
- 下一篇: PHP基本连接数据库