安装Nginx
Step 1: Turn off Apache
Shut dowm Apache. Remember: This will bring down any current website that are hosted on the server
service httpd stop
Now we need to remove Apache from the boot cycle, so that it doesn't try to start up during server boot:
systemctl disable httpd
If you want Apache to start on boot again, you can easily correct this previous command by running:
systemctl enable httpd
Step 2: Install Nignx
First,we need to add the CentOS EPEL package so that we can install NGINX:
yum install epel-release
此时,可以显示软件包是否存在
yum list nginx*
Now that our repository is installed on the server, we can now use yum to install Nginx, like so:
yum -y install nginx
Start Nginx:
service nginx start
// 或者
systemctl start nginx.service
What if you see a 'test faild' error message for ngix.conf?
You may be dealing with an IP address issue. By default, Nginx listens for both IPV4 and IPV6. If your server doesn't support IPV6, however, the test will fail.
You can fix this by opening up the configuration file:
vi /etc/nginx/nginx.config
Comment out the following line:
listen [::]:80 default_server;
So it looks like this:
# listen [::]:80 default_server;
Close and save the file, then try to start the server again:
service nginx start
// or
systemctl start nginx.service
If you don't see any errors, you're good to go.
Configure the server to start Nginx upon reboot:
systemctl enable nginx
You should now be able to see an nginx test page by going to your server's IP address in your browser.
如果你是在VMware虚机种的CentOS安装Nginx,本机无法访问,查看防火请firewall
systemctl status firewall.service
如果防火墙开启,需要我们配置开发端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
含义:
--zone 作用域
--add-port=80/tcp 添加端口,格式为: 端口/协议
--permanent 永久生效,否则重启后失效
重启防火墙
systemctl stop firewall.service
systemctl start firewall.service
ps: https://www.godaddy.com/garage/how-to-install-and-configure-nginx-on-centos-7/
ps: https://blog.csdn.net/harris135/article/details/74167910
安装MariaDB
Step1 Installing MariaDB
We'll use Yum install the MariaDB package, pressing y when promped to confirm that we wish to proceed:
yum install mariadb-server
Once the installation is complete, we'll start the daemon with the following command:
systemctl start mariadb.service
systemctl doesn't display the outcome of all service management commands, so to be sure we succeeded, we'll use the following command:
systemctl status mariadb.service
If mariaDB has successfully started, the output should contain "Active:active(running)" and the final line should look something like:
Dec 01 19:06:20 centos-512mb-sfo2-01 systemd[1]: Started MariaDB database server.
Next,let's take a moment to ensure that MariaDB start at boot,using the systemctl enable command,which will create the necessary symlinks:
systemctl enable mariadb
output
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
Step3 Securing the MariaDB Server
MariaDB includes a security script to change some of the less secure default options for things like remote root logins and sample users.Use this command to run the security script:
mysql_secure_installation
The script provides a detailed explanation for every step. The first prompts asks for the root password, which hasn't been set so we'll press ENTER as it recommends. Next, we'll be prompted to set that root password, whick we'll do.
Step4 Testing the Installation
mysqladmin -u root -p version
You should see output similar to this:
mysqladmin Ver 9.0 Distrib 5.5.50-MariaDB, for Linux on x86_64
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Server version 5.5.50-MariaDB
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 4 min 4 sec
Threads: 1 Questions: 42 Slow queries: 0 Opens: 1 Flush tables: 2 Open tables: 27 Queries per second avg: 0.172
ps:https://www.digitalocean.com/community/tutorials/how-to-install-mariadb-on-centos-7
安装PHP7.2
Step1 Turn on EPEL repo, enter:
yum install epel-release
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils
Step2 Turn on Remi repo i.e.remi-php72:
Enable remi repo,run
yum-config-manager --enable remi-php72
Step3 Refresh repository
yum update // 此命令可能更新时间长,可逃过此执行
search for php 7.2 packages and modules with more command / gerp command / egerp command:
yum search php72 | more
yum search php72 | egerp 'fpm|gd|mysql|memcache'
Sample outputs
php72-php-fpm.x86_64 : PHP FastCGI Process Manager
php72-php-gd.x86_64 : A module for PHP applications for using the gd graphics
php72-php-mysqlnd.x86_64 : A module for PHP applications that use MySQL
php72-php-pecl-mysql.x86_64 : MySQL database access functions
php72-php-pecl-mysql-xdevapi.x86_64 : MySQL database access functions
Step4 Install php 7.2
yum install php72
You must install "PHP FastCGI Process Manager" called php72-php-fpm along with commonly used modules:
yum install php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache
Check PHP version:
php72 -v
PHP 7.2.1 (cli) (built: Jan 3 2018 07:51:38) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.2.1, Copyright (c) 1999-2017, by Zend Technologies
List install moduels:
php72 --moduels
Step5 Turn on PHP fpm for nginx
systemctl enable php72-php-fpm.service
Sample ouputs:
Created symlink from /etc/systemd/system/multi-user.target.wants/php72-php-fpm.service to /usr/lib/systemd/system/php72-php-fpm.service.
Commands to control PHP fpm:
systemctl start php72-php-fpm.service
systemctl stop php72-php-fpm.service
systemctl restart php72-php-fpm.service
systemctl status php72-php-fpm.service
Configure Nginx for using with php 7.2
Find out nginx service user and group names using egrep command:
egrep '^(user|group)' /etc/nginx/nginx.conf
Edit vi /etc/opt/remi/php72/php-fpm.d/www.conf:
vi /etc/opt/remi/php72/php-fpm.d/www.conf
Set user and group to nginx:
user = nginx
group = nginx
Save and close the file. Restart php-fpm service:
systemctl restart php72-fpm.service
Update you nginx config
vi /etc/nginx/conf.d/default.conf
Edit/Add as follows in server section:
## enable php support ##
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Save and close file.Restart the nginx server:
systemctl restart nginx
Create a test script called foo.php an /usr/share/nginx/html/
vi /usr/share/nginx/html/foo.php
Append the following code:
<?php
phpinfo();
save and close the file.Fire a brower and try url:
http://your-domain-name/foo.php
ps:https://www.cyberciti.biz/faq/how-to-install-php-7-2-on-centos-7-rhel-7/