安裝Centos 7
在VMWARE安裝Centos 7(步驟略)
備份原有的yum源文件,更新yum源為阿里云
[root@localhost yum.repos.d]# ls | xargs -t -i mv {} {}.bak[root@localhost yum.repos.d]# ls -alhtotal 48Kdrwxr-xr-x. 2 root root 252 Apr 2 08:12 .drwxr-xr-x. 139 root root 8.0K Apr 2 08:09 ..-rw-r--r--. 1 root root 1.7K Apr 7 2024 CentOS-Base.repo.bak-rw-r--r--. 1 root root 1.3K Apr 7 2024 CentOS-CR.repo.bak-rw-r--r--. 1 root root 649 Apr 7 2024 CentOS-Debuginfo.repo.bak-rw-r--r--. 1 root root 314 Apr 7 2024 CentOS-fasttrack.repo.bak-rw-r--r--. 1 root root 630 Apr 7 2024 CentOS-Media.repo.bak-rw-r--r--. 1 root root 1.3K Apr 7 2024 CentOS-Sources.repo.bak-rw-r--r--. 1 root root 7.4K Apr 7 2024 CentOS-Vault.repo.bak-rw-r--r--. 1 root root 616 Apr 7 2024 CentOS-x86_64-kernel.repo.bak
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost yum.repos.d]# yum clean cache[root@localhost yum.repos.d]# yum makecache
-
更新一下系統(tǒng),然后最好做一下快照
[root@localhost yum.repos.d]# yum update
安裝LNMP環(huán)境
-
關閉防火墻
a. 確認防火墻當前狀態(tài)
[root@localhost ~]# systemctl status firewalld.service● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2024-04-02 08:22:54 EDT; 1min 43s ago Docs: man:firewalld(1) Main PID: 837 (firewalld) Tasks: 2 CGroup: /system.slice/firewalld.service └─837 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopidApr 02 08:22:53 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...Apr 02 08:22:54 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.Apr 02 08:22:54 localhost.localdomain firewalld[837]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Ple...bling it now.Hint: Some lines were ellipsized, use -l to show in full.
b. 關閉防火墻
[root@localhost ~]# systemctl stop firewalld.service[root@localhost ~]# systemctl disable firewalld.serviceRemoved symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
-
關閉Selinux,修改為SELINUX=disabled
[root@localhost ~]# cat /etc/selinux/config# This file controls the state of SELinux on the system.# SELINUX= can take one of these three values:# enforcing - SELinux security policy is enforced.# permissive - SELinux prints warnings instead of enforcing.# disabled - No SELinux policy is loaded.SELINUX=disabled# SELINUXTYPE= can take one of three values:# targeted - Targeted processes are protected,# minimum - Modification of targeted policy. Only selected processes are protected.# mls - Multi Level Security protection.SELINUXTYPE=targeted
安裝nginx,由于nginx位于第三方的yum源里面,而不在centos官方y(tǒng)um源里面
[root@localhost ~]# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@localhost opt]# rpm -ivh epel-release-latest-7.noarch.rpmwarning: epel-release-latest-7.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID 352c64e5: NOKEYPreparing... ################################# [100%]Updating / installing... 1:epel-release-7-14 ################################# [100%]
[root@localhost opt]# yum install -y nginx
驗證一下nginx是否安裝成功:
[root@localhost opt]# nginx -vnginx version: nginx/1.20.1
說明安裝成功!
-
安裝mysql
[root@localhost opt]# sudo rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
[root@localhost opt]# sudo yum -y install mysql-community-server --nogpgcheck
運行以下命令驗證是否安裝成功:
[root@localhost opt]# mysql -Vmysql Ver 14.14 Distrib 5.7.41, for Linux (x86_64) using EditLine wrapper
運行以下命令啟動和開機啟動Myssql:
[root@localhost opt]# systemctl start mysqld[root@localhost opt]# systemctl enable mysqld
-
安裝PHP
a. 更新yum源
sudo yum install \https://1eqimg.oss-cn-shenzhen.aliyuncs.com/upload/20240709/ezraonflnzx.rpm \https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
b. 運行以下命令添加Webtatic源
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
c. 安裝PHP
sudo yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-pdo.x86_64 php70w-mysqlnd php70w-fpm php70w-opcache php70w-pecl-redis php70w-pecl-mongodb
d.驗證PHP是否安裝成功
[root@localhost opt]# php -vPHP 7.0.33 (cli) (built: Dec 6 2024 22:30:44) ( NTS )Copyright (c) 1997-2024 The PHP GroupZend Engine v3.0.0, Copyright (c) 1998-2024 Zend Technologies with Zend OPcache v7.0.33, Copyright (c) 1999-2024, by Zend Technologies
-
配置NGINX
-
添加或修改
location /
配置信息。愛掏網(wǎng) - it200.comlocation / { index index.php index.html index.htm; }
-
添加或修改
location ~ .php$
配置信息。愛掏網(wǎng) - it200.com#添加下列信息,配置Nginx通過fastcgi方式處理您的PHP請求。愛掏網(wǎng) - it200.com location ~ .php$ { root /usr/share/nginx/html; #將/usr/share/nginx/html替換為您的網(wǎng)站根目錄,本文使用/usr/share/nginx/html作為網(wǎng)站根目錄。愛掏網(wǎng) - it200.com fastcgi_pass 127.0.0.1:9000; #Nginx通過本機的9000端口將PHP請求轉發(fā)給PHP-FPM進行處理。愛掏網(wǎng) - it200.com fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; #Nginx調用fastcgi接口處理PHP請求。愛掏網(wǎng) - it200.com }
-
啟動Nginx
[root@localhost ~]# systemctl start nginx[root@localhost ~]# systemctl enable nginxCreated symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
-
配置mysql
a. 運行以下命令,查看/var/log/mysqld.log文件,獲取并記錄root用戶的初始密碼。愛掏網(wǎng) - it200.com
[root@localhost ~]# grep temporary password /var/log/mysqld.log2024-04-02T12:43:47.099622Z 1 [Note] A temporary password is generated for root@localhost: ecz+LMihI1g=
[root@localhost ~]# mysql_secure_installation
-
配置PHP
在網(wǎng)站根目錄創(chuàng)建phpinfo.php文件
[root@localhost ~]# echo > /usr/share/nginx/html/phpinfo.php
運行以下命令,啟動PHP-FPM。愛掏網(wǎng) - it200.com
[root@localhost ~]# systemctl start php-fpm
設置開機啟動php-fpm
[root@localhost ~]# systemctl enable php-fpm
訪問phpinfo.php頁面
至此已經(jīng)成功的將php,mysql以及nginx安裝配置完成。愛掏網(wǎng) - it200.com
安裝Wordpress
- 創(chuàng)建數(shù)據(jù)庫huawen_db
mysql> create database huawen_db;Query OK, 1 row affected (0.00 sec)
- 創(chuàng)建數(shù)據(jù)庫用戶和密碼
mysql> CREATE USER AAAAAAAAAAAAAA@localhost IDENTIFIED BY xxxxxxx;Query OK, 0 rows affected (0.00 sec)
設置wordpressuser訪問wordpress數(shù)據(jù)庫權限
mysql> GRANT ALL PRIVILEGES ON huawen_db.* TO AAAAAAAAAAAAAr@localhost IDENTIFIED BY xxxxxxx;Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> FLUSH PRIVILEGES;Query OK, 0 rows affected (0.00 sec)mysql> exit
- 下載最新版本的wordpress包
[root@localhost opt]# wget http://wordpress.org/latest.tar.gz
[root@localhost opt]# tar -zxvf latest.tar.gz
并拷貝到nginxu網(wǎng)站根目錄
[root@localhost opt]# rsync -avP ./wordpress/ /usr/share/nginx/html/
編輯wp-config.php文件,配置數(shù)據(jù)庫名、用戶名和密碼
此時訪問ip,即可完成wordpress的安裝
STRIVE FOR PROGRESS,NOT FOR PERFECTION