We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

73
5.986.745,85

Cart

Quantity 19.800,00
Quantity 10.000,00
Quantity 116,00

Install CakePHP with LAMP on Ubuntu 18.04 – Google Cloud

Install CakePHP on Ubuntu 18.04 – Google Cloud. CakePHP is a rapid development framework for PHP which uses popular design patterns like Front Controller, Associative Data Mapping and MVC.

This guide, explains the steps to install CakePHP with LAMP on Ubuntu 18.04.

Prerequisites

With the above completed prerequisites I assume you have your Apache, PHP installed and Cloud SQL is configured.

1. Install Required Packages

CakePHP requires some additional extensions like php-intl

sudo apt install php-intl

2. Install Composer

CakePHP can be installed by Composer, so you can go ahead install composer.

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer

To verify the installation run the composer command.

3. Create CakePHP Project

Once Composer is installed you can create a new CakePHP project using composer.

Now quickly move into the html directory.

cd /var/www/html

Create new project.

sudo composer create-project --prefer-dist cakephp/app myapp 

This command will create a new CakePHP project in /var/www/html/myapp directory.

4. Set up Correct Permissions

Set correct permissions to the newly created project.

sudo chown -R username /var/www/html/myapp
sudo chmod -R 755 /var/www/html/myapp
sudo chmod -R 777 /var/www/html/myapp/tmp

5. Configure Apache

Enable Apache rewrite module.

sudo a2enmod rewrite

Edit the apache2.conf file and enable Allow Override for /var/wwwdirectory.

sudo nano /etc/apache2/apache2.conf

Replace Allowoverride None to Allowoverride All for /var/www directory and save the file.

Finally, edit the 000-default.conf file and replace the Document root to your CakePHP project path.

sudo nano /etc/apache2/sites-enabled/000-default.conf

Replace DocumentRoot /var/www/html with DocumentRoot /var/www/html/myapp/webroot and save the file.

Now visit your web browser with your external IP address. You shall see the welcome page of CakePHP.

Cake PHP welcome page

6. Set up Database

Now you can connect your application to Cloud SQL.

sudo nano /var/www/html/myapp/config/app.php 

Replace the following in the file.

  • Cloud_SQL_IP_ADDRESS: Your Cloud SQL Instance public IP address.
  • CLOUD_SQL_USERNAME: Your Cloud SQL username.
  • CLOUD_SQL_USER_PASSWORD: Your Cloud SQL password for the username.
  • CLOUD_SQL_DATABASE_NAME: Your Cloud SQL database name.
     'Datasources' => [
'default' => [
'className' => 'CakeDatabaseConnection',
'driver' => 'CakeDatabaseDriverMysql',
'persistent' => false,
'host' => 'Cloud_SQL_IP_ADDRESS',
/*
* CakePHP will use the default DB port based on the driver selected
* MySQL on MAMP uses port 8889, MAMP users will want to uncomment
* the following line and set the port accordingly
//'port' => 'non_standard_port_number',
'username' => 'CLOUD_SQL_USERNAME',
'password' => 'CLOUD_SQL_USER_PASSWORD',
'database' => 'CLOUD_SQL_DATABASE_NAME', /
* You do not need to set this flag to use full utf-8 encoding (internal default since CakePHP 3.6).
*/
//'encoding' => 'utf8mb4',
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'log' => false,

Save the file. That’all!

Conclusion

Now you have learned how to install CakePHP on your Ubuntu server in Google Cloud.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

73
5.986.745,85

Cart

Quantity 19.800,00
Quantity 10.000,00
Quantity 116,00