阿里云用的比较多,php自从发布了7.0版本之后性能提升不好,因此在新产品上使用php7也是一种不错得选择,但是相对来说,快速部署运营环境也许有些人会觉得有难度,而网络上有很多教程,不过仔细看来,基本都是搬来搬去,没有经过自己的实践的。下面是我经过测试的一些内容,欢迎网友拍砖。
首先需要更新一下CentOS7.0系统:
[root@localhost ~]yum -y update
接下来需要添加 Nginx 官方的yum源:
[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo
#nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1
好,更新好nginx源之后我们再更新一下php7的源:
CentOS/RHEL 7.x:
[root@localhost ~]rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm [root@localhost ~]rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
CentOS/RHEL 6.x:
[root@localhost ~]rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm [root@localhost ~]rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
好,添加完成后我们需要安装nginx了:
#安装nginx [root@localhost ~]yum -y install nginx #查看 nginx 版本号 [root@localhost ~]nginx -v
接下来可以安装PHP了,php是使用fast-cgi模式运行的,因此我们安装的是PHP-FPM
[root@localhost ~]yum install php70w-fpm php70w-opcache
下面是其他一些可安装参数
Package | Provides |
---|---|
php70w | mod_php, php70w-zts |
php70w-bcmath | |
php70w-cli | php-cgi, php-pcntl, php-readline |
php70w-common | php-api, php-bz2, php-calendar, php-ctype, php-curl, php-date, php-exif, php-fileinfo, php-filter, php-ftp, php-gettext, php-gmp, php-hash, php-iconv, php-json, php-libxml, php-openssl, php-pcre, php-pecl-Fileinfo, php-pecl-phar, php-pecl-zip, php-reflection, php-session, php-shmop, php-simplexml, php-sockets, php-spl, php-tokenizer, php-zend-abi, php-zip, php-zlib |
php70w-dba | |
php70w-devel | |
php70w-embedded | php-embedded-devel |
php70w-enchant | |
php70w-fpm | |
php70w-gd | |
php70w-imap | |
php70w-interbase | php_database, php-firebird |
php70w-intl | |
php70w-ldap | |
php70w-mbstring | |
php70w-mcrypt | |
php70w-mysql | php-mysqli, php_database |
php70w-mysqlnd | php-mysqli, php_database |
php70w-odbc | php-pdo_odbc, php_database |
php70w-opcache | php70w-pecl-zendopcache |
php70w-pdo | |
php70w-pdo_dblib | php70w-mssql |
php70w-pear | |
php70w-pecl-apcu | |
php70w-pecl-imagick | |
php70w-pecl-xdebug | |
php70w-pgsql | php-pdo_pgsql, php_database |
php70w-phpdbg | |
php70w-process | php-posix, php-sysvmsg, php-sysvsem, php-sysvshm |
php70w-pspell | |
php70w-recode | |
php70w-snmp | |
php70w-soap | |
php70w-tidy | |
php70w-xml | php-dom, php-domxml, php-wddx, php-xsl |
php70w-xmlrpc |
如果您要使用mysql,记得要安装 php70w-mysql哦,centos现在已经默认吧mysql替换成mariadb
[root@localhost ~]yum -y install mariadb-server [root@localhost ~]vi /etc/my.cnf # 在 [mysqld] 区域添加utf8编码 [mysqld] character-set-server=utf8 [root@localhost ~]systemctl start mariadb [root@localhost ~]systemctl enabled mariadb
安装设定mariadb参数
[root@localhost ~]mysql_secure_installation /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. # set root password Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. # remove anonymous users Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. # disallow root login remotely Disallow root login remotely? [Y/n] y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. # remove test database Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. # reload privilege tables Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB! [root@www ~]# mysql -u root -p # connect to MariaDB with root Enter password:# password you set Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 5.5.37-MariaDB MariaDB Server Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # show user list MariaDB [(none)]> select user,host,password from mysql.user; +------+-----------+-------------------------------------------+ | user | host | password | +------+-----------+-------------------------------------------+ | root | localhost | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | | root | 127.0.0.1 | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | | root | ::1 | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | +------+-----------+-------------------------------------------+ 3 rows in set (0.00 sec) # show database list MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec) MariaDB [(none)]> exit Bye
根据提示设定就可以了。
最后一步,设定 Nginx虚拟主机。
[root@localhost ~]cd /etc/nginx/ [root@localhost ~]vim nginx.conf #这里我们要修改一下nginx启动的用户,当然你也可以不修改的,第一行 user apache
创建虚拟主机
[root@localhost ~]cd conf.d [root@localhost ~]vi domain.conf #插入以下内容 server { listen 80; server_name domain.com www.domain.com; charset utf-8; access_log /home/user/logs/domain.com/access.log main; error_log /home/user/logs/domain.com/error.log warn; location / { root /home/user/html/domain.com; index index.html index.htm index.php; } #error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/user/html/domain.com$fastcgi_script_name; include fastcgi_params; } }
大功告成!