更新源:
rpm -Uvh https://dl.fedoraproject.org/...
rpm -Uvh https://mirror.webtatic.com/y... php
安裝服務:
yum -y install httpd html
CentOS7啓動服務:
systemctl start httpd.servicemysql
CentOS7設置開機啓動服務:
systemctl enable httpd.servicenginx
更新源:
rpm -Uvh http://dev.mysql.com/get/mysq...git
安裝MySQL5.6:
yum -y install mysql-community-serverweb
安裝成功後,將其加入開機啓動:
systemctl enable mysqldsql
啓動mysql服務進程:
systemctl start mysqld數據庫
配置MySQL:
mysql_secure_installation
具體設置項:新安裝MySQL以後設置
示例版本是MySQL5.6,操做系統CentOS6.5 - 7.3都可。npm
配置MySQL初始設置:
進行一些安全性配置
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQLvim
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, 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 MySQL
root user without the proper authorisation.
Set root password? [Y/n] Y <--是否設置Root密碼?
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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? [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? [Y/n] n <--是否容許Root遠程登陸?通常選擇Y,不過我爲了方便測試,先選N。
... skipping.
By default, MySQL 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 and access to it? [Y/n] y <--是否刪除測試數據庫?
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
... Failed! Not critical, keep moving...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y <--是否刷新權限?
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
配置遠程訪問
MySQL不容許遠程用戶訪問主機服務器 1130鏈接報錯:
ERROR 1130: Host ... is not allowed to connect to this MySQL server
說明所鏈接的用戶賬號沒有遠程鏈接的權限,只能在本機(localhost)登陸。 需更改 mysql 數據庫裏的user表裏的host項把localhost改稱%。
具體步驟:
登錄mysql :
[root@localhost ~]# mysql -uroot -p
mysql> use mysql
mysql> update user set host='%' where user = 'root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
有時候會報錯,可是沒關係,查看一下成功否。
mysql> select host from user where user = 'root'; |
---|
host |
% |
127.0.0.1 |
::1 |
izm5edi5djftntq1oes7sfz |
4 rows in set (0.00 sec)
host已經有了%這個值,因此沒問題了。
mysql> flush privileges;
mysql> set global max_allowed_packet = 210241024*10;
設置最大可存入數據庫字段的值長度。
Query OK, 0 rows affected (0.00 sec)
能夠遠程訪問了
安裝與設置
安裝最新版:
yum -y install mod_php71w php71w-bcmath php71w-cli php71w-common php71w-devel php71w-fpm php71w-gd php71w-mbstring php71w-mcrypt php71w-mysql php71w-snmp php71w-xml php71w-process php71w-ldap net-snmp net-snmp-devel net-snmp-utils rrdtool
查看版本:
php -v
基礎配置(保證一些基本使用):
vi /etc/php.ini
修改時區:把;date.timezone改成date.timezone =PRC; memory_limit = 2048M upload_max_filesize = 64M
測試
vim /var/www/html/index.php
<?php
phpinfo();
保存退出,瀏覽器訪問:
附加:安裝git、npm、composer(若是有須要)
yum install -y git
yum install -y npm
cd ~
curl -sS https://getcomposer.org/insta... | php --
mv composer.phar /usr/local/bin/composer
chmod -R 777 /usr/local/bin/composer
附加:配置PHP7-FPM與nginx(若是有須要)
vi /etc/php-fpm.d/www.conf
在第 8 行和第 10行,user 和 group 賦值爲 nginx: user = nginx group = nginx 在第 22 行,確保 php-fpm 運行在指定端口: listen = 127.0.0.1:9000 取消第 366-370 行的註釋,啓用 php-fpm 的系統環境變量: env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp 保存文件並退出。
在 /var/lib/ 目錄下建立一個新的文件夾 session,並將其擁有者變動爲 nginx 用戶:
mkdir -p /var/lib/php/sessionchown nginx:nginx -R /var/lib/php/session/啓動 php-fpm 和 Nginx,並將它們設置開機啓動systemctl start php-fpm.service systemctl start nginx.service systemctl enable php-fpmsystemctl enable nginx