centos7安裝lnmp
阿新 • • 發佈:2017-12-23
epo libmcrypt #### eve table toc side make out
一、配置CentOS 第三方yum源(CentOS默認的標準源裏沒有nginx軟件包)
[root@localhost ~]# yum install wget #安裝下載工具wget [root@localhost ~]#wget http://www.atomicorp.com/installers/atomic #下載atomic yum源 [root@localhost ~]#sh ./atomic #安裝 [root@localhost ~]# yum check-update #更新yum軟件包
二、安裝開發包和庫文件
[root@localhost ~]# yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel
三、卸載已安裝的apache、mysql、php
[root@localhost ~]# yum remove httpd
[root@localhost ~]# yum remove mysql
[root@localhost ~]# yum remove php
四、安裝nginx
[root@localhost ~]# yum install nginx -y
[root@localhost ~]# systemctl start nginx.service
[root@localhost ~]# systemctl status nginx.service[root@localhost ~]# systemctl enable nginx.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@localhost ~]#
五、安裝mariadb
[root@localhost ~]# yum install mariadb-devel mariadb mariadb-server
[root@localhost ~]# systemctl start mariadb.service[root@localhost ~]# systemctl status mariadb.service
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2017-12-23 10:37:58 HKT; 4s ago
Process: 18474 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 18395 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 18473 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─18473 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─18635 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/...
Dec 23 10:37:56 localhost.localdomain mariadb-prepare-db-dir[18395]: MySQL manual for more instructions.
Dec 23 10:37:56 localhost.localdomain mariadb-prepare-db-dir[18395]: Please report any problems at http://mariadb.org/jira
Dec 23 10:37:56 localhost.localdomain mariadb-prepare-db-dir[18395]: The latest information about MariaDB is available at http://mar...org/.
Dec 23 10:37:56 localhost.localdomain mariadb-prepare-db-dir[18395]: You can find additional information about the MySQL part at:
Dec 23 10:37:56 localhost.localdomain mariadb-prepare-db-dir[18395]: http://dev.mysql.com
Dec 23 10:37:56 localhost.localdomain mariadb-prepare-db-dir[18395]: Consider joining MariaDB‘s strong and vibrant community:
Dec 23 10:37:56 localhost.localdomain mariadb-prepare-db-dir[18395]: https://mariadb.org/get-involved/
Dec 23 10:37:56 localhost.localdomain mysqld_safe[18473]: 171223 10:37:56 mysqld_safe Logging to ‘/var/log/mariadb/mariadb.log‘.
Dec 23 10:37:56 localhost.localdomain mysqld_safe[18473]: 171223 10:37:56 mysqld_safe Starting mysqld daemon with databases from /v.../mysql
Dec 23 10:37:58 localhost.localdomain systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service
#為root賬戶設置密碼
[root@localhost ~]#mysql_secure_installation #初始化MySQL
Enter current password for root (enter for none): <---輸入現在的root密碼,因為我們還沒設置,直接回車
Set root password? [Y/n] Y <---是否設定root密碼,當然設置了,輸入Y回車
New password: <---輸入root密碼,並回車,輸入的過程中不會有任何顯示
Re-enter new password: <---再次輸入root密碼,並回車,輸入的過程中不會有任何顯示
Remove anonymous users? [Y/n] Y <---是否刪除匿名用戶,刪除,輸入Y回車
Disallow root login remotely? [Y/n] Y <---是否刪禁止root用戶遠程登錄,當然禁止,輸入Y回車
Remove test database and access to it? [Y/n] <---是否刪除測試數據庫test,看個人喜好
Reload privilege tables now? [Y/n] Y <---刷新權限,輸入Y回車
最後出現:Thanks for using MySQL!
MySql密碼設置完成,重新啟動 MySQL:
六、安裝php
[root@localhost ~]# yum -y install php php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap
安裝php和所需組件使PHP支持MySQL、FastCGI模式
[root@localhost ~]# yum install php-tidy php-common php-devel php-fpm php-mysql -y
[root@localhost ~]# systemctl start php-fpm.service
[root@localhost ~]# systemctl status php-fpm.service
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2017-12-23 10:53:59 HKT; 4s ago
Main PID: 18953 (php-fpm)
Status: "Ready to handle connections"
CGroup: /system.slice/php-fpm.service
├─18953 php-fpm: master process (/etc/php-fpm.conf)
├─18955 php-fpm: pool www
├─18956 php-fpm: pool www
├─18957 php-fpm: pool www
├─18958 php-fpm: pool www
└─18959 php-fpm: pool www
Dec 23 10:53:59 localhost.localdomain systemd[1]: Starting The PHP FastCGI Process Manager...
Dec 23 10:53:59 localhost.localdomain systemd[1]: Started The PHP FastCGI Process Manager.
[root@localhost ~]#
[root@localhost ~]# systemctl enable php-fpm.service
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@localhost ~]#
七、配置nginx支持php
[root@localhost ~]# cp /etc/nginx/nginx.conf{,.bak} #將配置文件改為備份文件
#修改nginx配置文件,添加fastcgi支持
[root@localhost ~]# vim /etc/nginx/nginx.conf
vim /etc/nginx/nginx.conf #編輯
user nginx nginx; #修改nginx運行賬號為:nginx組的nginx用戶
:wq! #保存退出
[root@localhost nginx]# vim /etc/nginx/conf.d/default.conf
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm; #增加index.php
}
location ~ \.php$ {
root /usr/share/nginx/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;
}
八、配置php
[root@localhost nginx]# cp /etc/php.ini{,.bak}
[root@localhost nginx]#vim /etc/php.ini
expose_php = Off #禁止顯示php版本的信息
九、重啟nginx php-fpm
[root@localhost ~]# systemctl restart nginx.service
[root@localhost ~]# systemctl restart php-fpm.service
十、測試
[root@localhost ~]# cd /usr/share/nginx/html/ [root@localhost html]# vim index.php <?php phpinfo(); ?> [root@localhost html]# chown nginx.nginx /usr/share/nginx/html/ -R #設置目錄所有者
#配置防火墻,開啟80端口、3306端口
[root@localhost html]# firewall-cmd --zone=public --add-port=80/tcp --permanent success [root@localhost html]# firewall-cmd --zone=public --add-port=3306/tcp --permanent success [root@localhost html]# systemctl restart firewalld.service [root@localhost html]# systemctl enable firewalld.service
在客戶端瀏覽器輸入服務器IP地址,可以看到相關的配置信息!
#############################################################################
備註
nginx默認站點目錄是:/usr/share/nginx/html/
權限設置:chown nginx.nginx/usr/share/nginx/html/ -R
MySQL數據庫目錄是:/var/lib/mysql
權限設置:chown mysql.mysql -R /var/lib/mysql
參考:
https://www.cnblogs.com/xiaoit/p/3991037.html
http://www.kuitao8.com/20150305/3571.shtml
centos7安裝lnmp