安装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 httpdStep 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 nginxStart Nginx:
service nginx start// 或者systemctl start nginx.serviceWhat 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// orsystemctl 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.servicesystemctl 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_64Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Server version 5.5.50-MariaDBProtocol version 10Connection Localhost via UNIX socketUNIX socket /var/lib/mysql/mysql.sockUptime: 4 min 4 secThreads: 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-releaseyum install http://rpms.remirepo.net/enterprise/remi-release-7.rpmyum install yum-utilsStep2 Turn on Remi repo i.e.remi-php72: Enable remi repo,run
yum-config-manager --enable remi-php72Step3 Refresh repository
yum update // 此命令可能更新时间长,可逃过此执行 search for php 7.2 packages and modules with more command / gerp command / egerp command:
yum search php72 | moreyum search php72 | egerp 'fpm|gd|mysql|memcache' Sample outputs
php72-php-fpm.x86_64 : PHP FastCGI Process Managerphp72-php-gd.x86_64 : A module for PHP applications for using the gd graphicsphp72-php-mysqlnd.x86_64 : A module for PHP applications that use MySQLphp72-php-pecl-mysql.x86_64 : MySQL database access functionsphp72-php-pecl-mysql-xdevapi.x86_64 : MySQL database access functionsStep4 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 -vPHP 7.2.1 (cli) (built: Jan 3 2018 07:51:38) ( NTS )Copyright (c) 1997-2017 The PHP GroupZend 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 --moduelsStep5 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.servicesystemctl stop php72-php-fpm.servicesystemctl restart php72-php-fpm.servicesystemctl status php72-php-fpm.serviceConfigure 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 = nginxgroup = nginx Save and close the file. Restart php-fpm service:
systemctl restart php72-fpm.serviceUpdate 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: