VP Easy 搭建 LAMP 环境

发布于 / 每日 / VP Easy 搭建 LAMP 环境已关闭评论

有些时候机器并不适合用一键包,最好的办法还是分步骤安装环境比较好。
第一步、安装和配置Apache服务器
yum update
yum install httpd
安装当前版本的Apache配置环境,然后配置httpd.conf(位置在/etc/httpd/conf/httpd.conf)文件,一般如何类似Linode 1GB方案可以这样的设置,也可以默认。
KeepAlive Off
……

StartServers 2
MinSpareServers 6
MaxSpareServers 12
MaxClients 80
MaxRequestsPerChild 3000

配置的时候不是要把里面设置都删除,而是对应的参数修改。
第二步、设置、绑定站点目录文件
手工安装LAMP不同于用一键包直接用命令就可以添加域名建立站点,这些所有都要用手工操作,比如我们这里需要添加域名建立站点。
/etc/httpd/conf.d/vhost.conf
在上述的目录下建立vhost.conf文件,然后配置站点
NameVirtualHost *:80

ServerAdmin admin@imlx.cn
ServerName imlx.cn
ServerAlias www.imlx.cn
DocumentRoot /srv/www/imlx.cn/public_html/
ErrorLog /srv/www/imlx.cn/logs/error.log
CustomLog /srv/www/imlx.cn/logs/access.log combined


ServerAdmin admin@lxtmm.com
ServerName lxtmm.com
ServerAlias www.lxtmm.com
DocumentRoot /srv/www/lxtmm.com/public_html/
ErrorLog /srv/www/lxtmm.com/logs/error.log
CustomLog /srv/www/lxtmm.com/logs/access.log combined

我们在上面文件中可以看到是添加2个站点,如果是添加多个站点类似的复制修改对应的目录。同样的,我们需要对应的目录创建没有的目录路径。
mkdir -p /srv/www/imlx.cn/public_html
mkdir /srv/www/imlx.cn/logs
mkdir -p /srv/www/lxtmm.com/public_html
mkdir /srv/www/lxtmm.com/logs
对应的目录路径比如srv是我创建的,如果有需要其他路径我们根据自己的需要自己创建。
/etc/init.d/httpd start
/sbin/chkconfig –levels 235 httpd on
/etc/init.d/httpd reload
启动httpd以及设置开机启动。
第三步、安装MYSQL数据库
A – 安装并且启动
yum install mysql-server #安装MYSQL服务
/sbin/chkconfig –levels 235 mysqld on # 设置开机启动
/etc/init.d/mysqld start # 启动MYSQL
B – 设置数据库用户
mysql_secure_installation #安装设置ROOT权限,根据提示设置ROOT密码
[root@localhost Desktop]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
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.

You already have a root password set, so you can safely answer ‘n’.

Change the root password? [Y/n] n
… skipping.

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
… 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] n
… skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
… Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

可以移除默认的其他用户和其他默认数据。
mysql -u root -p # 登录ROOT数据库用户
create database imlx;
grant all on imlx.* to ‘imlxuser’ identified by ‘imlx.cn’;
创建imlx数据库用户,以及imlxuser数据库用户名,以及imlx.cn数据库密码,这里我们创建之后,后面搭建网站时候需要用到。创建完毕之后输入quit退出。

远程链接失败 可能需要开放3306端口:
CentOS 打开mysql 3306端口
在CentOS系统中防火墙默认是阻止3306端口的,我们要是想访问mysql数据库,我们需要这个端口,命令如下:
1 /sbin/iptables -I INPUT -p tcp –dport 3306 -j ACCEPT
我们需要保存我们的操作,命令如下:
1 /etc/rc.d/init.d/iptables save
此时我们可以查看端口的状态,命令如下:
1 /etc/init.d/iptables status
当然如果你打开其他端口也一样,只需要把这个端口号换乘你需要的端口号即可。

第四步、安装PHP环境
yum install php php-pear
安装PHP环境,然后配置/etc/php.ini文件。
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
log_errors = On
error_log = /var/log/php/error.log
max_execution_time = 30
memory_limit = 128M
register_globals = Off
max_input_time = 30
用vi寻找上述的几个参数,然后对应进行修改参数,保存退出。
mkdir /var/log/php
chown apache /var/log/php
创建日志文件,如果我们需要支持MYSQL在PHP中,需要输入下面的命令安装php5-mysql包。
yum install php-mysql
/etc/init.d/httpd restart
安装并设置启动。
这样,我们的域名站点绑定、MYSQL数据库都已经添加,比如我们需要在imlx.cn域名下安装WORDPRESS程序或者其他程序,只需要在/srv/www/imlx.cn/public_html/目录下上传程序,然后利用设置的数据库用户安装就可以了。

转载原创文章请注明,转载自: 一个视界·触手可及 - 凌肖 » VP Easy 搭建 LAMP 环境