yum安装方便,快捷,能够快速解决包依赖的问题,但是没有源码安装的配置过程可以进行自定义参数设定,总而言之yum还是比较适合新手的。
本篇文章lamp使用:centos,httpd,mysql5.5,php5
一、Linux我们选择centos,目前centos6和centos7还是用的比较多的。
二、apache安装:
yum install -y httpd httpd-devel
三、mysql5.5安装:
默认使用安装的mysql不是5.5版本的,我们需要增加两个新的repo
- centos6:
rpm -Uvh http://mirror.steadfast.net/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm - centos7:
rpm -Uvh http://mirror.steadfast.net/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
查看一下是不是有mysql 5.5了
yum --enablerepo=remi,remi-test list mysql mysql-server
安装mysql5.5
yum --enablerepo=remi,remi-test install mysql mysql-server
启动mysql5.5
- centos6:
/etc/init.d/mysqld start - centos7:
systemctl start mysqld
设置开机启动
- centos6:
chkconfig --levels 345 mysqld on - centos7:
systemctl enable mysqld
修改一下mysql的root用户密码
mysqladmin -u root password [your_password_here]
为指定数据库,指定用户配置指定客户端(IP)远程访问
本示例的配置参数如下
DB_NAME = testdb
USER_NAME = testdb_user
REMOTE_IP = 10.0.15.1
PASSWORD = password001
PERMISSIONS = ALL
创建数据库 webdb
mysql> CREATE DATABASE testdb;
创建用户webdb_user
mysql> CREATE USER 'testdb_user'@'10.0.15.1' IDENTIFIED BY 'password001';
授权
mysql> GRANT ALL ON testdb.* TO testdb_user@'10.0.15.1';
重载权限表
mysql> FLUSH PRIVILEGES;
centos6配置防火墙开启3306端口:
vi /etc/sysconfig/iptables
在COMMIT之前加入以下内容:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
重启Iptables:
service iptables restart
centos7配置防火墙开启3306端口:
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload
在客户机上测试远程访问数据库:
mysql -h dbserver_name_or_ip_address -u webdb_user -p webdb
四、php5安装
默认安装的版本太低了,所以用以下办法来安装
1.检查当前安装的PHP包
yum list installed | grep php
如果有安装的PHP包,先删除他们
yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64
2.
- Centos 5.X
rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm - CentOs 6.x
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm - CentOs 7.X
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
如果想删除上面安装的包,重新安装
rpm -qa | grep webstatic
rpm -e 上面搜索到的包即可
3.运行yum install
yum install php55w.x86_64 php55w-cli.x86_64 php55w-common.x86_64 php55w-gd.x86_64 php55w-ldap.x86_64 php55w-mbstring.x86_64 php55w-mcrypt.x86_64 php55w-mysql.x86_64 php55w-pdo.x86_64
yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64
注:如果想升级到5.6把上面的55w换成56w就可以了。
yum install 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-mysql.x86_64 php70w-pdo.x86_64
4.安装PHP FPM
yum install php55w-fpm
yum install php56w-fpm
yum install php70w-fpm
注:如果想升级到5.6把上面的55w换成56w就可以了。
参考文章:
http://cuiyadll.iteye.com/blog/2186416
http://www.blogjava.net/nkjava/archive/2015/01/20/422289.html