An A-Z Index of the Linux command line: bash + utilities. – about the same as the list of shell commands above.20 Shell Scripting Questions for Practice
I always, always forget how to do this and it takes an hour of googling to figure this out again. Basically I often need to see not just what php modules are installed on my system, but also what can be installed.
For example you can see what is already installed and available to you on your current system you simply type
php -m
in your command line. This command will list all of what is installed currently on your system.
But that is not what I want and probably not what you want if you are reading this. What I want is to know what is available for installing, or better what are the exact names of the packages. For this information you need a different command.
sudo apt-cache search php7*
This command searches the apt cache for packages that contain php7* the * is a wildcard meaning anything that looks like php7 such as php7.4-mysql. Try the command above and you will get a list of all of the php modules specifically for version 7.4. Not all modules will be listed. You can use another command to see all of the available php modules even if they don’t contain 7.4 in the name you can install them.
To see all php modules available use this command.
sudo apt-cache search php*
Minus the 7 and it will return every last module that contains the word php.
Then to install anything you need you use a command like the following
And that is how you list and install php modules/extensions.
Pro-tip : add -y to the end of the apt install command so you don’t have to keep answering yes during the module installs
After you install the modules you need to restart the PHP service. To see all the services currently running in order to find your PHP service type service --status-all
That will list all of your systems services. Find the name of your php installation and restart it with this line of code service php7.4-fpm restart
Came across a weird not so feature of TinyMCE where it munges the URL your upload script returns when it uploads an image. For example if your upload script returns a url of http://example.com/folder/image.jpg. TinyMCE takes it upon itself to rewrite that URL breaking it to ../../folder/image.jpg I am not sure why but I think it is trying to help you in some way.
The best clue I could find in the docs as to why this happens is at the bottom of the page in the CORS section here. It appears TinyMCE is removing the domain you add to the url then it cuts from the current page. The problem I encountered was if my page was blog it would remove the http://example.com part and replace it with ../../blog/folder/image.jpg which is not what I wanted.
I was about to replace TinyMCE but I decided to try something else. I did some googling and found this in the docs.
Those 3 lines of code fixed it all. Totally didn’t expect TinyMCE to munge the URL’s I returned. This ate up an entire day as I kept thinking the reason the image didn’t display was because my code wasn’t creating the URL’s correctly. Then I thought it was my Nginx configs. Then before giving up on TinyMCE I did this last thing.
prependURL is a variable that contains the url of website hosting the image such as https://example.com TinyMCE prepends that to the url you return to it, even if https://example.com is already part of it. Otherwise it removes https://example.com and replaces it with a relative URL such as ../../folder/image.jpg
Basically if you want to remove a column from a table when using Doctrine and Symfony Entities all you do is remove the variable and the matching getter/setter methods from the Entity, then run a diff.
php bin/console doctrine:migrations:diff
instead of making a migration, this command makes the migration file for you. Then you can run this command to change the table.
Make sure you don’t have other migrations ready before running this command or all of them get executed. You can follow the advice in the console after issuing the above command and use “execute” instead with the name of the exact migration you want to use.
php bin/console doctrine:migrations:migrate
What is happening is Doctrine ORM is used to map the Database tables to an Entity. Every Doctrine/Symfony Entity matches 1 table in a database.
Lets view an example. This Entity should be familiar to anyone who created an app using the Symfony maker system. User.php should be located in app\src\Entity\User.php and it looks basically like this.
<?php namespace App\Entity; use App\Repository\UserRepository; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; /** * User * * @ORM\Table(name="user", uniqueConstraints={@ORM\UniqueConstraint(name="email_UNIQUE", columns={"email"})}, indexes={@ORM\Index(name="email", columns={"email"})}) * @ORM\Entity(repositoryClass=UserRepository::class) */ class User implements UserInterface { /** * @var int * * @ORM\Column(name="id", type="bigint", nullable=false, options={"unsigned"=true}) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private int $id; /** * @var string * * @ORM\Column(name="email", type="string", length=255, nullable=false) */ private string $email; /** * @var string * * @ORM\Column(name="password", type="string", length=255, nullable=false) */ private string $password; /** * @var array|null * * @ORM\Column(name="roles", type="json", nullable=true) */ private ?array $roles; /** * @var string|null * * @ORM\Column(name="web_token", type="string", length=255, nullable=true) */ private ?string $webToken; /** * @var string|null * * @ORM\Column(name="api_token", type="string", length=255, nullable=true) */ private ?string $apiToken; public function getId(): ?string { return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getRoles(): ?array
{
return $this->roles;
}
public function setRoles(?array $roles): self
{
$this->roles = $roles;
return $this;
}
public function getWebToken(): ?string
{
return $this->webToken;
}
public function setWebToken(?string $webToken): self
{
$this->webToken = $webToken;
return $this;
}
public function getApiToken(): ?string
{
return $this->apiToken;
}
public function setApiToken(?string $apiToken): self
{
$this->apiToken = $apiToken;
return $this;
}
public function getSalt()
{
// TODO: Implement getSalt() method.
}
public function getUsername(): ?string
{
// TODO: Implement getUsername() method.
return $this->getEmail();
}
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}
}
As you can see I have a web token and api token in this class. If I wanted to remove the web token from my database I simply remove the relate variable and getter/setters like so.
<?php namespace App\Entity; use App\Repository\UserRepository; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; /** * User * * @ORM\Table(name="user", uniqueConstraints={@ORM\UniqueConstraint(name="email_UNIQUE", columns={"email"})}, indexes={@ORM\Index(name="email", columns={"email"})}) * @ORM\Entity(repositoryClass=UserRepository::class) */ class User implements UserInterface { /** * @var int * * @ORM\Column(name="id", type="bigint", nullable=false, options={"unsigned"=true}) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private int $id; /** * @var string * * @ORM\Column(name="email", type="string", length=255, nullable=false) */ private string $email; /** * @var string * * @ORM\Column(name="password", type="string", length=255, nullable=false) */ private string $password; /** * @var array|null * * @ORM\Column(name="roles", type="json", nullable=true) */ private ?array $roles; /** * @var string|null * * @ORM\Column(name="api_token", type="string", length=255, nullable=true) */ private ?string $apiToken; public function getId(): ?string { return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getRoles(): ?array
{
return $this->roles;
}
public function setRoles(?array $roles): self
{
$this->roles = $roles;
return $this;
}
public function getApiToken(): ?string
{
return $this->apiToken;
}
public function setApiToken(?string $apiToken): self
{
$this->apiToken = $apiToken;
return $this;
}
public function getSalt()
{
// TODO: Implement getSalt() method.
}
public function getUsername(): ?string
{
// TODO: Implement getUsername() method.
return $this->getEmail();
}
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}
}
Now when you run the migrations:diff command a new migration file will be created. Inside that file will be the queries to make the changes in the “up” method of that migrations file. In the “down” method you will find the code to restore the database and add the column back, which will also update the Entity class.
After you run the diff you run a migration. Running the migration changes your database to match your changes in your Entity class.
Tips
#1 One entity at a time
The first tip I’d give is to work on only one entity at a time. That means change only one entity file, then run the diff, then migrate. You will often run into issues and it is easier to fix those issues one at a time than many at once.
#2 Check for indexes
When you remove a column, look to the top of the file to make sure there are not any indexes on those columns or else you will get errors.
check for indexes too
#3 Give divorces
Make sure you note any column that is used in any entity relationship, you will need to give them proper divorces. LOL Basically if you have two tables that are linked by an id, don’t delete an entity if that entity is referred to in another entity. This will get barf all over you.
Symfony/Doctrine will barf on you.
First find all the entities that your entity is referred to in and delete each one. then you can delete the entity itself. The easy way to do this is to use your IDE to “Find usages” of the class. Find each entity file that uses it and delete the reference. Also delete the import statement.
AWS autoscaling lets you set up groups of EC2 instances which are controlled by a load balancer. The load balancer in turn makes sure your app has the correct number of EC2 instances running at all times. If your traffic is high it adds the maximum that you set. If traffic goes down it adjust to have the minimum EC2 instances that you set.
This system is great for startups who have no idea if their app will go viral or just flop. Often they just flop. But if you are lucky and it takes off you want to be able to handle the traffic so you don’t lose users.