Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use SAE and GitCafe to build a website

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to use SAE and GitCafe to build a website", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn how to use SAE and GitCafe to build a website.

Create an application

First, all kinds of registrations. Sina Cloud needs to use a Sina Weibo account to log in and use.

Since Sina Cloud belongs to PaaS (that is, to provide a software running environment, rather than a virtual host or space), the charging model is based on the number of visits, so we do not need to pay attention to any indicators of the server, all we need to do is to create an application. At present, Sina Cloud needs real name verification to create more than 2 applications, so real name verification is recommended.

The interface for creating an application is as follows:

As you can see, our application will be host under the sinaapp.com domain name, and the subdomain name (App name) we can set is obviously globally unique on a first-come-first-served basis. In addition to the basic information of the application, you also need to choose the programming language, framework, template and so on. The PHP language is rich in frameworks and templates, while Python and Java do not have any frameworks or templates available. We use the PHP empty application here, and the name of the created application is assumed to be testapp, which will be used below.

After you have created the application, you need to configure various software or platform services used by the application. Several basic configurations are as follows:

In Application Management-Code Management, create a version. It is recommended to enter 1 for this version number.

In Service Management-MySQL, enable the function of MySQL. Unless your application does not require database support, MySQL is usually open. Phpmyadmin is used to manage MySQL.

By default, in code management, the code can be packaged and uploaded to the application, or submitted using SVN. See the instructions in Code Management for SVN. Our focus is on using Git for submission.

Create a code repository on Gitcafe

Register

In order to submit code using Git, we register to use Gitcafe. Because Gitcafe can be set to automatically push the code to Sina Cloud.

GitCafe is a code hosting platform that is very similar to Github. It feels OK for me to experience it, except for the green interface.

After registration, you can configure the public key to facilitate git submission. Find the file in the following path to your PC:

The code is as follows:

Cd / .ssh/id_rsa.pub

Copy and paste the contents into the SSH Public key Management Office of the Gitcafe website so that you do not need to enter a user name and password when submitting the code later.

Create a warehouse

We need to create a warehouse, which makes no difference to github. The only point is to set up automatic deployment to SAE.

Using this feature for the first time may require you to verify it with OAuth, which is very simple. Then Gitcafe can fetch the application you created on Sina and the corresponding version. Just choose and save it.

At present, Gitcafe's authorization to Sina is not automatically refreshed, which may be Sina's Policy, which will cause the authorization to expire a few days later and may need to be re-bound. I hope Gitcafe can improve it.

After you have created the application, you can initialize the application locally and submit the initialization to Gitcafe as prompted. But here, in order to lay the groundwork for the following local analog SAE environment, I made a slight change to the command:

First of all, create a folder in your local appropriate place to store SAE application code, such as sae:

The code is as follows:

Mkdir sae

Then use the following command:

The code is as follows:

Cd sae

Mkdir testapp

Cd testapp

Mkdir 1

Cd 1

Git init

Touch README.md

Git add README.md

Git commit-m 'first commit'

Git remote add origin...

Git push-u origin master

The above command is left at the remote warehouse address. You need to fill in it yourself, depending on your remote warehouse address. It is also worth noting that you need to create a folder named app, and there needs to be a folder of 1 under this folder, where 1 represents the version number of app, and the code part is placed under the folder 1.

If there is no problem with the above steps, because we have created README.md, this file will be automatically synchronized to Sina Cloud.

Configure the local environment

Next we need to configure a local execution environment to simulate the running environment of SAE to debug the code. Download the latest simulation environment here, and take the PHP environment as an example

After downloading and decompressing, you can find that the simulation environment comes with apache, php, redis and other software, and we need to configure the sae.conf file. The following is an explanation of the important configuration items of this file:

The root path of the DocumentRoot sae application is equivalent to the sae folder we created above. The simulation environment determines which applications are based on the folder under this folder every time.

The http port used by apache after the http_port simulation environment starts

Mysql_* simulation environment does not have its own mysql, so you need to use your local or remote mysql, so you need to configure these parameters here.

Once these are configured, start init.cmd as an administrator

If you need to modify the configuration of php, you may need to modify the file php.sae. This file is actually a configuration file for php, and every time the simulator starts, it copies the contents of php.sae to php.ini. However, there may be a bug. The configuration item disable_functions in php.sae cannot be correctly copied to php.ini, resulting in the failure to use the simulation environment. I wonder if it has been fixed or not. My solution is to leave the value of disable_functions blank in php.sae.

After the simulation environment starts, you can access the application locally in the form of http:// application name .sinaapp.com: Port, such as http://testapp.sinaapp.com:8081

The simulation environment will create config.yaml or .appconfig in the code directory. These two files cannot be uploaded to SAE through the code package, otherwise an error will occur. Therefore, we need to ignore these two files in .gitignore so that they are not submitted to Gitcafe, so they will not be uploaded to SAE.

If there is a second application in the future, you only need to create the corresponding app named folder and version folder in the sae directory, and the simulator will automatically recognize them. Of course, you can also use the relevant commands of the simulator to complete the management of the application.

Use mysql

In order to use mysql in a simulated environment, in addition to the basic configuration mentioned above, there are two other points to note:

The mysql database name needs to be in the form of an app_+ application name. For example, if the application name is testapp, the corresponding mysql database name must be app_testapp.

Accessing the database in php requires the use of constants defined by SAE, as well as in the real world.

Here is a code to connect to the database using pdo:

The code is as follows:

$dbh = 'mysql:host='. SAE_MYSQL_HOST_M. '; port='. SAE_MYSQL_PORT. '; dbname='. SAE_MYSQL_DB

$ops = array (PDO::MYSQL_ATTR_INIT_COMMAND = > "SET NAMES utf8")

$ops = array ()

Return new PDO ($dbh, SAE_MYSQL_USER, SAE_MYSQL_PASS, $ops)

At this point, I believe you have a deeper understanding of "how to use SAE and GitCafe to build a website". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report