Step 1 – Setup LAMP
First of all, you need to set up a LAMP environment to install CakePHP on your Red Hat system. We assume that you already have PHP, MySQL and Apache installed on your system. If you don’t have, use the following article to install it.
Step 2 – Install Composer
Now CakePHP is using composer for managing dependencies. So first we need to install Composer using following command on the system. If already installed then just update to latest version.
Install Composer:
curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer chmod +x /usr/local/bin/composer
Update Composer:
composer self-update
Step 3 – Create CakePHP 3 Application
After installing the composer on your system. Let’s create CakePHP application named “MyApp” using composer command as below.
composer create-project --prefer-dist cakephp/app MyApp
Now set the proper permission for your project files. For Red Hat based system Apache default uses apache as the user. So change files ownership as per your setup.
chown -R apache:apache MyApp chmod -R 755 MyApp chmod -R 777 MyApp/tmp
Step 4 – Setup Database for CakePHP
For this article, we are using MySQL as the database server. First use following commands to create a MySQL database and create.
1 2 3 4 | mysql> CREATE DATABASE mydb; mysql> GRANT ALL ON mydb.* to 'myuser'@'localhost' IDENTIFIED BY '_password_'; mysql> FLUSH PRIVILEGES; mysql> quit |
Now edit config/app.php configuration file and search for your database setting. Make necessary changes as per below details
'Datasources' => [ 'default' => [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\DatabaseDriver\Mysql', 'persistent' => false, 'host' => 'localhost ', //'port' => 'nonstandard_port_number', 'username' => 'myuser ', 'password' => '_password_ ', 'database' => 'mydb ', 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' => true,
Here, you have two options to run your CakePHP application. For development system follow the Step 5(A) and for Production deployment follow step 5(B).
Step 5(A) – Deploy CakePHP on Development System
First is to use its built-in web server preferred for development purpose installation. This will make your application available at http://host:port. From the app directory, execute:
bin/cake server
By default, without any arguments provided, this will serve your application at http://localhost:8765/.
You can also specify your own host and port like below
bin/cake server -H 192.168.10.123 -p 1234
This will serve your application at http://192.168.10.123:1234/
Step 5(B) – Deploy CakePHP on Production System
Second is deploy with external web servers like Apache its preferred for production use. Let’s create an Apache VirtualHost configuration file using the following content.
<VirtualHost *:80> ServerAdmin [email protected] ServerName cakephp.tecadmin.net DocumentRoot /var/www/html/MyApp/webroot <Directory /var/www/html/MyApp> Allowoverride All </Directory> </VirtualHost>
Change the ServerName and document root as per your setup. After that reload your Apache service and access your CakePHP like http://cakephp.example.com.
2 Comments
HI,
I am getting this error
Warning (2): file_put_contents(/var/www/html/cakephp/logs/error.log): failed to open stream: Permission denied [CORE/src/Log/Engine/FileLog.php, line 133]
Warning: file_put_contents(/var/www/html/cakephp/logs/error.log) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/html/cakephp/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 133
Warning (512): /var/www/html/cakephp/tmp/cache/ is not writable [CORE/src/Cache/Engine/FileEngine.php, line 437]
Warning: file_put_contents(/var/www/html/cakephp/logs/error.log) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/html/cakephp/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 133
Warning (512): _cake_routes_ cache was unable to write ‘routeCollection’ to Cake\Cache\Engine\FileEngine cache [CORE/src/Cache/Cache.php, line 290]
Warning: file_put_contents(/var/www/html/cakephp/logs/error.log) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/html/cakephp/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 133
Warning (512): Unable to emit headers. Headers sent in file=/var/www/html/cakephp/vendor/cakephp/cakephp/src/Error/Debugger.php line=853 [CORE/src/Http/ResponseEmitter.php, line 48]
Warning: file_put_contents(/var/www/html/cakephp/logs/error.log) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/html/cakephp/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 133
Warning (2): Cannot modify header information – headers already sent by (output started at /var/www/html/cakephp/vendor/cakephp/cakephp/src/Error/Debugger.php:853) [CORE/src/Http/ResponseEmitter.php, line 148]
Warning: file_put_contents(/var/www/html/cakephp/logs/error.log) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/html/cakephp/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 133
Warning (2): Cannot modify header information – headers already sent by (output started at /var/www/html/cakephp/vendor/cakephp/cakephp/src/Error/Debugger.php:853) [CORE/src/Http/ResponseEmitter.php, line 181]
Warning: file_put_contents(/var/www/html/cakephp/logs/error.log) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/html/cakephp/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 133
Warning (2): Cannot modify header information – headers already sent by (output started at /var/www/html/cakephp/vendor/cakephp/cakephp/src/Error/Debugger.php:853) [CORE/src/Http/ResponseEmitter.php, line 206]
Warning: file_put_contents(/var/www/html/cakephp/logs/error.log) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/html/cakephp/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 133
thank you!