在CentOS7上安装PHP5.4和CakePHP
-
- 安装EC2。从市场选择CentOS7的AMI。
-
- 选择安全组设置中的入站选项卡,点击“编辑”,允许HTTP访问。
-
- 以centos用户登录。
更改系统地区设置
$ sudo localectl set-locale LANG=ja_JP.UTF8
启用系统地区设置
$ sudo source /etc/locale.conf
将时区更改为日本
$ sudo timedatectl set-timezone Asia/Tokyo
禁用SELinux
vi /etc/selinux/config
+ SELINUX=enforcing
– SELINUX=disabled
重新启动
# shudown -Fr now
安装PHP7和postgresql(还包括mlocate和git)
# yum -y install php
# yum -y install php-mbstring php-xml php-gd php-mcrypt php-intl
# yum -y install php-pecl-memcache php-process php-pear php-xmlrpc
# yum -y install php-pgsql php-soap php-odbc php-pdo php-recode php-ldap
# yum -y install postgresql postgresql-server postgresql-devel
# yum -y install mlocate git
安装composer
执行以下URL中的命令行安装部分:
https://getcomposer.org/download/
以下是示例:
# php -r “copy(‘https://getcomposer.org/installer’, ‘composer-setup.php’);”
# php -r “if (hash_file(‘SHA384’, ‘composer-setup.php’) === ‘aa96f26c2b67226a324c27919f1eb05f21c248b987e6195cad9690d5c1ff713d53020a02ac8c217dbf90a7eacc9d141d’) { echo ‘Installer verified’; } else { echo ‘Installer corrupt’; unlink(‘composer-setup.php’); } echo PHP_EOL;”
# php composer-setup.php
# php -r “unlink(‘composer-setup.php’);”
移动composer.phar
# mv composer.phar /usr/local/bin/composer
将/usr/local/bin添加到centos用户的PATH
# exit
$ cd
$ vi /home/centos/.bash_profile
– PATH=$PATH:$HOME/.local/bin:$HOME/bin
+ PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/bin
使cakephp3的安装目录可写
$ sudo bash
# cd /var/www
# chmod 777 html
# exit
安装cakephp3
$ source /home/centos/.bash_profile
$ cd /var/www/html
$ composer self-update && composer create-project –prefer-dist cakephp/app ./app
如果想安装特定版本,比如最新的3.1系列:
$ composer self-update && composer create-project –prefer-dist cakephp/app:3.1.* ./app
在其中间会询问是否设置文件夹权限,回答Yes:
Set Folder Permissions ? (Default to Y) [Y,n]? Y
更改数据库设置(默认)
更改app.php文件223-234行之间的内容
$ vi /var/www/html/app/config/app.php
– ‘driver’ => ‘Cake\Database\Driver\Mysql’,
+ ‘driver’ => ‘Cake\Database\Driver\Postgres’,
– ‘username’ => ‘my_app’,
+ ‘username’ => ‘postgres’,
– ‘password’ => ‘secret’,
+ ‘password’ => ”,
– ‘database’ => ‘my_app’,
+ ‘database’ => ‘cakephp_dev’,
更改时区
/var/www/html/app/config/bootstrap.php
– date_default_timezone_set(‘UTC’);
+ date_default_timezone_set(‘Asia/Tokyo’);
更改数据库设置(测试)
步骤11相同,但更改app.php文件268-274行。并将’database’ => ‘cakephp_test’。
启用URL重写
更改/etc/httpd/conf/httpd.conf文件的第151行
$ sudo bash
# vi /etc/httpd/conf/httpd.conf
– AllowOverride None
+ AllowOverride All
更改DocumentRoot
$ sudo bash
# vi /etc/httpd/conf/httpd.conf
– DocumentRoot “/var/www/html”
+ DocumentRoot “/var/www/html/app/webroot”
初始化数据库
# su – postgres
$ /usr/lib64/pgsql/bin/initdb -D /var/lib/pgsql/data/
$ exit
启动postgresql和httpd
# service httpd start
# service postgresql start
创建数据库
# /usr/bin/createdb -U postgres -p 5432 -h localhost cakephp_dev
进行功能验证
打开浏览器,输入EC2的公网IP。